protected function LearningPathAchievementController::build_course_steps in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Controller/LearningPathAchievementController.php \Drupal\opigno_learning_path\Controller\LearningPathAchievementController::build_course_steps()
Returns course steps renderable array.
Parameters
\Drupal\group\Entity\GroupInterface $training: Parent training group entity.
\Drupal\group\Entity\GroupInterface $course: Course group entity.
Return value
array Course steps renderable array.
1 call to LearningPathAchievementController::build_course_steps()
- LearningPathAchievementController::build_lp_steps in src/
Controller/ LearningPathAchievementController.php - Returns LP steps.
File
- src/
Controller/ LearningPathAchievementController.php, line 543
Class
- LearningPathAchievementController
- Class LearningPathAchievementController.
Namespace
Drupal\opigno_learning_path\ControllerCode
protected function build_course_steps(GroupInterface $training, GroupInterface $course) {
$user = $this
->currentUser();
$steps = opigno_learning_path_get_steps($course
->id(), $user
->id());
$rows = array_map(function ($step) use ($training, $course, $user) {
return [
'data-training' => $training
->id(),
'data-course' => $course
->id(),
'data-module' => $step['id'],
'data' => [
[
'data' => $this
->build_step_name($step),
],
[
'data' => $this
->build_step_score($step),
],
[
'data' => $this
->build_step_state($step),
],
!empty($step['id']) && !empty($step['best_attempt']) ? [
'data' => Link::createFromRoute($this
->t('details'), 'opigno_module.module_result', [
'opigno_module' => $step['id'],
'user_module_status' => $step['best_attempt'],
])
->toRenderable(),
] : [],
],
];
}, $steps);
$module_steps = array_filter($steps, function ($step) {
return $step['typology'] === 'Module';
});
$module_panels = array_map(function ($step) use ($training, $course) {
$training_id = $training
->id();
$course_id = $course
->id();
$module_id = $step['id'];
return [
'#type' => 'container',
'#attributes' => [
'id' => "module_panel_{$training_id}_{$course_id}_{$module_id}",
'class' => [
'lp_module_panel',
],
],
];
}, $module_steps);
return [
'#theme' => 'opigno_learning_path_training_course_content',
'#course_id' => $course
->id(),
[
'#type' => 'table',
'#attributes' => [
'class' => [
'lp_course_steps',
'mb-0',
],
],
'#header' => [
t('Module'),
t('Results'),
t('State'),
t('Details'),
],
'#rows' => $rows,
],
$module_panels,
];
}