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
 * Event for when a new blog entry is associated with a context.
18
 *
19
 * @package    core
20
 * @copyright  2013 onwards Ankit Agarwal
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
namespace core\event;
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
/**
28
 * Class for event to be triggered when a new blog entry is associated with a context.
29
 *
30
 * @property-read array $other {
31
 *      Extra information about event.
32
 *
33
 *      - string associatetype: type of blog association, course/coursemodule.
34
 *      - int blogid: id of blog.
35
 *      - int associateid: id of associate.
36
 *      - string subject: blog subject.
37
 * }
38
 *
39
 * @package    core
40
 * @since      Moodle 2.7
41
 * @copyright  2013 onwards Ankit Agarwal
42
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43
 */
44
class blog_association_created extends base {
45
 
46
    /**
47
     * Set basic properties for the event.
48
     */
49
    protected function init() {
50
        $this->context = \context_system::instance();
51
        $this->data['objecttable'] = 'blog_association';
52
        $this->data['crud'] = 'c';
53
        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
54
    }
55
 
56
    /**
57
     * Returns localised general event name.
58
     *
59
     * @return string
60
     */
61
    public static function get_name() {
62
        return get_string('eventblogassociationadded', 'core_blog');
63
    }
64
 
65
    /**
66
     * Returns non-localised event description with id's for admin use only.
67
     *
68
     * @return string
69
     */
70
    public function get_description() {
71
        return "The user with id '$this->userid' associated the context '{$this->other['associatetype']}' with id " .
72
            "'{$this->other['associateid']}' to the blog entry with id '{$this->other['blogid']}'.";
73
    }
74
 
75
    /**
76
     * Returns relevant URL.
77
     * @return \moodle_url
78
     */
79
    public function get_url() {
80
        return new \moodle_url('/blog/index.php', array('entryid' => $this->other['blogid']));
81
    }
82
 
83
    /**
84
     * Custom validations.
85
     *
86
     * @throws \coding_exception when validation fails.
87
     * @return void
88
     */
89
    protected function validate_data() {
90
        parent::validate_data();
91
 
92
        if (!isset($this->relateduserid)) {
93
            throw new \coding_exception('The \'relateduserid\' must be set.');
94
        }
95
 
96
        if (empty($this->other['associatetype']) || ($this->other['associatetype'] !== 'course'
97
                && $this->other['associatetype'] !== 'coursemodule')) {
98
            throw new \coding_exception('The \'associatetype\' value must be set in other and be a valid type.');
99
        }
100
 
101
        if (!isset($this->other['blogid'])) {
102
            throw new \coding_exception('The \'blogid\' value must be set in other.');
103
        }
104
 
105
        if (!isset($this->other['associateid'])) {
106
            throw new \coding_exception('The \'associateid\' value must be set in other.');
107
        }
108
 
109
        if (!isset($this->other['subject'])) {
110
            throw new \coding_exception('The \'subject\' value must be set in other.');
111
        }
112
    }
113
 
114
    public static function get_objectid_mapping() {
115
        // Blogs are not included in backups, so no mapping required for restore.
116
        return array('db' => 'blog_association', 'restore' => base::NOT_MAPPED);
117
    }
118
 
119
    public static function get_other_mapping() {
120
        // Blogs are not included in backups, so no mapping required for restore.
121
        $othermapped = array();
122
        $othermapped['blogid'] = array('db' => 'post', 'restore' => base::NOT_MAPPED);
123
        // The associateid field is varying (context->instanceid) so cannot be mapped.
124
 
125
        return $othermapped;
126
    }
127
}