protected function LearningPathAchievementController::build_lp_steps in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 src/Controller/LearningPathAchievementController.php \Drupal\opigno_learning_path\Controller\LearningPathAchievementController::build_lp_steps()
Returns LP steps.
Parameters
\Drupal\group\Entity\GroupInterface $group: Group.
Return value
array LP steps.
2 calls to LearningPathAchievementController::build_lp_steps()
- LearningPathAchievementController::build_training in src/
Controller/ LearningPathAchievementController.php - Returns training array.
- LearningPathAchievementController::training_steps_ajax in src/
Controller/ LearningPathAchievementController.php - Loads steps for a training with a AJAX.
File
- src/
Controller/ LearningPathAchievementController.php, line 702
Class
- LearningPathAchievementController
- Class LearningPathAchievementController.
Namespace
Drupal\opigno_learning_path\ControllerCode
protected function build_lp_steps(GroupInterface $group, AccountInterface $account = NULL) {
$user = $this
->currentUser($account);
$uid = $user
->id();
// Get training latest certification timestamp.
$latest_cert_date = LPStatus::getTrainingStartDate($group, $uid);
// Get training guided navigation option.
$freeNavigation = !OpignoGroupManagerController::getGuidedNavigation($group);
if ($freeNavigation) {
// Get all steps for LP.
$steps = opigno_learning_path_get_all_steps($group
->id(), $uid, NULL, $latest_cert_date);
}
else {
// Get guided steps.
$steps = opigno_learning_path_get_steps($group
->id(), $uid, NULL, $latest_cert_date);
}
$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 = \Drupal::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 = \Drupal::entityTypeManager()
->getStorage('opigno_ilt')
->load($step['id']);
if (!$ilt
->isMember($user
->id())) {
return FALSE;
}
}
return TRUE;
});
$steps = array_map(static function ($step) use ($uid, $latest_cert_date) {
$step['status'] = opigno_learning_path_get_step_status($step, $uid, TRUE, $latest_cert_date);
$step['attempted'] = opigno_learning_path_is_attempted($step, $uid);
$step['progress'] = opigno_learning_path_get_step_progress($step, $uid, FALSE, $latest_cert_date);
return $step;
}, $steps);
return [
'#type' => 'container',
'#attributes' => [
'id' => 'training_steps_' . $group
->id(),
],
array_map(function ($step) use ($group, $user, $latest_cert_date) {
return [
'#theme' => 'opigno_learning_path_training_step',
'#step' => $step,
'#is_module' => $this
->isModule($step),
$this
->trainingStepContentBuild($step, $group, $user, $latest_cert_date),
];
}, $steps),
];
}