public function OpignoModuleManagerController::getActivityTypes in Opigno module 8
Same name and namespace in other branches
- 3.x src/Controller/OpignoModuleManagerController.php \Drupal\opigno_module\Controller\OpignoModuleManagerController::getActivityTypes()
Get the list of the existing activity types.
1 string reference to 'OpignoModuleManagerController::getActivityTypes'
File
- src/
Controller/ OpignoModuleManagerController.php, line 280
Class
- OpignoModuleManagerController
- Controller for all the actions of the Opigno module manager.
Namespace
Drupal\opigno_module\ControllerCode
public function getActivityTypes() {
// Get activity types.
$types = \Drupal::entityTypeManager()
->getStorage('opigno_activity_type')
->loadMultiple();
$types = array_filter($types, function ($type) {
/** @var \Drupal\opigno_module\Entity\OpignoActivityType $type */
return $type
->id() !== 'opigno_h5p';
});
$types = array_map(function ($type) {
/** @var \Drupal\opigno_module\Entity\OpignoActivityType $type */
return [
'bundle' => $type
->id(),
'name' => $type
->label(),
'description' => $this
->getNonH5PDescription($type),
'external_package' => FALSE,
];
}, $types);
// Get H5P libraries.
/** @var \Drupal\h5p\H5PDrupal\H5PDrupal $interface */
$interface = H5PDrupal::getInstance();
$libraries = $interface
->loadLibraries();
// Flatten libraries array.
$libraries = array_map(function ($library) {
return end($library);
}, $libraries);
// Filter runnable libraries.
$libraries = array_filter($libraries, function ($library) {
return $library->runnable == 1;
});
// Get library data.
$libraries = array_map(function ($library) {
return [
'bundle' => 'opigno_h5p',
'library' => $library->name,
'name' => $library->title,
'description' => $this
->getH5PDescription($library->name),
'major_version' => $library->major_version,
'minor_version' => $library->minor_version,
'external_package' => FALSE,
];
}, $libraries);
$types = array_merge($types, $libraries);
// Remove unwanted activities.
$config = \Drupal::config('opigno_module.settings');
$disabled = $config
->get('disabled_h5p');
foreach ($disabled as $item) {
unset($types[$item]);
}
// Set external package types.
$types['opigno_scorm']['external_package'] = TRUE;
$types['opigno_tincan']['external_package'] = TRUE;
if (self::getPptConvertAllow()) {
$ppt = [
'bundle' => 'external_package_ppt',
'name' => $this
->t('PPT(X) Course Presentation'),
'description' => $this
->t('This activity allows creation H5P Course Presentation content imported from PowerPoint files. Slides from PowerPoint presentation will be imported as images into H5P Course Presentation slider. Allowed file extensions are ppt/pptx.'),
];
if (array_key_exists('H5P.CoursePresentation', $types)) {
// Place new item after H5P.CoursePresentation element.
$types_updated = [];
foreach ($types as $key => $type) {
$types_updated[$key] = $type;
if ($key == 'H5P.CoursePresentation') {
$types_updated['external_package_ppt'] = $ppt;
}
}
$types = $types_updated;
}
else {
// Place new item at the end of the types array.
$types['external_package_ppt'] = $ppt;
}
}
$this
->array_unshift_assoc($types, 'external_package', [
'bundle' => 'external_package',
'name' => $this
->t('External package'),
'description' => $this
->t('This activity allows to easily load training packages created externally. The following formats are supported: SCORM 1.2 and 2004, TinCan and H5P.'),
]);
return new JsonResponse($types, Response::HTTP_OK);
}