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 created
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_created extends \core\event\base {
29
 
30
    /**
31
     * Init
32
     */
33
    protected function init() {
34
        $this->data['crud'] = 'c';
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_created', '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 rated the course with ".$this->other['rating']." stars";
55
    }
56
 
57
    /**
58
     * Shortcut to create an instance of event
59
     *
60
     * @param rating $object
61
     * @return self
62
     */
63
    public static function create_from_rating(rating $object): self {
64
        /** @var self $event */
65
        $event = static::create([
66
            'objectid' => $object->get('id'),
67
            'courseid' => $object->get('courseid'),
68
            'relateduserid' => $object->get('userid'),
69
            'context' => \context_course::instance($object->get('courseid')),
70
            'other' => ['rating' => $object->get('rating')],
71
        ]);
72
        $event->add_record_snapshot($event->data['objecttable'], $object->to_record());
73
        return $event;
74
    }
75
}