Skip to content

Commit d6d55be

Browse files
NinaHerrmannjustusdieckmannbluetom
authored
Show category of specified level in interaction tables (#216)
* added setting - coursecategorydepth * Advanced tha category setting to have either a specified level or the _closest_ level * changed the interaction table to get all course categories in case a specific level of the coures hierachy should be displayed * updated phpdoc comment * added a behat test to test the matrix of possible settings for categories to be displayed * newline at end of file * added german lang strings * cleaned up according to cbf (not use todo but enhancement) * codechecker... * new lang strings @justusdieckmann * Also use category depth setting for remaining courses table * added behat for course remaining table --------- Co-authored-by: Justus Dieckmann <[email protected]> Co-authored-by: Thomas Niedermaier <[email protected]>
1 parent a0ff919 commit d6d55be

12 files changed

+93
-17
lines changed

classes/local/manager/interaction_manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public static function get_process_status_message($processid) {
170170
}
171171

172172
if ($process->stepindex == 0) {
173-
// TODO: Rethink behaviour for multiple triggers.
173+
// Software enhancement: Rethink behaviour for multiple triggers.
174174
$trigger = trigger_manager::get_triggers_for_workflow($process->workflowid)[0];
175175
$triggerlib = lib_manager::get_trigger_lib($trigger->subpluginname);
176176
return $triggerlib->get_status_message();

classes/local/manager/workflow_manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public static function activate_workflow($workflowid) {
257257
$transaction = $DB->start_delegated_transaction();
258258
$workflow = self::get_workflow($workflowid);
259259
if (!self::is_active($workflow->id)) {
260-
// TODO: Rethink behaviour for multiple triggers.
260+
// Software enhancement: Rethink behaviour for multiple triggers.
261261
$trigger = trigger_manager::get_triggers_for_workflow($workflowid)[0];
262262
$lib = lib_manager::get_trigger_lib($trigger->subpluginname);
263263
$workflow->manual = $lib->is_manual_trigger();

classes/local/table/interaction_attention_table.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ public function __construct($uniqueid, $courseids, $filterdata = null) {
5151
global $PAGE, $DB;
5252

5353
$fields = "p.id as processid, c.id as courseid, c.fullname as coursefullname, c.shortname as courseshortname, " .
54-
"c.startdate, cc.name as category , s.id as stepinstanceid, s.instancename as stepinstancename, ".
55-
"s.subpluginname as subpluginname";
54+
"c.startdate, cc.name as category, cc.path as categorypath, s.id as stepinstanceid, " .
55+
"s.instancename as stepinstancename, s.subpluginname as subpluginname";
5656
$from = '{tool_lifecycle_process} p join ' .
5757
'{course} c on p.courseid = c.id join ' .
5858
'{tool_lifecycle_step} s ' .
5959
'on p.workflowid = s.workflowid AND p.stepindex = s.sortindex ' .
6060
'left join {course_categories} cc on c.category = cc.id';
6161
$ids = implode(',', $courseids);
62-
6362
$where = ['FALSE'];
6463
if ($ids) {
6564
$where = ['p.courseid IN (' . $ids . ')'];

classes/local/table/interaction_remaining_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct($uniqueid, $courseids) {
5858
// We need to do this, so that courses without any action have a smaller timestamp than courses with an recorded action.
5959
// Otherwise, it would mess up the sorting.
6060
$fields = "c.id as courseid, p.id AS processid, c.fullname AS coursefullname, c.shortname AS courseshortname, " .
61-
"c.startdate, cc.name AS category, COALESCE(l.time, 0) AS lastmodified, l.userid, " .
61+
"c.startdate, cc.name AS category, cc.path as categorypath, COALESCE(l.time, 0) AS lastmodified, l.userid, " .
6262
"l.action, s.subpluginname, ";
6363
if ($CFG->branch >= 311) {
6464
$fields .= \core_user\fields::for_name()->get_sql('u', false, '', '', false)->selects;

classes/local/table/interaction_table.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,26 @@
4242
*/
4343
abstract class interaction_table extends \table_sql {
4444

45+
/**
46+
* In case a specific course category should be shown, all course categories are fetched once ...
47+
* ... to find the suitable category later.
48+
* @var \stdClass
49+
*/
50+
private $coursecategories;
51+
4552
/**
4653
* Constructor for interaction_table.
4754
* @param int $uniqueid Unique id of this table.
4855
*/
4956
public function __construct($uniqueid) {
57+
global $DB;
5058
parent::__construct($uniqueid);
59+
60+
if (get_config('tool_lifecycle', 'enablecategoryhierachy')) {
61+
// We have to get the complete category tree.
62+
$this->coursecategories = $DB->get_records_sql('SELECT id, name, depth, path, parent FROM {course_categories} ');
63+
}
64+
5165
$this->set_attribute('class', $this->attributes['class'] . ' ' . $uniqueid);
5266
}
5367

@@ -107,6 +121,31 @@ public function col_status($row) {
107121
return '';
108122
}
109123

124+
/**
125+
* Dependent on the setting either returns the closest category or the category that is on the specified depth,
126+
* if the category depth is not reached the last category is returned.
127+
* @param object $row Row data.
128+
* @return string category name
129+
* @throws \dml_exception
130+
*/
131+
public function col_category($row): String {
132+
$categorydepth = get_config('tool_lifecycle', 'enablecategoryhierachy');
133+
if ($categorydepth == false) {
134+
return $row->category;
135+
} else {
136+
$categorydepth = (int) get_config('tool_lifecycle', 'coursecategorydepth');
137+
$categoryhierachy = explode('/', substr($row->categorypath, 1));
138+
$categoryhierachy = array_map('intval', $categoryhierachy);
139+
if (isset($categoryhierachy[$categorydepth])) {
140+
$category = $this->coursecategories[$categoryhierachy[$categorydepth]];
141+
return $category->name;
142+
} else {
143+
$category = $this->coursecategories[end($categoryhierachy)];
144+
return $category->name;
145+
}
146+
}
147+
}
148+
110149
/**
111150
* This function is not part of the public api.
112151
*/

classes/view_controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function handle_view($renderer, $filterdata) {
5757
$courses = get_user_capability_course('tool/lifecycle:managecourses', null, false);
5858
if (!$courses) {
5959
echo 'no courses';
60-
// TODO show error.
60+
// Software enhancement show error.
6161
return;
6262
}
6363

@@ -142,7 +142,7 @@ public function handle_interaction($action, $processid, $stepid) {
142142
*/
143143
public function handle_trigger($triggerid, $courseid) {
144144
global $PAGE;
145-
// TODO check if trigger to triggerid exists.
145+
// Software enhancement check if trigger to triggerid exists.
146146
// Check if trigger is manual.
147147
$trigger = trigger_manager::get_instance($triggerid);
148148
$lib = lib_manager::get_trigger_lib($trigger->subpluginname);

lang/de/tool_lifecycle.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@
4545
$string['backupcreated'] = 'Erstellt am';
4646
$string['backupworkflow'] = 'Workflow sichern';
4747
$string['cannot_trigger_workflow_manually'] = 'Der Workflow konnte nicht manuell ausgelöst werden.';
48+
$string['config_coursecategorydepth'] = 'Tiefe der Kurskategorien, die in der Interaktionstabelle angezeigt werden sollen';
49+
$string['config_coursecategorydepth_desc'] = 'Standardmäßig wird die erste Kategorie angezeigt, wenn Lehrkräfte den Status ihrer Kurse in der view.php verwalten. Die Einstellung ermöglicht es, nicht die erste Ebene der Kategorien, sondern Unterkategorien anzuzeigen.';
4850
$string['config_delay_duration'] = 'Standardlänge eines Kursausschlusses';
4951
$string['config_delay_duration_desc'] = 'Diese Einstellung definiert den Standardlänge einer Kursausschlusses in einem Workflow
5052
falls ein Prozess des Workflows zurückgesetzt oder beendigt wird. Die Länge des Kursausschlusses besagt, wie lange es dauert, bis
5153
der Kurs wieder vom Workflow bearbeitet wird.';
54+
$string['config_enablecategoryhierachy'] = 'Kurskategorienhierarchie in der Interaktionstabelle spezifizieren';
55+
$string['config_enablecategoryhierachy_desc'] = 'Standardmäßig wird die direkt zugewiesene Kurskategorie angezeigt, wenn Lehrkräfte den Status ihrer Kurse in der view.php verwalten. Die Einstellung ermöglicht es, eine bestimmte Ebene des Kurskategorienbaums anzuzeigen.';
5256
$string['config_logreceivedmails'] = 'Zusätzliches Logging von E-mails zu Nutzern.';
5357
$string['config_logreceivedmails_desc'] = 'Das Schreiben in die Datenbank hat den Vorteil, dass es explizit nachgeguckt werden kann, allerdings verbraucht es Speicher.';
5458
$string['config_showcoursecounts'] = 'Zeige Anzahl der Kurse, die getriggert werden';

lang/en/tool_lifecycle.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@
5353
$string['config_backup_path'] = 'Path of the lifecycle backup folder';
5454
$string['config_backup_path_desc'] = 'This settings defines the storage location of the backups created by the backup step.
5555
The path has to be specified as an absolute path on your server.';
56+
$string['config_coursecategorydepth'] = 'Depth of categories to be shown in the interaction table';
57+
$string['config_coursecategorydepth_desc'] = 'By default the first category is shown when teachers manage the status of their courses on the view.php. The setting enables to show not the first level of categories but subcategories.';
5658
$string['config_delay_duration'] = 'Default duration of a course delay';
5759
$string['config_delay_duration_desc'] = 'This setting defines the default delay duration of a workflow
5860
in case one of its processes is rolled back or finishes.
5961
The delay duration determines how long a course will be excepted from being processed again in either of the cases.';
62+
$string['config_enablecategoryhierachy'] = 'Show a specified level of the course category hierarchy in the interaction table';
63+
$string['config_enablecategoryhierachy_desc'] = 'By default the directly assigned course category is shown when teachers manage the status of their courses on the view.php. The setting enables to show a specified level of the course category tree.';
6064
$string['config_logreceivedmails'] = 'Save sent mails to the database';
6165
$string['config_logreceivedmails_desc'] = 'Additionally writing to the database has the advantage that it can be looked up, however it consumes memory.';
6266
$string['config_showcoursecounts'] = 'Show amount of courses which will be triggered';

settings.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@
4646
get_string('config_showcoursecounts', 'tool_lifecycle'),
4747
get_string('config_showcoursecounts_desc', 'tool_lifecycle'),
4848
1));
49+
$settingenablehierachy = new admin_setting_configcheckbox('tool_lifecycle/enablecategoryhierachy',
50+
get_string('config_enablecategoryhierachy', 'tool_lifecycle'),
51+
get_string('config_enablecategoryhierachy_desc', 'tool_lifecycle'),
52+
false);
53+
$settings->add($settingenablehierachy);
54+
$coursehierachysetting = new admin_setting_configtext('tool_lifecycle/coursecategorydepth',
55+
get_string('config_coursecategorydepth', 'tool_lifecycle'),
56+
get_string('config_coursecategorydepth_desc', 'tool_lifecycle'),
57+
0, PARAM_INT);
58+
$coursehierachysetting->add_dependent_on('tool_lifecycle/enablecategoryhierachy');
59+
$settings->add($coursehierachysetting);
60+
$settings->hide_if('tool_lifecycle/coursecategorydepth', 'tool_lifecycle/enablecategoryhierachy', 'notchecked');
4961

5062
$settings->add(new admin_setting_configcheckbox('tool_lifecycle/logreceivedmails',
5163
get_string('config_logreceivedmails', 'tool_lifecycle'),

step/email/interactionlib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function get_due_date($processid, $stepid) {
126126
$date += $settings['responsetimeout'];
127127
}
128128
}
129-
// TODO default format -- seconds -> not in this class !
129+
// Software enhancement default format -- seconds -> not in this class !
130130
return date('d.m.Y', $date);
131131
}
132132

0 commit comments

Comments
 (0)