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 updated
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_updated extends \core\event\base {
29
 
30
    /**
31
     * Init
32
     */
33
    protected function init() {
34
        $this->data['crud'] = 'u';
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_updated', 'tool_courserating');
46
    }
47
 
48
    /**
49
     * Event description
50
     *
51
     * @return string
52
     */
53
    public function get_description(): string {
54
        return "User {$this->relateduserid} has changed the rating for the course from ".
55
            $this->other['oldrating']." to ".$this->other['rating'];
56
    }
57
 
58
    /**
59
     * Shortcut to create an instance of event
60
     *
61
     * @param rating $object
62
     * @param \stdClass $recordold
63
     * @return self
64
     */
65
    public static function create_from_rating(rating $object, \stdClass $recordold): self {
66
        /** @var self $event */
67
        $event = static::create([
68
            'objectid' => $object->get('id'),
69
            'courseid' => $object->get('courseid'),
70
            'relateduserid' => $recordold->userid,
71
            'context' => \context_course::instance($object->get('courseid')),
72
            'other' => ['rating' => $object->get('rating'), 'oldrating' => $recordold->rating],
73
        ]);
74
        $event->add_record_snapshot($event->data['objecttable'], $object->to_record());
75
        return $event;
76
    }
77
}