public function OpignoModule::getModuleActivities in Opigno module 8
Same name and namespace in other branches
- 3.x src/Entity/OpignoModule.php \Drupal\opigno_module\Entity\OpignoModule::getModuleActivities()
Get activities related to specific module.
1 call to OpignoModule::getModuleActivities()
- OpignoModule::getRandomActivity in src/
Entity/ OpignoModule.php - Returns random activity.
File
- src/
Entity/ OpignoModule.php, line 627
Class
- OpignoModule
- Defines the Module entity.
Namespace
Drupal\opigno_module\EntityCode
public function getModuleActivities($full = FALSE) {
if (empty($this->activities)) {
/* @todo join table with activity revisions */
/* @var $db_connection \Drupal\Core\Database\Connection */
$db_connection = \Drupal::service('database');
$query = $db_connection
->select('opigno_activity', 'oa');
$query
->fields('oafd', [
'id',
'vid',
'type',
'name',
'usage_activity',
'skills_list',
'skill_level',
]);
$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_id');
$query
->condition('oafd.status', 1);
$query
->condition('omr.parent_id', $this
->id());
if ($this
->getRevisionId()) {
$query
->condition('omr.parent_vid', $this
->getRevisionId());
}
$query
->condition('omr_pid', NULL, 'IS');
$query
->orderBy('omr.weight');
$query
->orderBy('omr.omr_id');
$result = $query
->execute();
foreach ($result as $activity) {
$this->activities[$activity->id] = $activity;
}
}
// Load entities if full was requested.
if ($full && !empty($this->activities)) {
$activity_ids = [];
foreach ($this->activities as $activity) {
$activity_ids[$activity->id] = $activity->id;
}
return OpignoActivity::loadMultiple($activity_ids);
}
return $this->activities;
}