diff --git a/classes/local/table/interaction_attention_table.php b/classes/local/table/interaction_attention_table.php index 2624831d..cf3acb88 100644 --- a/classes/local/table/interaction_attention_table.php +++ b/classes/local/table/interaction_attention_table.php @@ -40,6 +40,12 @@ */ class interaction_attention_table extends interaction_table { + /** + * In case a specific course category should be shown, all course categories are fetched once ... + * ... to find the suitable category later. + * @var \stdClass + */ + private $coursecategories; /** * Constructor for deactivated_workflows_table. * @param int $uniqueid Unique id of this table. @@ -51,15 +57,18 @@ public function __construct($uniqueid, $courseids, $filterdata = null) { global $PAGE, $DB; $fields = "p.id as processid, c.id as courseid, c.fullname as coursefullname, c.shortname as courseshortname, " . - "c.startdate, cc.name as category , s.id as stepinstanceid, s.instancename as stepinstancename, ". - "s.subpluginname as subpluginname"; + "c.startdate, cc.name as category, cc.path as categorypath, s.id as stepinstanceid, " . + "s.instancename as stepinstancename, s.subpluginname as subpluginname"; $from = '{tool_lifecycle_process} p join ' . '{course} c on p.courseid = c.id join ' . '{tool_lifecycle_step} s ' . 'on p.workflowid = s.workflowid AND p.stepindex = s.sortindex ' . 'left join {course_categories} cc on c.category = cc.id'; $ids = implode(',', $courseids); - + if (get_config('tool_lifecycle', 'enablecategoryhierachy')) { + // We have to get the complete category tree. + $this->coursecategories = $DB->get_records_sql('SELECT id, name, depth, path, parent FROM {course_categories} '); + } $where = ['FALSE']; if ($ids) { $where = ['p.courseid IN (' . $ids . ')']; @@ -124,6 +133,30 @@ public function col_tools($row) { return $output; } + /** + * Dependent on the setting either returns the closest category or the category that is on the specified depth, + * if the category depth is not reached the last category is returned. + * @param $row + * @return string + * @throws \dml_exception + */ + public function col_category($row): String { + $categorydepth = get_config('tool_lifecycle', 'enablecategoryhierachy'); + if ($categorydepth == false) { + return $row->category; + } else { + $categorydepth = (int) get_config('tool_lifecycle', 'coursecategorydepth'); + $categoryhierachy = explode('/', substr($row->categorypath, 1)); + $categoryhierachy = array_map('intval', $categoryhierachy); + if (isset($categoryhierachy[$categorydepth])) { + $category = $this->coursecategories[$categoryhierachy[$categorydepth]]; + return $category->name; + } else { + $category = $this->coursecategories[end($categoryhierachy)]; + return $category->name; + } + } + } /** * Render date column. * @param object $row Row data.