Skip to content

Commit

Permalink
Also use category depth setting for remaining courses table
Browse files Browse the repository at this point in the history
  • Loading branch information
justusdieckmann committed Jun 11, 2024
1 parent f7bf4f5 commit 67da437
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 35 deletions.
34 changes: 0 additions & 34 deletions classes/local/table/interaction_attention_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@
*/
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 @@ -65,10 +59,6 @@ public function __construct($uniqueid, $courseids, $filterdata = null) {
'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 @@ -133,30 +123,6 @@ 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 object $row Row data.
* @return string category name
* @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
2 changes: 1 addition & 1 deletion classes/local/table/interaction_remaining_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct($uniqueid, $courseids) {
// We need to do this, so that courses without any action have a smaller timestamp than courses with an recorded action.
// Otherwise, it would mess up the sorting.
$fields = "c.id as courseid, p.id AS processid, c.fullname AS coursefullname, c.shortname AS courseshortname, " .
"c.startdate, cc.name AS category, COALESCE(l.time, 0) AS lastmodified, l.userid, " .
"c.startdate, cc.name AS category, cc.path as categorypath, COALESCE(l.time, 0) AS lastmodified, l.userid, " .
"l.action, s.subpluginname, ";
if ($CFG->branch >= 311) {
$fields .= \core_user\fields::for_name()->get_sql('u', false, '', '', false)->selects;
Expand Down
39 changes: 39 additions & 0 deletions classes/local/table/interaction_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,26 @@
*/
abstract class interaction_table extends \table_sql {

/**
* 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 interaction_table.
* @param int $uniqueid Unique id of this table.
*/
public function __construct($uniqueid) {
global $DB;
parent::__construct($uniqueid);

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} ');
}

$this->set_attribute('class', $this->attributes['class'] . ' ' . $uniqueid);
}

Expand Down Expand Up @@ -107,6 +121,31 @@ public function col_status($row) {
return '';
}

/**
* 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 object $row Row data.
* @return string category name
* @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;
}
}
}

/**
* This function is not part of the public api.
*/
Expand Down

0 comments on commit 67da437

Please sign in to comment.