Skip to content

Commit e33088d

Browse files
committed
merge accept theirs
2 parents 4de461d + 25f46d5 commit e33088d

File tree

2 files changed

+214
-3
lines changed

2 files changed

+214
-3
lines changed

classes/local/table/interaction_remaining_table.php

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class interaction_remaining_table extends interaction_table {
4343

4444
/** @var manual_trigger_tool[] $availabletools list of all available trigger tools. */
4545
private $availabletools;
46+
/** @var array[] $trigger2courses map from manual trigger id to courses that are selected by
47+
* automatic trigger(s) which is (are) associated to manual trigger.
48+
*/
49+
private $trigger2courses = [];
4650

4751
/**
4852
* Constructor for deactivated_workflows_table.
@@ -51,9 +55,41 @@ class interaction_remaining_table extends interaction_table {
5155
*/
5256
public function __construct($uniqueid, $courseids) {
5357
parent::__construct($uniqueid);
54-
global $PAGE, $CFG;
58+
global $PAGE, $CFG, $DB;
5559

5660
$this->availabletools = workflow_manager::get_manual_trigger_tools_for_active_workflows();
61+
foreach ($this->availabletools as $tool) {
62+
// Check if there is an automatic trigger associated with the manual trigger.
63+
$records = $DB->get_records_select('tool_lifecycle_trigger', "subpluginname != :plugin and workflowid in
64+
(select workflowid from {tool_lifecycle_trigger} where id = :id)",
65+
['id' => $tool->triggerid, 'plugin' => 'manual']);
66+
if ($records && count($records) > 0) {
67+
$first = reset($records);
68+
// There is at least one automatic trigger associated
69+
// => check for AND condition.
70+
$field = $DB->get_field('tool_lifecycle_workflow', 'andor', ['id' => $first->workflowid]);
71+
if ($field) {
72+
// No AND condition => OR condition is not supported.
73+
echo 'OR condition is not supported.<br>';
74+
continue;
75+
}
76+
// Ok, we have an AND condition =>
77+
// Store courses selected by this (these) trigger(s).
78+
$triggers = [];
79+
foreach ($records as $record) {
80+
$triggers[] = $record;
81+
}
82+
if (count($triggers) > 0) {
83+
$processor = new \tool_lifecycle\processor();
84+
$recordset = $processor->get_course_recordset($triggers);
85+
$courses = [];
86+
foreach ($recordset as $element) {
87+
$courses[] = $element->id;
88+
}
89+
$this->trigger2courses[$tool->triggerid] = $courses;
90+
}
91+
}
92+
}
5793

5894
// COALESCE returns l.time if l.time != null and 0 otherwise.
5995
// We need to do this, so that courses without any action have a smaller timestamp than courses with an recorded action.
@@ -122,7 +158,7 @@ public function init() {
122158
* @throws \moodle_exception
123159
*/
124160
public function col_tools($row) {
125-
global $PAGE, $OUTPUT;
161+
global $PAGE, $OUTPUT, $DB;
126162

127163
if ($row->processid !== null) {
128164
return '--';
@@ -132,7 +168,27 @@ public function col_tools($row) {
132168
}
133169
$actions = [];
134170
foreach ($this->availabletools as $tool) {
135-
if (has_capability($tool->capability, \context_course::instance($row->courseid), null, true)) {
171+
// Check if the manual trigger has at least one automatic trigger associated.
172+
if (array_key_exists($tool->triggerid, $this->trigger2courses)) {
173+
// There is at least one automatic trigger =>
174+
// Check if 'this' course is included in course set.
175+
$found = false;
176+
foreach ($this->trigger2courses[$tool->triggerid] as $element) {
177+
if ($row->courseid === $element) {
178+
// Course is included in course set of automatic trigger(s).
179+
$found = true;
180+
break;
181+
}
182+
}
183+
if (!$found) {
184+
// Course is not included in automatic trigger(s) set
185+
// => do not display action in action menu.
186+
continue;
187+
}
188+
}
189+
190+
// Check capability.
191+
if (has_capability($tool->capability, \context_course::instance($row->courseid), null, false)) {
136192
$actions[$tool->triggerid] = new \action_menu_link_secondary(
137193
new \moodle_url($PAGE->url, ['triggerid' => $tool->triggerid,
138194
'courseid' => $row->courseid, 'sesskey' => sesskey(), ]),
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
@tool @tool_lifecycle @manual_trigger
2+
Feature: Combine triggers with 'and' operation and test view and actions
3+
4+
Background:
5+
Given the following "users" exist:
6+
| username | firstname | lastname | email |
7+
| teacher1 | Teacher | 1 | teacher1@example.com |
8+
| teacher2 | Teacher | 2 | teacher2@example.com |
9+
And the following "categories" exist:
10+
| name | category | idnumber |
11+
| cata | 0 | cata |
12+
| catba | cata | catba |
13+
| catc | 0 | catc |
14+
| archive | 0 | archive |
15+
And the following "courses" exist:
16+
| fullname | shortname | category |
17+
| Course A | CA | cata |
18+
| Course BA | CBA | catba |
19+
| Course C | CC | catc |
20+
| ArchCourse | CArch | archive |
21+
And the following "course enrolments" exist:
22+
| user | course | role |
23+
| teacher1 | CA | editingteacher |
24+
| teacher1 | CBA | editingteacher |
25+
| teacher1 | CC | editingteacher |
26+
| teacher1 | CArch | editingteacher |
27+
| teacher2 | CA | editingteacher |
28+
| teacher2 | CBA | student |
29+
| teacher2 | CC | student |
30+
| teacher2 | CArch | editingteacher |
31+
32+
@javascript
33+
Scenario: Combine manual trigger with automatic categories trigger (backup and course deletion)
34+
# => category archive is excluded, so course ArchCourse shall not be deleted
35+
Given I log in as "admin"
36+
And I am on workflowdrafts page
37+
And I click on "Create new workflow" "link"
38+
And I set the following fields to these values:
39+
| Title | My Workflow |
40+
| Displayed workflow title | Teachers view on workflow |
41+
And I press "Save changes"
42+
And I select "Manual trigger" from the "tool_lifecycle-choose-trigger" singleselect
43+
And I set the following fields to these values:
44+
| Instance name | My Trigger |
45+
| Icon | t/delete |
46+
| Action name | Delete course |
47+
| Capability | moodle/course:manageactivities |
48+
And I press "Save changes"
49+
50+
And I select "Categories trigger" from the "tool_lifecycle-choose-trigger" singleselect
51+
And I set the following fields to these values:
52+
| Instance name | Categories |
53+
And I set the following fields to these values:
54+
| Categories, for which the workflow should be triggered | cata, catc |
55+
And I press "Save changes"
56+
57+
And I select "Create backup step" from the "tool_lifecycle-choose-step" singleselect
58+
And I set the field "Instance name" to "Create backup step"
59+
And I press "Save changes"
60+
And I select "Delete course step" from the "tool_lifecycle-choose-step" singleselect
61+
And I set the field "Instance name" to "Delete Course 2"
62+
And I press "Save changes"
63+
64+
And I am on workflowdrafts page
65+
And I press "Activate"
66+
And I log out
67+
And I log in as "teacher1"
68+
69+
And I am on lifecycle view
70+
Then I should see the tool "Delete course" in the "Course A" row of the "tool_lifecycle_remaining" table
71+
And I should see the tool "Delete course" in the "Course BA" row of the "tool_lifecycle_remaining" table
72+
And I should see the tool "Delete course" in the "Course C" row of the "tool_lifecycle_remaining" table
73+
And I should not see "Action" in the "ArchCourse" "table_row"
74+
75+
When I click on the tool "Delete course" in the "Course C" row of the "tool_lifecycle_remaining" table
76+
And I should not see the tool "Delete course" in the "Course C" row of the "tool_lifecycle_remaining" table
77+
And I should see the tool "Delete course" in the "Course BA" row of the "tool_lifecycle_remaining" table
78+
And I should see the tool "Delete course" in the "Course A" row of the "tool_lifecycle_remaining" table
79+
When I log out
80+
And I log in as "admin"
81+
And I run the scheduled task "tool_lifecycle\task\lifecycle_task"
82+
And I wait "5" seconds
83+
And I run the scheduled task "tool_lifecycle\task\lifecycle_task"
84+
And I wait "5" seconds
85+
And I run the scheduled task "tool_lifecycle\task\lifecycle_task"
86+
And I wait "5" seconds
87+
And I log out
88+
And I log in as "teacher1"
89+
And I am on lifecycle view
90+
Then I should not see "Course C"
91+
And I should see "Course BA"
92+
And I should see "Course A"
93+
And I should see "ArchCourse"
94+
When I log out
95+
And I log in as "admin"
96+
And I am on coursebackups page
97+
Then I should see "Course C"
98+
And I should not see "Course BA"
99+
And I should not see "Course A"
100+
And I should not see "ArchCourse"
101+
102+
@javascript
103+
Scenario: Combine automatic triggers (backup and course deletion)
104+
Given I log in as "admin"
105+
And I am on workflowdrafts page
106+
And I click on "Create new workflow" "link"
107+
And I set the following fields to these values:
108+
| Title | My Workflow |
109+
| Displayed workflow title | Teachers view on workflow |
110+
And I press "Save changes"
111+
112+
And I select "Trigger courses by roles missing" from the "tool_lifecycle-choose-trigger" singleselect
113+
And I set the following fields to these values:
114+
| Instance name | Roles |
115+
| Responsible Roles in courses | student |
116+
And I press "Save changes"
117+
118+
And I select "Categories trigger" from the "tool_lifecycle-choose-trigger" singleselect
119+
And I set the following fields to these values:
120+
| Instance name | Categories |
121+
And I set the following fields to these values:
122+
| Categories, for which the workflow should be triggered | cata, catc |
123+
And I press "Save changes"
124+
125+
And I select "Create backup step" from the "tool_lifecycle-choose-step" singleselect
126+
And I set the field "Instance name" to "Create backup step"
127+
And I press "Save changes"
128+
And I select "Delete course step" from the "tool_lifecycle-choose-step" singleselect
129+
And I set the field "Instance name" to "Delete Course 2"
130+
And I press "Save changes"
131+
132+
And I am on workflowdrafts page
133+
And I press "Activate"
134+
135+
And I run the scheduled task "tool_lifecycle\task\lifecycle_task"
136+
And I wait "2" seconds
137+
And I run the scheduled task "tool_lifecycle\task\lifecycle_task"
138+
And I wait "2" seconds
139+
And I run the scheduled task "tool_lifecycle\task\lifecycle_task"
140+
And I wait "2" seconds
141+
142+
And I log out
143+
And I log in as "teacher1"
144+
And I am on lifecycle view
145+
Then I should not see "Course A"
146+
And I should see "Course BA"
147+
And I should see "Course C"
148+
And I should see "ArchCourse"
149+
When I log out
150+
And I log in as "admin"
151+
And I am on coursebackups page
152+
Then I should see "Course A"
153+
And I should not see "Course BA"
154+
And I should not see "Course CS"
155+
And I should not see "ArchCourse"

0 commit comments

Comments
 (0)