You are here

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

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

Returns group user access flag in validation condition.

5 calls to LearningPathAccess::statusGroupValidation()
DefaultTwigExtension::get_start_link in src/TwigExtension/DefaultTwigExtension.php
Returns group start link.
LearningPathController::trainingContent in src/Controller/LearningPathController.php
Returns training content.
LearningPathMembersForm::buildForm in src/Form/LearningPathMembersForm.php
Form constructor.
LearningPathStepsController::startAccess in src/Controller/LearningPathStepsController.php
Check if the user has access to start the Learning Path.
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 100

Class

LearningPathAccess
Class LearningPathAccess.

Namespace

Drupal\opigno_learning_path

Code

public static function statusGroupValidation(Group $group, AccountInterface $account) {
  $access = TRUE;
  if ($membership = $group
    ->getMember($account)) {
    $visibility = $group->field_learning_path_visibility->value;

    // Check if we need to wait validation.
    $validation = LearningPathAccess::requiredValidation($group, $account);
    $status = LearningPathAccess::getMembershipStatus($membership
      ->getGroupContent()
      ->id());
    $required_trainings = self::hasUncompletedRequiredTrainings($group, $account);
    if ($visibility === 'semiprivate' && $validation) {

      // For semi-private groups with validation status should be 'Active'.
      if ($status != 1) {
        $access = FALSE;
      }
    }
    elseif ($required_trainings) {
      $access = FALSE;
    }
    else {

      // For another groups status should be not 'Blocked'.
      if ($status == 3) {
        $access = FALSE;
      }
    }

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