public function OpignoModuleController::moduleActivities in Opigno module 8
Same name and namespace in other branches
- 3.x src/Controller/OpignoModuleController.php \Drupal\opigno_module\Controller\OpignoModuleController::moduleActivities()
Get activities related to specific module.
Parameters
\Drupal\opigno_module\Entity\OpignoModuleInterface $opigno_module: Opigno module entity object.
Return value
array Array of module's activities.
File
- src/
Controller/ OpignoModuleController.php, line 39
Class
- OpignoModuleController
- Class OpignoModuleController.
Namespace
Drupal\opigno_module\ControllerCode
public function moduleActivities(OpignoModuleInterface $opigno_module) {
/* @todo join table with activity revisions */
$activities = [];
/* @var $db_connection \Drupal\Core\Database\Connection */
$db_connection = \Drupal::service('database');
$query = $db_connection
->select('opigno_activity', 'oa');
$query
->fields('oafd', [
'id',
'type',
'name',
]);
$query
->fields('omr', [
'activity_status',
'weight',
'max_score',
'auto_update_max_score',
'omr_id',
'omr_pid',
'child_id',
'child_vid',
]);
$query
->addJoin('inner', 'opigno_activity_field_data', 'oafd', 'oa.id = oafd.id');
$query
->addJoin('inner', 'opigno_module_relationship', 'omr', 'oa.id = omr.child_vid');
$query
->condition('oafd.status', 1);
$query
->condition('omr.parent_id', $opigno_module
->id());
if ($opigno_module
->getRevisionId()) {
$query
->condition('omr.parent_vid', $opigno_module
->getRevisionId());
}
$query
->condition('omr_pid', NULL, 'IS');
$query
->orderBy('omr.weight');
$result = $query
->execute();
foreach ($result as $activity) {
$activities[] = $activity;
}
return $activities;
}