Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 76 additions & 102 deletions classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,175 +15,149 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Notificationeabc enrolment plugin.
* Notification enrolment plugin.
*
* This plugin notifies users when an event occurs on their enrolments (enrol, unenrol, update enrolment)
*
* @package enrol_notificationeabc
* @package enrol_notification
* @copyright 2017 e-ABC Learning
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Osvaldo Arriola <osvaldo@e-abclearning.com>
*/

defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/enrol/notificationeabc/lib.php');
require_once($CFG->dirroot . '/enrol/notification/lib.php');

/**
* Observer definition
*
* @package enrol_notificationeabc
* @package enrol_notification
* @copyright 2017 e-ABC Learning
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Osvaldo Arriola <osvaldo@e-abclearning.com>
*/
class enrol_notificationeabc_observer
class enrol_notification_observer
{

/**
* hook enrol event
* @param \core\event\user_enrolment_deleted $event
* hook enrolment event
* @param \core\event\user_enrolment_created $event
*/
public static function user_unenroled(\core\event\user_enrolment_deleted $event) {
public static function user_enrolled(\core\event\user_enrolment_created $event) {
global $DB;

// Validate status plugin.
// Validate plugin status in system context.
$enableplugins = get_config(null, 'enrol_plugins_enabled');
$enableplugins = explode(',', $enableplugins);
$enabled = false;
foreach ($enableplugins as $enableplugin) {
if ($enableplugin === 'notificationeabc') {
$enabled = true;
}
}
$enabled = in_array('notification', $enableplugins);

if ($enabled) {
$notification = new enrol_notification_plugin();

$user = $DB->get_record('user', array('id' => $event->relateduserid));
$course = $DB->get_record('course', array('id' => $event->courseid));

$notificationeabc = new enrol_notificationeabc_plugin();
$globalenrolalert = $notification->get_config('globalenrolalert');

$activeglobal = $notificationeabc->get_config('activarglobalunenrolalert');
$activeunenrolalert = $notificationeabc->get_config('activeunenrolalert');
$enrol = $DB->get_record('enrol', array('enrol' => 'notification', 'courseid' => $event->courseid));

$enrol = $DB->get_record('enrol', array('enrol' => 'notificationeabc', 'courseid' => $event->courseid));

/*
* check the instance status
* status = 0 enabled and status = 1 disabled
*/
$instanceenabled = false;
if (!empty($enrol)) {
if (!$enrol->status) {
$instanceenabled = true;
if (empty($enrol)) {
// This course does not use this enrolment plugin.
if (!empty($globalenrolalert)) {
// But global use of enrolalert was requested at site level for each course.
$notification->send_email($user, $course, 1);
}
} else {
// This course uses this enrolment plugin.
// Check the instance status. Take care: status = 0 enabled; status = 1 disabled.
if (empty($enrol->status)) {
$localenrolalert = $enrol->customint1;
if (!empty($localenrolalert)) {
$notification->send_email($user, $course, 1);
}
}
}
if (!empty($enrol) && $instanceenabled) {
$activeunenrolalert = $enrol->customint4;
}

if ($activeglobal == 1 && $activeunenrolalert == 1) {
$notificationeabc->enviarmail($user, $course, 2);
} else if (!empty($enrol) && !empty($activeunenrolalert) && $instanceenabled) {
$notificationeabc->enviarmail($user, $course, 2);
}
}
}

/**
* hook user update event
* @param \core\event\user_enrolment_updated $event
* hook unenrolment event
* @param \core\event\user_enrolment_deleted $event
*/
public static function user_updated(\core\event\user_enrolment_updated $event) {
public static function user_unenrolled(\core\event\user_enrolment_deleted $event) {
global $DB;

// Validate plugin status in system context.
// Validate status plugin.
$enableplugins = get_config(null, 'enrol_plugins_enabled');
$enableplugins = explode(',', $enableplugins);
$enabled = false;
foreach ($enableplugins as $enableplugin) {
if ($enableplugin === 'notificationeabc') {
$enabled = true;
}
}
$enabled = in_array('notification', $enableplugins);

if ($enabled) {
$notification = new enrol_notification_plugin();

$user = $DB->get_record('user', array('id' => $event->relateduserid));
$course = $DB->get_record('course', array('id' => $event->courseid));

$notificationeabc = new enrol_notificationeabc_plugin();

$activeglobal = $notificationeabc->get_config('activarglobalenrolupdated');
$activeenrolupdatedalert = $notificationeabc->get_config('activeenrolupdatedalert');
$globalunenrolalert = $notification->get_config('globalunenrolalert');

// Plugin instance in course.
$enrol = $DB->get_record('enrol', array('enrol' => 'notificationeabc', 'courseid' => $event->courseid));
$enrol = $DB->get_record('enrol', array('enrol' => 'notification', 'courseid' => $event->courseid));

/*
* check the instance status
* status = 0 enabled and status = 1 disabled
*/
$instanceenabled = false;
if (!empty($enrol)) {
if (!$enrol->status) {
$instanceenabled = true;
if (empty($enrol)) {
// This course does not use this enrolment plugin.
if (!empty($globalunenrolalert)) {
// But global use of unenrolalert was requested at site level for each course.
$notification->send_email($user, $course, 2);
}
} else {
// This course uses this enrolment plugin.
// Check the instance status. Take care: status = 0 enabled; status = 1 disabled.
if (empty($enrol->status)) {
$localunenrolalert = $enrol->customint2;
if (!empty($localunenrolalert)) {
$notification->send_email($user, $course, 2);
}
}
}
if (!empty($enrol) && $instanceenabled) {
$activeenrolupdatedalert = $enrol->customint5;
}

if ($activeglobal == 1 && $activeenrolupdatedalert == 1) {
$notificationeabc->enviarmail($user, $course, 3);
} else if (!empty($enrol) && !empty($activeenrolupdatedalert) && $instanceenabled) {
$notificationeabc->enviarmail($user, $course, 3);
}
}
}

/**
* hook enrolment event
* @param \core\event\user_enrolment_created $event
* hook user enrolment update event
* @param \core\event\user_enrolment_updated $event
*/
public static function user_enroled(\core\event\user_enrolment_created $event) {
public static function user_updated(\core\event\user_enrolment_updated $event) {
global $DB;

// Validate plugin status in system context.
$enableplugins = get_config(null, 'enrol_plugins_enabled');
$enableplugins = explode(',', $enableplugins);
$enabled = false;
foreach ($enableplugins as $enableplugin) {
if ($enableplugin === 'notificationeabc') {
$enabled = true;
}
}
$enabled = in_array('notification', $enableplugins);

if ($enabled) {
$notification = new enrol_notification_plugin();

$user = $DB->get_record('user', array('id' => $event->relateduserid));
$course = $DB->get_record('course', array('id' => $event->courseid));

$notificationeabc = new enrol_notificationeabc_plugin();

$activeglobal = $notificationeabc->get_config('activarglobal');
$activeenrolalert = $notificationeabc->get_config('activeenrolalert');
$globalenrolmentupdatealert = $notification->get_config('globalenrolmentupdatealert');

$enrol = $DB->get_record('enrol', array('enrol' => 'notificationeabc', 'courseid' => $event->courseid));
$enrol = $DB->get_record('enrol', array('enrol' => 'notification', 'courseid' => $event->courseid));

/*
* check the instance status
* status = 0 enabled and status = 1 disabled
*/
$instanceenabled = false;
if (!empty($enrol)) {
if (!$enrol->status) {
$instanceenabled = true;
if (empty($enrol)) {
// This course does not use this enrolment plugin.
if (!empty($globalenrolmentupdatealert)) {
// But global use of enrolmentupdatealert was requested at site level for each course.
$notification->send_email($user, $course, 3);
}
} else {
// This course uses this enrolment plugin.
// Check the instance status. Take care: status = 0 enabled; status = 1 disabled.
if (empty($enrol->status)) {
$localenrolmentupdatealert = $enrol->customint3;
if (!empty($localenrolmentupdatealert)) {
$notification->send_email($user, $course, 3);
}
}
}

if (!empty($enrol) && $instanceenabled) {
$activeenrolalert = $enrol->customint3;
}

if ($activeglobal == 1 && $activeenrolalert == 1) {
$notificationeabc->enviarmail($user, $course, 1);
} else if (!empty($enrol) && !empty($activeenrolalert) && $instanceenabled) {
$notificationeabc->enviarmail($user, $course, 1);
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Notificationeabc enrolment plugin.
* Notification enrolment plugin.
*
* This plugin notifies users when an event occurs on their enrolments (enrol, unenrol, update enrolment)
*
* @package enrol_notificationeabc
* @package enrol_notification
* @copyright 2017 e-ABC Learning
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Osvaldo Arriola <osvaldo@e-abclearning.com>
Expand All @@ -28,8 +28,8 @@
defined('MOODLE_INTERNAL') || die();

$capabilities = array(
/* Manage user notificationeabc-enrolments. */
'enrol/notificationeabc:manage' => array(
/* Manage user notification-enrolments. */
'enrol/notification:manage' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
Expand All @@ -38,4 +38,13 @@
'manager' => CAP_ALLOW,
)
),
'enrol/notification:config' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
)
),
);
10 changes: 5 additions & 5 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Notificationeabc enrolment plugin.
* Notification enrolment plugin.
*
* This plugin notifies users when an event occurs on their enrolments (enrol, unenrol, update enrolment)
*
* @package enrol_notificationeabc
* @package enrol_notification
* @copyright 2017 e-ABC Learning
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Osvaldo Arriola <osvaldo@e-abclearning.com>
Expand All @@ -31,17 +31,17 @@

array(
'eventname' => '\core\event\user_enrolment_deleted',
'callback' => 'enrol_notificationeabc_observer::user_unenroled',
'callback' => 'enrol_notification_observer::user_unenrolled',
),

array(
'eventname' => '\core\event\user_enrolment_created',
'callback' => 'enrol_notificationeabc_observer::user_enroled',
'callback' => 'enrol_notification_observer::user_enrolled',
),

array(
'eventname' => '\core\event\user_enrolment_updated',
'callback' => 'enrol_notificationeabc_observer::user_updated',
'callback' => 'enrol_notification_observer::user_updated',
)

);
6 changes: 3 additions & 3 deletions db/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Notificationeabc enrolment plugin.
* Notification enrolment plugin.
*
* This plugin notifies users when an event occurs on their enrolments (enrol, unenrol, update enrolment)
*
* @package enrol_notificationeabc
* @package enrol_notification
* @copyright 2017 e-ABC Learning
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Osvaldo Arriola <osvaldo@e-abclearning.com>
Expand All @@ -29,7 +29,7 @@

$messageproviders = array (

'notificationeabc_enrolment' => array(),
'notification_enrolment' => array(),

);

12 changes: 6 additions & 6 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Notificationeabc enrolment plugin.
* Notification enrolment plugin.
*
* This plugin notifies users when an event occurs on their enrolments (enrol, unenrol, update enrolment)
*
* @package enrol_notificationeabc
* @package enrol_notification
* @copyright 2017 e-ABC Learning
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Osvaldo Arriola <osvaldo@e-abclearning.com>
Expand All @@ -28,12 +28,12 @@
defined('MOODLE_INTERNAL') || die();

/**
* Upgrade script
* Upgrade script
* @param int $oldversion
* @return bool
*/
function xmldb_enrol_notificationeabc_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
function xmldb_enrol_notification_upgrade($oldversion) {
global $DB;
// $dbman = $DB->get_manager();
return true;
}
Loading