1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace mod_assign\task;
|
|
|
18 |
|
|
|
19 |
use core\task\adhoc_task;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Ad-hoc task to recalculate penalties for users in an assignment.
|
|
|
23 |
*
|
|
|
24 |
* @package mod_assign
|
|
|
25 |
* @copyright 2024 David Woloszyn <david.woloszyn@moodle.com>
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
*/
|
|
|
28 |
class recalculate_penalties extends adhoc_task {
|
|
|
29 |
#[\Override]
|
|
|
30 |
public function execute(): void {
|
|
|
31 |
global $CFG, $DB;
|
|
|
32 |
|
|
|
33 |
require_once($CFG->dirroot . '/mod/assign/lib.php');
|
|
|
34 |
require_once($CFG->dirroot . '/course/lib.php');
|
|
|
35 |
|
|
|
36 |
$assignid = $this->get_custom_data()->assignid;
|
|
|
37 |
$assign = $DB->get_record('assign', ['id' => $assignid], '*', MUST_EXIST);
|
|
|
38 |
$cm = get_coursemodule_from_instance('assign', $assignid, 0, false, MUST_EXIST);
|
|
|
39 |
$assign->cmidnumber = $cm->idnumber;
|
|
|
40 |
assign_update_grades($assign);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Queue the task.
|
|
|
45 |
*
|
|
|
46 |
* @param int $assignid assignment id
|
|
|
47 |
* @param int $usermodified user who triggered the recalculation
|
|
|
48 |
*/
|
|
|
49 |
public static function queue(int $assignid, int $usermodified): void {
|
|
|
50 |
$task = new self();
|
|
|
51 |
$task->set_custom_data((object) [
|
|
|
52 |
'assignid' => $assignid,
|
|
|
53 |
'usermodified' => $usermodified,
|
|
|
54 |
]);
|
|
|
55 |
\core\task\manager::queue_adhoc_task($task);
|
|
|
56 |
}
|
|
|
57 |
}
|