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
/**
18
 * Notificationeabc enrolment plugin.
19
 *
20
 * This plugin notifies users when an event occurs on their enrolments (enrol, unenrol, update enrolment)
21
 *
22
 * @package    enrol_notificationeabc
23
 * @copyright  2017 e-ABC Learning
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @author     Osvaldo Arriola <osvaldo@e-abclearning.com>
26
 */
27
 
28
defined('MOODLE_INTERNAL') || die();
29
require_once($CFG->dirroot . '/enrol/notificationeabc/lib.php');
30
 
31
/**
32
 * Observer definition
33
 *
34
 * @package    enrol_notificationeabc
35
 * @copyright  2017 e-ABC Learning
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 * @author     Osvaldo Arriola <osvaldo@e-abclearning.com>
38
 */
39
class enrol_notificationeabc_observer
40
{
41
 
42
    /**
43
     * hook enrol event
44
     * @param \core\event\user_enrolment_deleted $event
45
     */
46
    public static function user_unenroled(\core\event\user_enrolment_deleted $event) {
47
        global $DB;
48
 
49
        // Validate status plugin.
50
        $enableplugins = get_config(null, 'enrol_plugins_enabled');
51
        $enableplugins = explode(',', $enableplugins);
52
        $enabled = false;
53
        foreach ($enableplugins as $enableplugin) {
54
            if ($enableplugin === 'notificationeabc') {
55
                $enabled = true;
56
            }
57
        }
58
        if ($enabled) {
59
            $user = $DB->get_record('user', array('id' => $event->relateduserid));
60
            $course = $DB->get_record('course', array('id' => $event->courseid));
61
 
62
            $notificationeabc = new enrol_notificationeabc_plugin();
63
 
64
            $activeglobal = $notificationeabc->get_config('activarglobalunenrolalert');
65
            $activeunenrolalert = $notificationeabc->get_config('activeunenrolalert');
66
 
67
            $enrol = $DB->get_record('enrol', array('enrol' => 'notificationeabc', 'courseid' => $event->courseid));
68
 
69
            /*
70
            * check the instance status
71
            * status = 0 enabled and status = 1 disabled
72
            */
73
            $instanceenabled = false;
74
            if (!empty($enrol)) {
75
                if (!$enrol->status) {
76
                    $instanceenabled = true;
77
                }
78
            }
79
            if (!empty($enrol) && $instanceenabled) {
80
                $activeunenrolalert = $enrol->customint4;
81
            }
82
 
83
            if ($activeglobal == 1 && $activeunenrolalert == 1) {
84
                $notificationeabc->enviarmail($user, $course, 2);
85
            } else if (!empty($enrol) && !empty($activeunenrolalert) && $instanceenabled) {
86
                $notificationeabc->enviarmail($user, $course, 2);
87
            }
88
        }
89
    }
90
 
91
    /**
92
     * hook user update event
93
     * @param \core\event\user_enrolment_updated $event
94
     */
95
    public static function user_updated(\core\event\user_enrolment_updated $event) {
96
        global $DB;
97
 
98
        // Validate plugin status in system context.
99
        $enableplugins = get_config(null, 'enrol_plugins_enabled');
100
        $enableplugins = explode(',', $enableplugins);
101
        $enabled = false;
102
        foreach ($enableplugins as $enableplugin) {
103
            if ($enableplugin === 'notificationeabc') {
104
                $enabled = true;
105
            }
106
        }
107
        if ($enabled) {
108
            $user = $DB->get_record('user', array('id' => $event->relateduserid));
109
            $course = $DB->get_record('course', array('id' => $event->courseid));
110
 
111
            $notificationeabc = new enrol_notificationeabc_plugin();
112
 
113
            $activeglobal = $notificationeabc->get_config('activarglobalenrolupdated');
114
            $activeenrolupdatedalert = $notificationeabc->get_config('activeenrolupdatedalert');
115
 
116
            // Plugin instance in course.
117
            $enrol = $DB->get_record('enrol', array('enrol' => 'notificationeabc', 'courseid' => $event->courseid));
118
 
119
            /*
120
            * check the instance status
121
            * status = 0 enabled and status = 1 disabled
122
            */
123
            $instanceenabled = false;
124
            if (!empty($enrol)) {
125
                if (!$enrol->status) {
126
                    $instanceenabled = true;
127
                }
128
            }
129
            if (!empty($enrol) && $instanceenabled) {
130
                $activeenrolupdatedalert = $enrol->customint5;
131
            }
132
 
133
            if ($activeglobal == 1 && $activeenrolupdatedalert == 1) {
134
                $notificationeabc->enviarmail($user, $course, 3);
135
            } else if (!empty($enrol) && !empty($activeenrolupdatedalert) && $instanceenabled) {
136
                $notificationeabc->enviarmail($user, $course, 3);
137
            }
138
        }
139
    }
140
 
141
    /**
142
     * hook enrolment event
143
     * @param \core\event\user_enrolment_created $event
144
     */
145
    public static function user_enroled(\core\event\user_enrolment_created $event) {
146
        global $DB;
147
 
148
        // Validate plugin status in system context.
149
        $enableplugins = get_config(null, 'enrol_plugins_enabled');
150
        $enableplugins = explode(',', $enableplugins);
151
        $enabled = false;
152
        foreach ($enableplugins as $enableplugin) {
153
            if ($enableplugin === 'notificationeabc') {
154
                $enabled = true;
155
            }
156
        }
157
        if ($enabled) {
158
            $user = $DB->get_record('user', array('id' => $event->relateduserid));
159
            $course = $DB->get_record('course', array('id' => $event->courseid));
160
 
161
            $notificationeabc = new enrol_notificationeabc_plugin();
162
 
163
            $activeglobal = $notificationeabc->get_config('activarglobal');
164
            $activeenrolalert = $notificationeabc->get_config('activeenrolalert');
165
 
166
            $enrol = $DB->get_record('enrol', array('enrol' => 'notificationeabc', 'courseid' => $event->courseid));
167
 
168
            /*
169
            * check the instance status
170
            * status = 0 enabled and status = 1 disabled
171
            */
172
            $instanceenabled = false;
173
            if (!empty($enrol)) {
174
                if (!$enrol->status) {
175
                    $instanceenabled = true;
176
                }
177
            }
178
 
179
            if (!empty($enrol) && $instanceenabled) {
180
                $activeenrolalert = $enrol->customint3;
181
            }
182
 
183
            if ($activeglobal == 1 && $activeenrolalert == 1) {
184
                $notificationeabc->enviarmail($user, $course, 1);
185
            } else if (!empty($enrol) && !empty($activeenrolalert) && $instanceenabled) {
186
                $notificationeabc->enviarmail($user, $course, 1);
187
            }
188
        }
189
    }
190
}