You are here

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

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

Returns uncompleted required trainings flag.

Parameters

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

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

Return value

bool|array Return FALSE or Array with unfinished training.

4 calls to LearningPathAccess::hasUncompletedRequiredTrainings()
DefaultTwigExtension::get_start_link in src/TwigExtension/DefaultTwigExtension.php
Returns group start link.
LearningPathAccess::statusGroupValidation in src/LearningPathAccess.php
Returns group user access flag in validation condition.
opigno_learning_path_group_access in ./opigno_learning_path.module
Restricts user access to Learning Path and it's content.
opigno_learning_path_preprocess_page in ./opigno_learning_path.module
Implements hook_preprocess_page().

File

src/LearningPathAccess.php, line 565

Class

LearningPathAccess
Class LearningPathAccess.

Namespace

Drupal\opigno_learning_path

Code

public static function hasUncompletedRequiredTrainings(GroupInterface $group, AccountInterface $account) {
  $trainings = $group
    ->get('field_required_trainings')
    ->getValue();
  if (!$trainings) {
    return FALSE;
  }
  $database = \Drupal::database();

  // Array of uncompleted required trainings.
  $uncompleted = [];
  if (is_array($trainings)) {
    for ($i = 0; $i < count($trainings); $i++) {
      $gid = $trainings[$i]['target_id'];

      // Check that training is completed.
      $is_completed = $database
        ->select('opigno_learning_path_achievements', 'a')
        ->fields('a')
        ->condition('uid', $account
        ->id())
        ->condition('gid', $gid)
        ->condition('status', 'completed')
        ->execute()
        ->fetchObject();
      if (!$is_completed) {
        array_push($uncompleted, $gid);
      }
    }
  }
  return $uncompleted;
}