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\flag;
20
use tool_courserating\local\models\rating;
21
 
22
/**
23
 * Event flag deleted
24
 *
25
 * @package     tool_courserating
26
 * @copyright   2022 Marina Glancy <marina.glancy@gmail.com>
27
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class flag_deleted extends \core\event\base {
30
 
31
    /**
32
     * Init
33
     */
34
    protected function init() {
35
        $this->data['crud'] = 'd';
36
        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
37
        $this->data['objecttable'] = flag::TABLE;
38
    }
39
 
40
    /**
41
     * Event name
42
     *
43
     * @return string
44
     */
45
    public static function get_name(): string {
46
        return get_string('event:flag_deleted', 'tool_courserating');
47
    }
48
 
49
    /**
50
     * Event description
51
     *
52
     * @return string
53
     */
54
    public function get_description(): string {
55
        return "User {$this->userid} has revoked their flag on the course rating made by the user with id {$this->relateduserid}";
56
    }
57
 
58
    /**
59
     * Shortcut to create an instance of event
60
     *
61
     * @param \stdClass $object
62
     * @param rating $rating
63
     * @return self
64
     */
65
    public static function create_from_flag(\stdClass $object, rating $rating): self {
66
        /** @var self $event */
67
        $event = static::create([
68
            'objectid' => $object->id,
69
            'courseid' => $rating->get('courseid'),
70
            'relateduserid' => $rating->get('userid'),
71
            'context' => \context_course::instance($rating->get('courseid')),
72
            'other' => ['ratingid' => $object->id],
73
        ]);
74
        $event->add_record_snapshot($event->data['objecttable'], $object);
75
        $event->add_record_snapshot(rating::TABLE, $rating->to_record());
76
        return $event;
77
    }
78
}