You are here

class OpignoTourFunctions in Opigno tour 3.x

Same name and namespace in other branches
  1. 8 src/OpignoTourFunctions.php \Drupal\opigno_tour\OpignoTourFunctions

Class OpignoTourFunctions.

@package Drupal\opigno_tour

Hierarchy

Expanded class hierarchy of OpignoTourFunctions

1 file declares its use of OpignoTourFunctions
opigno_tour.module in ./opigno_tour.module
Contains opigno_tour.module.

File

src/OpignoTourFunctions.php, line 10

Namespace

Drupal\opigno_tour
View source
class OpignoTourFunctions {

  /**
   * Checks if current route has a Guided tour.
   */
  public static function checkRouteTour($route_name) {
    $routes = [
      'view.frontpage.page_1',
      'view.opigno_training_catalog.training_catalogue',
      'opigno_learning_path.achievements',
      'entity.group.canonical',
      'entity.group.edit_form',
    ];
    if (in_array($route_name, $routes)) {
      return TRUE;
    }
    return FALSE;
  }

  /**
   * Checks if user has already viewed current page.
   */
  public static function isPageUserViewed($route_name, $uid) {
    $viewed = \Drupal::database()
      ->select('opigno_tour_user_routes', 'ur')
      ->fields('ur', [
      'timestamp',
    ])
      ->condition('uid', $uid)
      ->condition('route', $route_name)
      ->execute()
      ->fetchAll();
    if ($viewed) {
      return TRUE;
    }
    return FALSE;
  }

  /**
   * Saves user and current route.
   */
  public static function savePageUserViewed($route_name, $uid) {
    try {
      \Drupal::database()
        ->insert('opigno_tour_user_routes')
        ->fields([
        'uid' => $uid,
        'route' => $route_name,
        'timestamp' => time(),
      ])
        ->execute();
    } catch (\Exception $e) {
      \Drupal::logger('opigno_tour')
        ->error($e
        ->getMessage());
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OpignoTourFunctions::checkRouteTour public static function Checks if current route has a Guided tour.
OpignoTourFunctions::isPageUserViewed public static function Checks if user has already viewed current page.
OpignoTourFunctions::savePageUserViewed public static function Saves user and current route.