Skip to content

Commit

Permalink
changed the interaction table to get all course categories in case a …
Browse files Browse the repository at this point in the history
…specific level of the coures hierachy should be displayed
  • Loading branch information
NinaHerrmann committed Jun 11, 2024
1 parent 7d5329f commit 0bc7570
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions classes/local/table/interaction_attention_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 . ')'];
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0bc7570

Please sign in to comment.