Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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;
18
 
19
use core\context;
20
use mod_assign\task\recalculate_penalties;
21
 
22
/**
23
 * Recalculate penalties for the assignment.
24
 *
25
 * @package   mod_assign
26
 * @copyright 2025 Catalyst IT Australia Pty Ltd
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class penalty_recalculator extends \core_grades\penalty_recalculator {
30
    #[\Override]
31
    public static function recalculate_penalty(context $context, int $usermodified): void {
32
        global $CFG, $DB;
33
 
34
        require_once($CFG->dirroot . '/mod/assign/locallib.php');
35
 
36
        switch ($context->contextlevel) {
37
            case CONTEXT_MODULE:
38
                $cmid = $context->instanceid;
39
                $cm = get_coursemodule_from_id('assign', $cmid, 0, false, MUST_EXIST);
40
                recalculate_penalties::queue($cm->instance, $usermodified);
41
                break;
42
            case CONTEXT_COURSE:
43
                $courseid = $context->instanceid;
44
                $assigns = $DB->get_records('assign', ['course' => $courseid]);
45
                foreach ($assigns as $assign) {
46
                    recalculate_penalties::queue($assign->id, $usermodified);
47
                }
48
                break;
49
        }
50
    }
51
}