Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 tool_courserating\event;
18
 
19
use tool_courserating\local\models\rating;
20
 
21
/**
22
 * Event rating deleted
23
 *
24
 * @package     tool_courserating
25
 * @copyright   2022 Marina Glancy <marina.glancy@gmail.com>
26
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
class rating_deleted extends \core\event\base {
29
 
30
    /**
31
     * Init
32
     */
33
    protected function init() {
34
        $this->data['crud'] = 'd';
35
        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
36
        $this->data['objecttable'] = rating::TABLE;
37
    }
38
 
39
    /**
40
     * Event name
41
     *
42
     * @return string
43
     */
44
    public static function get_name(): string {
45
        return get_string('event:rating_deleted', 'tool_courserating');
46
    }
47
 
48
    /**
49
     * Event description
50
     *
51
     * @return string
52
     */
53
    public function get_description(): string {
54
        return "User {$this->userid} has deleted course rating made by the user with id {$this->relateduserid}. ".
55
            "The old rating was ".$this->other['oldrating']." and the review had been flagged ".
56
            $this->other['flagcount']." times. Reason provided: ".s($this->other['reason']);
57
    }
58
 
59
    /**
60
     * Shortcut to create an instance of event
61
     *
62
     * @param \stdClass $recordold
63
     * @param int $flagcount
64
     * @param string $reason
65
     * @return self
66
     */
67
    public static function create_from_rating(\stdClass $recordold, int $flagcount, string $reason): self {
68
        /** @var self $event */
69
        $event = static::create([
70
            'objectid' => $recordold->id,
71
            'courseid' => $recordold->courseid,
72
            'context' => \context_course::instance($recordold->courseid, IGNORE_MISSING) ?? \context_system::instance(),
73
            'relateduserid' => $recordold->userid,
74
            'other' => ['oldrating' => $recordold->rating, 'flagcount' => $flagcount, 'reason' => $reason],
75
        ]);
76
        $event->add_record_snapshot($event->data['objecttable'], $recordold);
77
        return $event;
78
    }
79
}