You are here

public function LearningPathAchievementTrait::getStepsByGroup in Opigno Learning path 3.x

Retrieves the steps by group.

2 calls to LearningPathAchievementTrait::getStepsByGroup()
DefaultTwigExtension::opigno_modules_counter in src/TwigExtension/DefaultTwigExtension.php
Counter of modules by group.
StepsBlock::build in src/Plugin/Block/StepsBlock.php
Builds and returns the renderable array for this block plugin.

File

src/Traits/LearningPathAchievementTrait.php, line 25

Class

LearningPathAchievementTrait
LearningPathAchievementTrait trait.

Namespace

Drupal\opigno_learning_path\Traits

Code

public function getStepsByGroup(GroupInterface $group) : array {
  $static_steps =& drupal_static(__FUNCTION__, []);
  if (empty($group)) {
    return [];
  }
  if (isset($static_steps[$group
    ->id()])) {
    return $static_steps[$group
      ->id()];
  }

  // Get training guided navigation option.
  $freeNavigation = !OpignoGroupManagerController::getGuidedNavigation($group);
  if ($freeNavigation) {

    // Get all steps for LP.
    $steps = LearningPathContent::getAllStepsOnlyModules($group
      ->id(), $this
      ->currentUser()
      ->id(), TRUE);
  }
  else {

    // Get guided steps.
    $steps = LearningPathContent::getAllStepsOnlyModules($group
      ->id(), $this
      ->currentUser()
      ->id());
  }
  $user = $this
    ->currentUser();
  $steps = array_filter($steps, function ($step) use ($user) {
    if ($step['typology'] === 'Meeting') {

      // If the user have not the collaborative features role.
      if (!$user
        ->hasPermission('view meeting entities')) {
        return FALSE;
      }

      // If the user is not a member of the meeting.

      /** @var \Drupal\opigno_moxtra\MeetingInterface $meeting */
      $meeting = $this
        ->entityTypeManager()
        ->getStorage('opigno_moxtra_meeting')
        ->load($step['id']);
      if (!$meeting
        ->isMember($user
        ->id())) {
        return FALSE;
      }
    }
    elseif ($step['typology'] === 'ILT') {

      // If the user is not a member of the ILT.

      /** @var \Drupal\opigno_ilt\ILTInterface $ilt */
      $ilt = $this
        ->entityTypeManager()
        ->getStorage('opigno_ilt')
        ->load($step['id']);
      if (!$ilt
        ->isMember($user
        ->id())) {
        return FALSE;
      }
    }
    return TRUE;
  });
  $static_steps[$group
    ->id()] = $steps;
  return $steps;
}