You are here

public static function LearningPathAccess::checkCourseClassAccess in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/LearningPathAccess.php \Drupal\opigno_learning_path\LearningPathAccess::checkCourseClassAccess()

Returns user course/class access flag.

Parameters

\Drupal\group\Entity\Group $group: Group.

\Drupal\Core\Session\AccountInterface $account: User account.

Return value

bool Check if user has access to Class or Course.

1 call to LearningPathAccess::checkCourseClassAccess()
opigno_learning_path_group_access in ./opigno_learning_path.module
Restricts user access to Learning Path and it's content.

File

src/LearningPathAccess.php, line 604

Class

LearningPathAccess
Class LearningPathAccess.

Namespace

Drupal\opigno_learning_path

Code

public static function checkCourseClassAccess(Group $group, AccountInterface $account) {
  $access = FALSE;
  $type = $group
    ->getGroupType()
    ->id();

  // Check for class.
  if ($type == 'opigno_class') {
    $is_member = $group
      ->getMember($account);
    $access = $is_member ? TRUE : FALSE;
  }
  elseif ($type == 'opigno_course') {
    $database = Database::getConnection();

    // Get all trainings where user is a member and course is a content.
    $query = $database
      ->select('opigno_group_content', 'ogc');
    $query
      ->leftJoin('group_content_field_data', 'gc', 'ogc.group_id = gc.gid');
    $results = $query
      ->fields('ogc', [
      'group_id',
    ])
      ->condition('ogc.entity_id', $group
      ->id())
      ->condition('ogc.group_content_type_id', 'ContentTypeCourse')
      ->condition('gc.type', 'learning_path-group_membership')
      ->condition('gc.entity_id', $account
      ->id())
      ->execute()
      ->fetchAll();
    $access = $results ? TRUE : FALSE;

    // Added possibility to override access for groups from other modules.
    if (!self::triggerHookAccess('status_course_validation_access', $group, $account)) {
      $access = FALSE;
    }
  }
  return $access;
}