public function LearningPathContentController::getModules in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Controller/LearningPathContentController.php \Drupal\opigno_learning_path\Controller\LearningPathContentController::getModules()
This method is called on learning path load.
It returns all the LP modules in JSON format.
1 string reference to 'LearningPathContentController::getModules'
File
- src/
Controller/ LearningPathContentController.php, line 197
Class
- LearningPathContentController
- Controller for all the actions of the Learning Path content.
Namespace
Drupal\opigno_learning_path\ControllerCode
public function getModules(Group $group) {
// Init the response and get all the contents from this learning path.
$modules = [];
// Get the courses and modules within those.
if ($group
->getGroupType()
->id() == 'learning_path') {
$group_content = $group
->getContent('subgroup:opigno_course');
foreach ($group_content as $content) {
/* @var $content \Drupal\group\Entity\GroupContent */
/* @var $content_entity \Drupal\group\Entity\Group */
$course = $content
->getEntity();
$course_contents = $course
->getContent('opigno_module_group');
foreach ($course_contents as $course_content) {
/* @var $module_entity \Drupal\opigno_module\Entity\OpignoModule */
$module_entity = $course_content
->getEntity();
$modules[] = [
'entity_id' => $module_entity
->id(),
'name' => $module_entity
->label(),
'activity_count' => $this
->countActivityInModule($module_entity),
'editable' => $module_entity
->access('update'),
];
}
}
}
// Get the direct modules.
$group_content = $group
->getContent('opigno_module_group');
foreach ($group_content as $content) {
/* @var $content \Drupal\group\Entity\GroupContent */
/* @var $content_entity \Drupal\opigno_module\Entity\OpignoModule */
$content_entity = $content
->getEntity();
$modules[] = [
'entity_id' => $content_entity
->id(),
'name' => $content_entity
->label(),
'activity_count' => $this
->countActivityInModule($content_entity),
'editable' => $content_entity
->access('update'),
];
}
// Sort according to position.
$modules = $this
->sortModulesArray($modules, $group);
// Return all the contents in JSON format.
return new JsonResponse($modules, Response::HTTP_OK);
}