Skip to content
Merged
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
57 changes: 23 additions & 34 deletions classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class enrol_notificationeabc_observer
* hook enrol event
* @param \core\event\user_enrolment_deleted $event
*/
public static function user_unenroled(\core\event\user_enrolment_deleted $event) {
public static function user_unenrolled(\core\event\user_enrolment_deleted $event) {
global $DB;

// Validate status plugin.
Expand All @@ -61,8 +61,8 @@ public static function user_unenroled(\core\event\user_enrolment_deleted $event)

$notificationeabc = new enrol_notificationeabc_plugin();

$activeglobal = $notificationeabc->get_config('activarglobalunenrolalert');
$activeunenrolalert = $notificationeabc->get_config('activeunenrolalert');
$activeglobal = $notificationeabc->get_config('globalunenrolalert');
$unenrolalert = $notificationeabc->get_config('unenrolalert');

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

Expand All @@ -76,14 +76,11 @@ public static function user_unenroled(\core\event\user_enrolment_deleted $event)
$instanceenabled = true;
}
}
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);
if ($activeglobal == 1 && $unenrolalert == 1) {
$notificationeabc->send_email($user, $course, 2);
} else if (!empty($enrol) && !empty($unenrolalert) && $instanceenabled) {
$notificationeabc->send_email($user, $course, 2);
}
}
}
Expand All @@ -110,8 +107,8 @@ public static function user_updated(\core\event\user_enrolment_updated $event) {

$notificationeabc = new enrol_notificationeabc_plugin();

$activeglobal = $notificationeabc->get_config('activarglobalenrolupdated');
$activeenrolupdatedalert = $notificationeabc->get_config('activeenrolupdatedalert');
$activeglobal = $notificationeabc->get_config('globalenrolupdatealert');
$enrolupdatealert = $notificationeabc->get_config('enrolupdatealert');

// Plugin instance in course.
$enrol = $DB->get_record('enrol', array('enrol' => 'notificationeabc', 'courseid' => $event->courseid));
Expand All @@ -126,14 +123,11 @@ public static function user_updated(\core\event\user_enrolment_updated $event) {
$instanceenabled = true;
}
}
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);
if ($activeglobal == 1 && $enrolupdatealert == 1) {
$notificationeabc->send_email($user, $course, 3);
} else if (!empty($enrol) && !empty($enrolupdatealert) && $instanceenabled) {
$notificationeabc->send_email($user, $course, 3);
}
}
}
Expand All @@ -142,7 +136,7 @@ public static function user_updated(\core\event\user_enrolment_updated $event) {
* hook enrolment event
* @param \core\event\user_enrolment_created $event
*/
public static function user_enroled(\core\event\user_enrolment_created $event) {
public static function user_enrolled(\core\event\user_enrolment_created $event) {
global $DB;

// Validate plugin status in system context.
Expand All @@ -154,36 +148,31 @@ public static function user_enroled(\core\event\user_enrolment_created $event) {
$enabled = true;
}
}

if ($enabled) {
$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');
$activeglobal = $notificationeabc->get_config('globalenrolalert');
$enrolalert = $notificationeabc->get_config('enrolalert');

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

/*
* check the instance status
* status = 0 enabled and status = 1 disabled
*/
// Check the instance status.
// Legend: status = 0 enabled; status = 1 disabled.
$instanceenabled = false;
if (!empty($enrol)) {
if (!$enrol->status) {
$instanceenabled = true;
}
}

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);
if ($activeglobal == 1 && $enrolalert == 1) {
$notificationeabc->send_email($user, $course, 1);
} else if (!empty($enrol) && !empty($enrolalert) && $instanceenabled) {
$notificationeabc->send_email($user, $course, 1);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@
'manager' => CAP_ALLOW,
)
),
'enrol/notificationeabc:config' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
)
),
);
4 changes: 2 additions & 2 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

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

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

array(
Expand Down
6 changes: 3 additions & 3 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
global $DB;
// $dbman = $DB->get_manager();
return true;
}
146 changes: 0 additions & 146 deletions edit.php

This file was deleted.

Loading