Skip to content

Commit 6aae696

Browse files
committed
adminapprove: reintroduce proceed all and rollback all
1 parent 4a1e19b commit 6aae696

File tree

6 files changed

+121
-16
lines changed

6 files changed

+121
-16
lines changed

step/adminapprove/approvestep.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,10 @@
6161
* Constant to roll back selected.
6262
*/
6363
const ROLLBACK = 'rollback';
64-
/**
65-
* Constant to roll back all courses.
66-
*/
67-
const ROLLBACK_ALL = 'rollbackall';
6864
/**
6965
* Constant to proceed selected.
7066
*/
7167
const PROCEED = 'proceed';
72-
/**
73-
* Constant to proceed all courses.
74-
*/
75-
const PROCEED_ALL = 'proceedall';
7668

7769
$workflow = workflow_manager::get_workflow($step->workflowid);
7870

step/adminapprove/classes/decision_table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function __construct($stepid, $courseid, $category, $coursename) {
8383

8484
$this->define_baseurl("/admin/tool/lifecycle/step/adminapprove/approvestep.php?stepid=$stepid");
8585
$this->define_columns(['checkbox', 'courseid', 'course', 'category', 'startdate', 'tools']);
86+
$this->column_class('tools', 'text-nowrap');
8687
$this->define_headers(
8788
[\html_writer::checkbox('checkall', null, false),
8889
get_string('courseid', 'lifecyclestep_adminapprove'),
@@ -174,7 +175,7 @@ public function col_startdate($row) {
174175
}
175176

176177
/**
177-
* Show the availble tool/actions for a column.
178+
* Show the available tool/actions for a column.
178179
* @param object $row
179180
* @return string
180181
* @throws coding_exception
@@ -206,8 +207,7 @@ public function col_tools($row) {
206207
]),
207208
$this->strings['proceedbuttonlabel'],
208209
'post',
209-
single_button::BUTTON_PRIMARY,
210-
['class' => 'mr-1 ml-0 mt-1']
210+
single_button::BUTTON_PRIMARY
211211
);
212212
$output .= $OUTPUT->render($button);
213213

step/adminapprove/classes/step_table.php

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
namespace lifecyclestep_adminapprove;
2626

27+
use core\output\single_button;
28+
use moodle_url;
29+
use tool_lifecycle\urls;
30+
2731
defined('MOODLE_INTERNAL') || die();
2832

2933
global $CFG;
@@ -41,13 +45,18 @@ class step_table extends \table_sql {
4145
public function __construct() {
4246
parent::__construct('lifecyclestep_adminapprove-steptable');
4347
$this->define_baseurl("/admin/tool/lifecycle/step/adminapprove/index.php");
44-
$this->define_columns(['stepname', 'workflowname', 'courses']);
48+
$this->define_columns(['stepname', 'workflowname', 'courses', 'tools']);
4549
$this->define_headers(
46-
[get_string('step', 'tool_lifecycle'), get_string('workflow', 'lifecyclestep_adminapprove'),
47-
get_string('amount_courses', 'lifecyclestep_adminapprove')]);
50+
[get_string('step', 'tool_lifecycle'),
51+
get_string('workflow', 'lifecyclestep_adminapprove'),
52+
get_string('amount_courses', 'lifecyclestep_adminapprove'),
53+
get_string('tools', 'lifecyclestep_adminapprove'),
54+
]
55+
);
4856
$this->set_attribute('id', 'adminapprove-steptable');
4957
$this->sortable(false);
50-
$fields = 's.id as id, s.instancename as stepname, w.title as workflowname, b.courses as courses';
58+
$fields = 's.id as id, s.instancename as stepname, w.title as workflowname, b.courses as courses,
59+
b.workflowid as wfid, b.stepindex as stepindex';
5160
$from = '( ' .
5261
'SELECT p.workflowid, p.stepindex, COUNT(1) as courses FROM {lifecyclestep_adminapprove} a ' .
5362
'JOIN {tool_lifecycle_process} p ON p.id = a.processid ' .
@@ -65,10 +74,62 @@ public function __construct() {
6574
* @return string
6675
*/
6776
public function col_stepname($row) {
77+
6878
return '<div data-stepid="' . $row->id . '" hidden></div> <a href="approvestep.php?stepid='. $row->id .'">'
6979
. $row->stepname . '</a>';
7080
}
7181

82+
/**
83+
* Show the wokflowname.
84+
* @param object $row
85+
* @return string
86+
*/
87+
public function col_workflowname($row) {
88+
$url = new moodle_url(urls::WORKFLOW_DETAILS, ['wf' => $row->wfid]);
89+
$link = \html_writer::link($url, $row->workflowname);
90+
return $link;
91+
}
92+
93+
/**
94+
* Show the available tool/actions for a column.
95+
* @param object $row
96+
* @return string
97+
* @throws coding_exception
98+
* @throws moodle_exception
99+
*/
100+
public function col_tools($row) {
101+
global $OUTPUT;
102+
103+
$button = new \single_button(
104+
new \moodle_url('', [
105+
'action' => 'rollback',
106+
'wfid' => $row->wfid,
107+
'stepindex' => $row->stepindex,
108+
'sesskey' => sesskey(),
109+
]),
110+
get_string('rollbackall', 'lifecyclestep_adminapprove'),
111+
'post',
112+
single_button::BUTTON_SECONDARY,
113+
['class' => 'mr-1']
114+
);
115+
$output = $OUTPUT->render($button);
116+
117+
$button = new \single_button(
118+
new \moodle_url('', [
119+
'action' => 'proceed',
120+
'wfid' => $row->wfid,
121+
'stepindex' => $row->stepindex,
122+
'sesskey' => sesskey(),
123+
]),
124+
get_string('proceedall', 'lifecyclestep_adminapprove'),
125+
'post',
126+
single_button::BUTTON_PRIMARY
127+
);
128+
$output .= $OUTPUT->render($button);
129+
130+
return $output;
131+
}
132+
72133
/**
73134
* Print information if table does not have content.
74135
* @return void

step/adminapprove/index.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,62 @@
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
2424

25+
use tool_lifecycle\local\manager\step_manager;
26+
use tool_lifecycle\local\manager\workflow_manager;
2527
use tool_lifecycle\tabs;
2628
use tool_lifecycle\urls;
2729

2830
require_once(__DIR__ . '/../../../../../config.php');
2931
require_once($CFG->libdir . '/adminlib.php');
3032

3133
require_admin();
34+
$action = optional_param('action', null, PARAM_ALPHANUMEXT);
35+
$wfid = optional_param('wfid', null, PARAM_INT);
36+
$stepindex = optional_param('stepindex', null, PARAM_INT);
37+
38+
/**
39+
* Constant to roll back selected.
40+
*/
41+
const ROLLBACK = 'rollback';
42+
/**
43+
* Constant to proceed selected.
44+
*/
45+
const PROCEED = 'proceed';
3246

3347
$PAGE->set_context(context_system::instance());
34-
$PAGE->set_url(new \moodle_url(urls::SUBPLUGINS));
48+
$PAGE->set_url("/admin/tool/lifecycle/step/adminapprove/index.php");
49+
50+
if ($action) {
51+
require_sesskey();
52+
53+
$subselect = 'SELECT id FROM {tool_lifecycle_process} WHERE workflowid = :wfid AND stepindex = :stepindex';
54+
$params = ['wfid' => $wfid, 'stepindex' => $stepindex];
55+
if ($action == PROCEED || $action == ROLLBACK) {
56+
$sql = 'UPDATE {lifecyclestep_adminapprove} ' .
57+
'SET status = ' . ($action == PROCEED ? 1 : 2) . ' ' .
58+
'WHERE processid IN (' . $subselect . ') ' .
59+
'AND status = 0';
60+
try {
61+
$DB->execute($sql, $params);
62+
} catch (dml_exception $e) {
63+
throw $e;
64+
}
65+
66+
$a = new stdClass();
67+
$step = step_manager::get_step_instance_by_workflow_index($wfid, $stepindex);
68+
$workflow = workflow_manager::get_workflow($wfid);
69+
$a->step = $step->instancename;
70+
$a->workflow = $workflow->title;
71+
72+
if ($action == PROCEED) {
73+
$message = get_string('allstepapprovalsproceed', 'lifecyclestep_adminapprove', $a);
74+
} else if ($action == ROLLBACK) {
75+
$message = get_string('allstepapprovalsrollback', 'lifecyclestep_adminapprove', $a);
76+
}
77+
78+
redirect($PAGE->url, $message);
79+
}
80+
}
3581

3682
$PAGE->set_pagetype('admin-setting-' . 'tool_lifecycle');
3783
$PAGE->set_pagelayout('admin');

step/adminapprove/lang/de/lifecyclestep_adminapprove.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525

2626
$string['adminapprovals'] = 'Admin-Bestätigungen';
27+
$string['allstepapprovalsproceed'] = 'Alle Prozesse im Schritt "{$a->step}" des Workflow "{$a->workflow}" wurden der weiteren Verarbeitung zugewiesen.';
28+
$string['allstepapprovalsrollback'] = 'Alle Prozesse im Schritt "{$a->step}" des Workflow "{$a->workflow}" wurden zurückgesetzt.';
2729
$string['amount_courses'] = 'Anzahl wartender Kurse';
2830
$string['bulkactions'] = 'Massenaktionen';
2931
$string['courseid'] = 'Kurs-ID';
@@ -45,6 +47,7 @@
4547
$string['proceedselectedbuttonlabel'] = 'Ausgewählte fortführen';
4648
$string['proceedselectedbuttonlabel_help'] = 'Ändert die Beschriftung des Buttons \'Ausgewählte fortführen\'. Wenn das Feld leer bleibt, wird die Standardbeschriftung beibehalten.';
4749
$string['rollback'] = 'Zurücksetzten';
50+
$string['rollbackall'] = 'Rollback all';
4851
$string['rollbackbuttonlabel'] = 'Beschriftung des Zurücksetzten-Buttons';
4952
$string['rollbackbuttonlabel_help'] = 'Ändert die Beschriftung des Zurücksetzten-Buttons. Wenn das Feld leer bleibt, wird die Standardbeschriftung beibehalten.';
5053
$string['rollbackselected'] = 'Ausgewählte zurücksetzten';

step/adminapprove/lang/en/lifecyclestep_adminapprove.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424

2525
$string['adminapprovals'] = 'Admin Approvals';
26+
$string['allstepapprovalsproceed'] = 'All pending processes of step "{$a->step}" of the workflow "{$a->workflow}" have been proceeded.';
27+
$string['allstepapprovalsrollback'] = 'All pending processes of step "{$a->step}" of the workflow "{$a->workflow}" have been rolled back.';
2628
$string['amount_courses'] = 'Remaining waiting courses';
2729
$string['bulkactions'] = 'Bulk actions';
2830
$string['cachedef_mformdata'] = 'Caches the mform data';
@@ -47,6 +49,7 @@
4749
$string['proceedselectedbuttonlabel'] = 'Label of the proceed selected button';
4850
$string['proceedselectedbuttonlabel_help'] = 'Option to customize the label of the button \'Proceed selected\'. Leave it empty if you are ok with the default value.';
4951
$string['rollback'] = 'Rollback';
52+
$string['rollbackall'] = 'Rollback all';
5053
$string['rollbackbuttonlabel'] = 'Label of the rollback button';
5154
$string['rollbackbuttonlabel_help'] = 'Option to customize the label of the button \'Rollback\'. Leave it empty if you are ok with the default value.';
5255
$string['rollbackselected'] = 'Rollback selected';

0 commit comments

Comments
 (0)