Skip to content

Commit 50e453e

Browse files
committed
add adhoc cron for batch synchronization
1 parent 174a7b6 commit 50e453e

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

classes/local/table/remaining_courses_table.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ class remaining_courses_table extends \table_sql {
4242

4343
private evasys_category $evasyscategory;
4444

45+
private bool $showbuttons;
46+
4547
/**
4648
* Constructor for course_manager_table.
4749
*/
48-
public function __construct($categoryids, $semester, evasys_category $evasyscategory, $coursefullname = null) {
50+
public function __construct($categoryids, $semester, evasys_category $evasyscategory, $coursefullname = null, bool $showbuttons = true) {
4951
parent::__construct('block_evasys_sync-course_manager_table');
5052
global $DB, $PAGE, $OUTPUT;
5153

5254
$this->evasyscategory = $evasyscategory;
55+
$this->showbuttons = $showbuttons;
5356

5457
$fields = 'c.id as courseid, c.fullname as coursename, cfd.intvalue as semester';
5558

@@ -134,7 +137,7 @@ public function col_teacher($row) {
134137
*/
135138
public function col_tools($row) {
136139
global $PAGE, $OUTPUT;
137-
if (!$this->evasyscategory->default_period_set()) {
140+
if (!$this->evasyscategory->default_period_set() || !$this->showbuttons) {
138141
return '';
139142
}
140143
return $OUTPUT->render(new \single_button(new moodle_url($PAGE->url, ['action' => 'seteval', 'ids[]' => $row->courseid]),
@@ -155,7 +158,7 @@ public function wrap_html_finish() {
155158
parent::wrap_html_finish();
156159
echo "<br>";
157160

158-
if (!$this->evasyscategory->default_period_set()) {
161+
if (!$this->evasyscategory->default_period_set() || !$this->showbuttons) {
159162
return;
160163
}
161164

classes/task/evasys_bulk_task.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace block_evasys_sync\task;
4+
5+
use core\task\adhoc_task;
6+
7+
class evasys_bulk_task extends adhoc_task{
8+
9+
public function execute()
10+
{
11+
$data = $this->get_custom_data();
12+
$courses = $data->courses;
13+
$evasyscategory = $data->evasyscategory;
14+
if(empty($evasyscategory) || empty($courses)){
15+
mtrace("No category or courses specified, exiting.");
16+
}
17+
$errors = \block_evasys_sync\evaluation_manager::set_default_evaluation_for($courses, $evasyscategory);
18+
if ($errors) {
19+
$erroroutput = '';
20+
foreach ($errors as $courseid => $error) {
21+
$erroroutput .= $courseid . ': ' . $error . '<br>';
22+
}
23+
mtrace($erroroutput);
24+
}
25+
}
26+
}

lang/en/block_evasys_sync.php

+2
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,5 @@
301301
$string['missing_course_id'] = 'Missing course id! Please contact the Learnweb support with a link to the course in HIS LSF which should be evaluated.';
302302
$string['no_evasys_course_found'] = 'No matching EvaSys-Course found! Please contact your evaluation coordinator.';
303303
$string['not_inside_evaluation_category'] = 'This course isn\'t inside any evaluation category! Please contact the Learnweb support.';
304+
305+
$string["running_crontask"] = "The synchronization to Evasys is currently being processed. This may take a few minutes. Please wait and reload the page.";

managecategory_remaining.php

+21-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
use block_evasys_sync\local\table\remaining_courses_table;
26+
use block_evasys_sync\task\evasys_bulk_task;
2627
use customfield_semester\data_controller;
2728

2829
require_once(__DIR__ . '/../../config.php');
@@ -50,13 +51,18 @@
5051
if ($action === 'seteval') {
5152
require_sesskey();
5253
$courses = required_param_array('ids', PARAM_INT);
53-
$errors = \block_evasys_sync\evaluation_manager::set_default_evaluation_for($courses, $evasyscategory);
54-
if ($errors) {
55-
$erroroutput = '';
56-
foreach ($errors as $courseid => $error) {
57-
$erroroutput .= $courseid . ': ' . $error . '<br>';
58-
}
59-
\core\notification::error($erroroutput);
54+
$queuedtasks = \core\task\manager::get_adhoc_tasks(evasys_bulk_task::class);
55+
$tasksofcurrentmodule = array_filter($queuedtasks, fn($task) => $task->get_custom_data()->evasyscategory === $evasyscategory);
56+
if(empty($tasksofcurrentmodule)){
57+
$task = new evasys_bulk_task();
58+
$data = new stdClass();
59+
$data->courses = $courses;
60+
$data->evasyscategory = $evasyscategory;
61+
$task->set_custom_data($data);
62+
$task->set_userid($USER->id);
63+
\core\task\manager::queue_adhoc_task($task, true);
64+
} else {
65+
\core\notification::warning(get_string("running_crontask", "block_evasys"));
6066
}
6167
redirect($PAGE->url);
6268
}
@@ -72,7 +78,10 @@
7278

7379
$catids = array_merge($category->get_all_children_ids(), [$category->id]);
7480

75-
$table = new remaining_courses_table($catids, $data->semester ?? null, $evasyscategory, $data->coursename ?? null);
81+
$queuedtasks = \core\task\manager::get_adhoc_tasks(evasys_bulk_task::class);
82+
$tasksofcurrentmodule = array_filter($queuedtasks, fn($task) => $task->get_custom_data()->evasyscategory === $evasyscategory);
83+
84+
$table = new remaining_courses_table($catids, $data->semester ?? null, $evasyscategory, $data->coursename ?? null, empty($tasksofcurrentmodule));
7685
$table->define_baseurl($PAGE->url);
7786

7887
$PAGE->navigation->add('EvaSys', new moodle_url('/blocks/evasys_sync/manageroverview.php'))
@@ -87,6 +96,10 @@
8796
$renderer = $PAGE->get_renderer('block_evasys_sync');
8897
$renderer->print_evasys_category_header($evasyscategory);
8998

99+
if(!empty($tasksofcurrentmodule)){
100+
\core\notification::warning(get_string("running_crontask", "block_evasys"));
101+
}
102+
90103
$table->out(48, false);
91104

92105
echo $OUTPUT->footer();

0 commit comments

Comments
 (0)