+ */
+
+$string['failsend'] = 'ATENCION: No se pudo notificar al usuario {$a->username} sobre su matriculación en el curso {$a->coursename}'."\n";
+$string['messageprovider:notification_enrolment'] = 'Enrol notification messages';
+$string['notification:manage'] = 'Gestionar notificaciones de matriculación';
+
+$string['pluginname'] = 'Notificación de Matriculación';
+$string['status'] = 'Activar notification de matriculación';
+$string['subject'] = 'Notificación de Matriculación';
+$string['succefullsend'] = 'Se notifico al usuario {$a->username} sobre su matriculación en el curso {$a->coursename}'. "\n";
+
+// Aviso de matriculacion.
+$string['globalenrolalert'] = 'Activar para todo el sitio';
+$string['globalenrolalert_help'] = 'Activa la notificacion de matriculacion para todo los cursos';
+$string['enrolalert'] = 'Activar aviso de matriculación';
+$string['enrolalert_help'] = 'Activar aviso de matriculación';
+$string['enrolmessage'] = 'Mensaje personalizado';
+$string['enrolmessage_help'] = 'Personalice el mensaje que le llegará a los usuarios al ser matriculados. Este campo acepta los siguientes marcadores que luego seran reemplazados dinámicamente por los valores correspondientes
+
+{COURSENAME} = Nombre completo del curso
+{USERNAME} = Nombre de usuario
+{FIRSTNAME} = Nombre
+{LASTNAME} = Apellido
+{URL} = Url del curso
+';
+$string['enrolmessagedefault'] = 'Ud ha sido matriculado en el curso {$a->fullname} ({$a->url})';
+
+// Aviso de desmatriculacion.
+$string['globalunenrolalert'] = 'Activar para todo el sitio';
+$string['globalunenrolalert_help'] = 'Activar la notificacion de desmatriculacion para todo el sitio';
+$string['unenrolalert'] = 'Activar aviso de desmatriculacion';
+$string['unenrolalert_help'] = 'Activar aviso de desmatriculacion';
+$string['unenrolmessage'] = 'Mensaje personalizado';
+$string['unenrolmessage_help'] = 'Personalice el mensaje que le llegará a los usuarios al ser desmatriculados. Este campo acepta los siguientes marcadores que luego seran reemplazados dinámicamente por los valores correspondientes
+
+{COURSENAME} = Nombre completo del curso
+{USERNAME} = Nombre de usuario
+{FIRSTNAME} = Nombre
+{LASTNAME} = Apellido
+{URL} = Url del curso
+';
+$string['unenrolmessagedefault'] = 'Ud ha sido desmatriculado del curso {$a->fullname} ({$a->url})';
+
+// Aviso de actualizacion de matriculacion.
+$string['globalenrolmentupdatealert'] = 'Activar para todo el sitio';
+$string['globalenrolmentupdatealert_help'] = 'Activar la notificacion de actualizacion de matriculacion para todo el sitio';
+$string['enrolmentupdatealert'] = 'Activar aviso de actualizacion de matriculacion';
+$string['enrolmentupdatealert_help'] = 'Activar aviso de actualizacion de matriculacion';
+$string['enrolmentupdatemessage'] = 'Mensaje personalizado';
+$string['enrolmentupdatemessage_help'] = 'Personalice el mensaje que le llegará a los usuarios al realizar alguna actualizacion en su matriculacion. Este campo acepta los siguientes marcadores que luego seran reemplazados dinámicamente por los valores correspondientes
+
+{COURSENAME} = Nombre completo del curso
+{USERNAME} = Nombre de usuario
+{FIRSTNAME} = Nombre
+{LASTNAME} = Apellido
+{URL} = Url del curso
+';
+$string['enrolmentupdatemessagedefault'] = 'Su matriculacion en el curso {$a->fullname} ha sido actualizada ({$a->url})';
diff --git a/lang/es/enrol_notificationeabc.php b/lang/es/enrol_notificationeabc.php
deleted file mode 100644
index a185d74..0000000
--- a/lang/es/enrol_notificationeabc.php
+++ /dev/null
@@ -1,87 +0,0 @@
-.
-
-/**
- * Notificationeabc enrolment plugin.
- *
- * This plugin notifies users when an event occurs on their enrolments (enrol, unenrol, update enrolment)
- *
- * @package enrol_notificationeabc
- * @copyright 2017 e-ABC Learning
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @author Osvaldo Arriola
- */
-
-$string['filelockedmail'] = 'Ud ha sido matriculado en el curso {$a->fullname} ({$a->url})';
-$string['location'] = 'Mensaje personalizado';
-$string['messageprovider:notificationeabc_enrolment'] = 'Enrol notification messages';
-$string['notificationeabc:manage'] = 'Gestionar notificaciones de matriculación';
-$string['pluginname'] = 'Notificación de Matriculación';
-$string['pluginname_desc'] = 'Notificación de matriculaciones a cursos via mail';
-$string['location_help'] = 'Personalice el mensaje que le llegará a los usuarios al ser matriculados. Este campo acepta los siguientes marcadores que luego seran reemplazados dinámicamente por los valores correspondientes
-
-{COURSENAME} = Nombre completo del curso
-{USERNAME} = Nombre de usuario
-{NOMBRE} = Nombre
-{APELLIDO} = Apellido
-{URL} = Url del curso
-';
-$string['fecha_help'] = 'Coloque el periodo por el cual desea que se realice la virificación inicial de usuarios matriculados';
-$string['fecha'] = 'Período para realizar la verificación de usuarios que se matricularon a cursos';
-$string['activar'] = 'Activar verificación inicial';
-$string['activar_help'] = 'Al activarse se verificará, mediante la ejecucion del cron inmediata posterior, los usuarios que fueron matriculados en el periodo establecido arriba';
-$string['activarglobal'] = 'Activar para todo el sitio';
-$string['activarglobal_help'] = 'Activa la notificacion de matriculacion para todo los cursos';
-$string['emailsender'] = 'Email del remitente ';
-$string['emailsender_help'] = 'Por defecto toma el email configurado como el usuario de soporte ';
-$string['namesender'] = 'Nombre del remitente ';
-$string['namesender_help'] = 'Por defecto toma el nombre configurado como el usuario de soporte ';
-$string['status'] = 'Activar notification de matriculación';
-$string['subject'] = 'Notificación de Matriculación';
-$string['activeenrolalert'] = 'Activar aviso de matriculación';
-$string['activeenrolalert_help'] = 'Activar aviso de matriculación';
-// Aviso de desmatriculacion.
-$string['activeunenrolalert'] = 'Activar aviso de desmatriculacion';
-$string['activeunenrolalert_help'] = 'Activar aviso de desmatriculacion';
-$string['activarglobalunenrolalert'] = 'Activar para todo el sitio';
-$string['activarglobalunenrolalert_help'] = 'Activar la notificacion de desmatriculacion para todo el sitio';
-$string['unenrolmessage'] = 'Mensaje personalizado';
-$string['unenrolmessage_help'] = 'Personalice el mensaje que le llegará a los usuarios al ser desmatriculados. Este campo acepta los siguientes marcadores que luego seran reemplazados dinámicamente por los valores correspondientes
-
-{COURSENAME} = Nombre completo del curso
-{USERNAME} = Nombre de usuario
-{NOMBRE} = Nombre
-{APELLIDO} = Apellido
-{URL} = Url del curso
-';
-$string['unenrolmessagedefault'] = 'Ud ha sido desmatriculado del curso {$a->fullname} ({$a->url})';
-// Aviso de actualizacion de matriculacion.
-$string['activeenrolupdatedalert'] = 'Activar aviso de actualizacion de matriculacion';
-$string['activeenrolupdatedalert_help'] = 'Activar aviso de actualizacion de matriculacion';
-$string['activarglobalenrolupdated'] = 'Activar para todo el sitio';
-$string['activarglobalenrolupdated_help'] = 'Activar la notificacion de actualizacion de matriculacion para todo el sitio';
-$string['updatedenrolmessage'] = 'Mensaje personalizado';
-$string['updatedenrolmessage_help'] = 'Personalice el mensaje que le llegará a los usuarios al realizar alguna actualizacion en su matriculacion. Este campo acepta los siguientes marcadores que luego seran reemplazados dinámicamente por los valores correspondientes
-
-{COURSENAME} = Nombre completo del curso
-{USERNAME} = Nombre de usuario
-{NOMBRE} = Nombre
-{APELLIDO} = Apellido
-{URL} = Url del curso
-';
-$string['updatedenrolmessagedefault'] = 'Su matriculacion en el curso {$a->fullname} ha sido actualizada ({$a->url})';
-$string['succefullsend'] = 'Se notifico al usuario {$a->username} sobre su matriculación en el curso {$a->coursename}'. "\n";
-$string['failsend'] = 'ATENCION: No se pudo notificar al usuario {$a->username} sobre su matriculación en el curso {$a->coursename}'."\n";
\ No newline at end of file
diff --git a/lang/it/enrol_notification.php b/lang/it/enrol_notification.php
new file mode 100644
index 0000000..5e92a5f
--- /dev/null
+++ b/lang/it/enrol_notification.php
@@ -0,0 +1,31 @@
+.
+
+/**
+ * Notification enrolment plugin.
+ *
+ * This plugin notifies users when an event occurs on their enrolments (enrol, unenrol, update enrolment)
+ *
+ * @package enrol_notification
+ * @copyright 2017 e-ABC Learning
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @author Osvaldo Arriola
+ */
+
+$string['subject'] = 'Notifica sullo stato di iscrizione';
+$string['enrolmessagedefault'] = 'Sei stato iscritto al corso "{COURSENAME}" all\'indirizzo: {URL}';
+$string['unenrolmessagedefault'] = 'Sei stato disiscritto dal corso "{COURSENAME}" all\'indirizzo: {URL}';
+$string['enrolmentupdatemessagedefault'] = 'La tua iscrizione al corso {COURSENAME} all\'indirizzo: {URL} è stata modificata';
diff --git a/lib.php b/lib.php
index 0e68872..9f33ab4 100644
--- a/lib.php
+++ b/lib.php
@@ -15,11 +15,11 @@
// along with Moodle. If not, see .
/**
- * 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
@@ -32,133 +32,88 @@
/**
* Lib class
*
- * @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
*/
-class enrol_notificationeabc_plugin extends enrol_plugin
-{
+class enrol_notification_plugin extends enrol_plugin {
/** @var log.*/
private $log = '';
// Funcion que envia las notificaciones a los usuarios.
/**
- * Send mail method
- * @param stdClass $user instancia usuario
- * @param stdClass $course instancia curso
- * @param int $type aviso matriculacion, actualizacion o desmatriculacion
+ * Send mail method
+ * @param stdClass $user user instance
+ * @param stdClass $course course instance
+ * @param int $type notice enrollment, update or unenrollment
* @return bool
*/
- public function enviarmail(stdClass $user, stdClass $course, $type) {
- global $CFG, $DB, $COURSE;
-
- $course->url = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
-
- $enrol = $DB->get_record('enrol', array('enrol' => 'notificationeabc', 'courseid' => $course->id, 'status' => 0));
- $activeglobalenrol = $this->get_config('activarglobal');
- $activarglobalunenrolalert = $this->get_config('activarglobalunenrolalert');
- $activarglobalenrolupdated = $this->get_config('activarglobalenrolupdated');
- $mensajeenrol = $this->get_config('location');
- $plainmensajeenrol = strip_tags($mensajeenrol);
- $mensajeunenrol = $this->get_config('unenrolmessage');
- $plainmensajeunenrol = strip_tags($mensajeunenrol);
- $mensajeupdateenrol = $this->get_config('updatedenrolmessage');
- $plainmensajeupdateenrol = strip_tags($mensajeupdateenrol);
-
- switch ((int)$type) {
- case 1:
- // Si no se configuro un mensaje personalizado se envia uno por defecto basico.
- if (!empty($enrol) && !empty($enrol->customtext1)) {
- $texto = strip_tags($enrol->customtext1);
- if (!empty($texto)) {
- $mensaje = $this->process_mensaje($enrol->customtext1, $user, $course);
- } else {
- $mensaje = get_string("filelockedmail", "enrol_notificationeabc", $course);
- }
-
- } else if (!empty($activeglobalenrol) && !empty($plainmensajeenrol)) {
- $mensaje = $this->process_mensaje($mensajeenrol, $user, $course);
- } else {
- $mensaje = get_string("filelockedmail", "enrol_notificationeabc", $course);
- }
- break;
- case 2:
-
- if (!empty($enrol) && !empty($enrol->customtext2)) {
- $texto = strip_tags($enrol->customtext2);
- if (!empty($texto)) {
- $mensaje = $this->process_mensaje($enrol->customtext2, $user, $course);
- } else {
- $mensaje = get_string("unenrolmessagedefault", "enrol_notificationeabc", $course);
- }
-
- } else if (!empty($activarglobalunenrolalert) && !empty($plainmensajeunenrol)) {
- $mensaje = $this->process_mensaje($mensajeunenrol, $user, $course);
- } else {
- $mensaje = get_string("unenrolmessagedefault", "enrol_notificationeabc", $course);
- }
- break;
- case 3:
-
- if (!empty($enrol) && !empty($enrol->customtext3)) {
- $texto = strip_tags($enrol->customtext3);
- if (!empty($texto)) {
- $mensaje = $this->process_mensaje($enrol->customtext3, $user, $course);
- } else {
- $mensaje = get_string("updatedenrolmessagedefault", "enrol_notificationeabc", $course);
- }
-
- } else if (!empty($activarglobalenrolupdated) && !empty($plainmensajeupdateenrol)) {
- $mensaje = $this->process_mensaje($mensajeupdateenrol, $user, $course);
- } else {
- $mensaje = get_string("updatedenrolmessagedefault", "enrol_notificationeabc", $course);
- }
- break;
+ public function send_email(stdClass $user, stdClass $course, $type) {
+ global $CFG, $DB;
- default:
- break;
- }
+ $enrol = $DB->get_record('enrol', array('enrol' => 'notification', 'courseid' => $course->id, 'status' => 0));
- $soporte = core_user::get_support_user();
+ $pluginconfig = get_config('enrol_notification');
- $sender = get_admin();
+ if ($type == 1) {
+ $enrolalert = $pluginconfig->enrolalert;
+ $globalenrolalert = $pluginconfig->globalenrolalert;
- if (!empty($enrol) && !empty($enrol->customchar1)) {
- $sender->email = $enrol->customchar1;
- } else {
- $sender->email = $soporte->email;
+ if (!$message = $enrol->customtext1) { // Course level.
+ if (!$message = $pluginconfig->enrolmessage) { // Plugin level.
+ $message = get_string('enrolmessagedefault', 'enrol_notification');
+ }
+ }
}
- if (!empty($enrol) && !empty($enrol->customchar2)) {
- $sender->firstname = $enrol->customchar2;
- } else {
- $sender->firstname = $soporte->firstname;
+ if ($type == 2) {
+ $unenrolalert = $pluginconfig->unenrolalert;
+ $globalunenrolalert = $pluginconfig->globalunenrolalert;
+
+ if (!$message = $enrol->customtext2) { // Course level.
+ if (!$message = $pluginconfig->unenrolmessage) { // Plugin level.
+ $message = get_string('unenrolmessagedefault', 'enrol_notification');
+ }
+ }
}
- $sender->lastname = $soporte->lastname;
+ if ($type == 3) {
+ $enrolmentupdatealert = $pluginconfig->enrolmentupdatealert;
+ $globalenrolmentupdatealert = $pluginconfig->globalenrolmentupdatealert;
+
+ if (!$message = $enrol->customtext3) { // Course level.
+ if (!$message = $pluginconfig->enrolmentupdatemessage) { // Plugin level.
+ $message = get_string('enrolmentupdatemessagedefault', 'enrol_notification');
+ }
+ }
+ }
+
+ $message = $this->get_message($message, $user, $course);
+
+ $supportuser = \core_user::get_support_user();
$eventdata = new \core\message\message();
$eventdata->courseid = $course->id;
$eventdata->modulename = 'moodle';
- $eventdata->component = 'enrol_notificationeabc';
- $eventdata->name = 'notificationeabc_enrolment';
- $eventdata->userfrom = $sender;
+ $eventdata->component = 'enrol_notification';
+ $eventdata->name = 'notification_enrolment';
+ $eventdata->userfrom = $supportuser;
$eventdata->userto = $user->id;
- $eventdata->subject = get_string('subject', 'enrol_notificationeabc');
+ $eventdata->subject = get_string('subject', 'enrol_notification');
$eventdata->fullmessage = '';
$eventdata->fullmessageformat = FORMAT_HTML;
- $eventdata->fullmessagehtml = $mensaje;
+ $eventdata->fullmessagehtml = $message;
$eventdata->smallmessage = '';
$strdata = new stdClass();
$strdata->username = $user->username;
$strdata->coursename = $course->fullname;
if (message_send($eventdata)) {
- $this->log .= get_string('succefullsend', 'enrol_notificationeabc', $strdata);
+ $this->log .= get_string('succefullsend', 'enrol_notification', $strdata);
return true;
} else {
- $this->log .= get_string('failsend', 'enrol_notificationeabc', $strdata);
+ $this->log .= get_string('failsend', 'enrol_notification', $strdata);
return false;
}
} // End of function.
@@ -166,24 +121,25 @@ public function enviarmail(stdClass $user, stdClass $course, $type) {
// Procesa el mensaje para aceptar marcadores.
/**
* Proccess message method
- * @param String $mensaje el mensaje en bruto
- * @param stdClass $user instancia usuario
- * @param stdClass $course instancia curso
- * @return String el mensaje procesado
+ * @param String $message the raw message
+ * @param stdClass $user user instance
+ * @param stdClass $course course instance
+ * @return String the processed message
*/
- public function process_mensaje($mensaje, stdClass $user, stdClass $course) {
+ public function get_message($message, stdClass $user, stdClass $course) {
global $CFG;
- $m = $mensaje;
+
+ $m = $message;
$url = new moodle_url($CFG->wwwroot . '/course/view.php', array('id' => $course->id));
$m = str_replace('{COURSENAME}', $course->fullname, $m);
$m = str_replace('{USERNAME}', $user->username, $m);
- $m = str_replace('{NOMBRE}', $user->firstname, $m);
- $m = str_replace('{APELLIDO}', $user->lastname, $m);
+ $m = str_replace('{FIRSTNAME}', $user->firstname, $m);
+ $m = str_replace('{LASTNAME}', $user->lastname, $m);
$m = str_replace('{URL}', $url, $m);
+
return $m;
}
-
/**
* Returns link to page which may be used to add new instance of enrolment plugin in course.
* @param int $courseid
@@ -191,13 +147,15 @@ public function process_mensaje($mensaje, stdClass $user, stdClass $course) {
*/
public function get_newinstance_link($courseid) {
global $DB;
- $numenrol = $DB->count_records('enrol', array('courseid' => $courseid, 'enrol' => 'notificationeabc'));
+
+ $numenrol = $DB->count_records('enrol', array('courseid' => $courseid, 'enrol' => 'notification'));
$context = context_course::instance($courseid, MUST_EXIST);
- if (!has_capability('enrol/notificationeabc:manage', $context) or $numenrol >= 1) {
+ if (!has_capability('enrol/notification:manage', $context) or $numenrol >= 1) {
return null;
}
- return new moodle_url('/enrol/notificationeabc/edit.php', array('courseid' => $courseid));
+
+ return new moodle_url('/enrol/notification/edit.php', array('courseid' => $courseid));
}
@@ -206,19 +164,26 @@ public function get_newinstance_link($courseid) {
* @return array
*/
public function get_instance_defaults() {
-
$fields = array();
- $fields['customtext1'] = $this->get_config('location');
- $fields['customtext2'] = $this->get_config('unenrolmessage');
- $fields['customtext3'] = $this->get_config('updatedenrolmessage');
+
+ $pluginconfig = get_config('enrol_notification');
+
$fields['status'] = 1;
- $fields['customint1'] = 0;
- $fields['customint2'] = 0;
- $fields['customint3'] = $this->get_config('activeenrolalert');
- $fields['customint4'] = $this->get_config('activeunenrolalert');
- $fields['customint5'] = $this->get_config('activeenrolupdatedalert');
- $fields['customchar1'] = $this->get_config('emailsender');
- $fields['customchar2'] = $this->get_config('namesender');
+ $fields['customint1'] = $this->get_config('enrolalert');
+ $fields['customint2'] = $this->get_config('unenrolalert');
+ $fields['customint3'] = $this->get_config('enrolmentupdatealert');
+
+ $fields['customtext1'] = array();
+ $fields['customtext1']['text'] = $pluginconfig->enrolmessage;
+ $fields['customtext1']['format'] = '1';
+
+ $fields['customtext2'] = array();
+ $fields['customtext2']['text'] = $pluginconfig->unenrolmessage;
+ $fields['customtext2']['format'] = '1';
+
+ $fields['customtext3'] = array();
+ $fields['customtext3']['text'] = $pluginconfig->enrolmentupdatemessage;
+ $fields['customtext3']['format'] = '1';
return $fields;
}
@@ -232,32 +197,49 @@ public function get_instance_defaults() {
public function get_action_icons(stdClass $instance) {
global $OUTPUT;
- if ($instance->enrol !== 'notificationeabc') {
- throw new coding_exception('invalid enrol instance!');
- }
$context = context_course::instance($instance->courseid);
$icons = array();
- if (has_capability('enrol/notificationeabc:manage', $context)) {
+ if (has_capability('enrol/notification:manage', $context)) {
$editlink = new moodle_url(
- "/enrol/notificationeabc/edit.php",
- array('courseid' => $instance->courseid, 'id' => $instance->id)
+ '/enrol/editinstance.php',
+ array('courseid' => $instance->courseid, 'id' => $instance->id, 'type' => 'notification')
);
$icons[] = $OUTPUT->action_icon(
$editlink,
- new pix_icon(
- 'i/edit',
- get_string('edit'),
- 'core',
- array('class' => 'icon')
- )
+ new pix_icon( 't/edit', get_string('edit'), 'core', array('class' => 'icon iconsmall'))
);
}
return $icons;
}
+ /**
+ * Is it possible to delete enrol instance via standard UI?
+ *
+ * @param object $instance
+ * @return bool
+ */
+ public function can_delete_instance($instance) {
+ $context = context_course::instance($instance->courseid);
+ if (!has_capability('enrol/notification:manage', $context)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Is it possible to hide/show enrol instance via standard UI?
+ *
+ * @param stdClass $instance
+ * @return bool
+ */
+ public function can_hide_show_instance($instance) {
+ $context = context_course::instance($instance->courseid);
+ return has_capability('enrol/notification:config', $context);
+ }
/**
* get info icons method
@@ -266,9 +248,193 @@ public function get_action_icons(stdClass $instance) {
*/
public function get_info_icons(array $instances) {
$icons = array();
- $icons[] = new pix_icon('email', get_string('pluginname', 'enrol_notificationeabc'), 'enrol_notificationeabc');
+ $icons[] = new pix_icon('email', get_string('pluginname', 'enrol_notification'), 'enrol_notification');
return $icons;
}
+ /**
+ * We are a good plugin and don't invent our own UI/validation code path.
+ *
+ * @return boolean
+ */
+ public function use_standard_editing_ui() {
+ return true;
+ }
+
+ /**
+ * Return an array of valid options for the status.
+ *
+ * @return array
+ */
+ protected function get_status_options() {
+ $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
+ ENROL_INSTANCE_DISABLED => get_string('no'));
+ return $options;
+ }
+
+ /**
+ * Add elements to the edit instance form.
+ *
+ * @param stdClass $instance
+ * @param MoodleQuickForm $mform
+ * @param context $context
+ * @return bool
+ */
+ public function edit_instance_form($instance, MoodleQuickForm $mform, $context) {
+
+ // Bloody hack!
+ if (!is_array($instance->customtext1)) {
+ $temp = $instance->customtext1;
+ $instance->customtext1 = array();
+ $instance->customtext1['text'] = $temp;
+ $instance->customtext1['format'] = '1';
+
+ $temp = $instance->customtext2;
+ $instance->customtext2 = array();
+ $instance->customtext2['text'] = $temp;
+ $instance->customtext2['format'] = '1';
+
+ $temp = $instance->customtext3;
+ $instance->customtext3 = array();
+ $instance->customtext3['text'] = $temp;
+ $instance->customtext3['format'] = '1';
+ }
+ // End of bloody hack!
+
+ $textareaparams = array('rows' => 8, 'cols' => 60);
+
+ $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
+ $mform->setType('name', PARAM_RAW);
+ $mform->setDefault('name', get_string('pluginname', 'enrol_notification'));
+
+ $options = $this->get_status_options();
+ $mform->addElement('select', 'status', get_string('status', 'enrol_notification'), $options);
+ $mform->setDefault('status', $this->get_config('status'));
+
+ // Enrol notifications -> 'enrolalert'.
+ $mform->addElement('advcheckbox', 'customint1', get_string('enrolalert', 'enrol_notification'));
+ $mform->addHelpButton('customint1', 'enrolalert', 'enrol_notification');
+ $mform->setDefault('customint1', $this->get_config('enrolalert'));
+
+ // Enrol notifications -> 'enrolmessage'
+ $mform->addElement('editor', 'customtext1', get_string('enrolmessage', 'enrol_notification'), $textareaparams);
+ $mform->addHelpButton('customtext1', 'enrolmessage', 'enrol_notification');
+ $mform->setType('customtext1', PARAM_RAW);
+ $mform->setDefault('customtext1', $this->get_config('enrolmessage'));
+
+ // Unenrol notifications -> 'unenrolalert'.
+ $mform->addElement('advcheckbox', 'customint2', get_string('unenrolalert', 'enrol_notification'));
+ $mform->addHelpButton('customint2', 'unenrolalert', 'enrol_notification');
+ $mform->setDefault('customint2', $this->get_config('unenrolalert'));
+
+ // Unenrol notifications -> 'unenrolmessage'.
+ $mform->addElement('editor', 'customtext2', get_string('unenrolmessage', 'enrol_notification'), $textareaparams);
+ $mform->addHelpButton('customtext2', 'unenrolmessage', 'enrol_notification');
+ $mform->setType('customtext2', PARAM_RAW);
+ $mform->setDefault('customtext2', $this->get_config('unenrolmessage'));
+
+ // Update enrolment notifications -> 'enrolmentupdatealert'.
+ $mform->addElement('advcheckbox', 'customint3', get_string('enrolmentupdatealert', 'enrol_notification'));
+ $mform->addHelpButton('customint3', 'enrolmentupdatealert', 'enrol_notification');
+ $mform->setDefault('customint3', $this->get_config('enrolmentupdatealert'));
+
+ // Update enrolment notifications -> 'enrolmentupdatemessage'.
+ $mform->addElement('editor', 'customtext3', get_string('enrolmentupdatemessage', 'enrol_notification'), $textareaparams);
+ $mform->addHelpButton('customtext3', 'enrolmentupdatemessage', 'enrol_notification');
+ $mform->setType('customtext3', PARAM_RAW);
+ $mform->setDefault('customtext3', $this->get_config('enrolmentupdatemessage'));
+
+ if (enrol_accessing_via_instance($instance)) {
+ $warntext = get_string('instanceeditselfwarningtext', 'core_enrol');
+ $mform->addElement('static', 'selfwarn', get_string('instanceeditselfwarning', 'core_enrol'), $warntext);
+ }
+ }
+
+ public function add_instance($course, array $fields = NULL) {
+ global $DB;
+
+ if ($course->id == SITEID) {
+ throw new coding_exception('Invalid request to add enrol instance to frontpage.');
+ }
+
+ $instance = new stdClass();
+ $instance->enrol = $this->get_name();
+ $instance->status = ENROL_INSTANCE_ENABLED;
+ $instance->courseid = $course->id;
+ $instance->enrolstartdate = 0;
+ $instance->enrolenddate = 0;
+ $instance->timemodified = time();
+ $instance->timecreated = $instance->timemodified;
+ $instance->sortorder = $DB->get_field('enrol', 'COALESCE(MAX(sortorder), -1) + 1', array('courseid'=>$course->id));
+
+ $fields = (array)$fields;
+ unset($fields['enrol']);
+ unset($fields['courseid']);
+ unset($fields['sortorder']);
+ foreach($fields as $field=>$value) {
+ $instance->$field = $value;
+ }
+
+ $instance->customtext1 = $fields['customtext1']['text'];
+ $instance->customtext2 = $fields['customtext2']['text'];
+ $instance->customtext3 = $fields['customtext3']['text'];
+
+ $instance->id = $DB->insert_record('enrol', $instance);
+
+ \core\event\enrol_instance_created::create_from_record($instance)->trigger();
+
+ return $instance->id;
+ }
+
+ public function update_instance($instance, $data) {
+ global $DB;
+
+ $properties = array('status', 'name', 'password', 'customint1', 'customint2', 'customint3',
+ 'customint4', 'customint5', 'customint6', 'customint7', 'customint8',
+ 'customchar1', 'customchar2', 'customchar3', 'customdec1', 'customdec2',
+ 'customtext4', 'roleid',
+ 'enrolperiod', 'expirynotify', 'notifyall', 'expirythreshold',
+ 'enrolstartdate', 'enrolenddate', 'cost', 'currency');
+
+ foreach ($properties as $key) {
+ if (isset($data->$key)) {
+ $instance->$key = $data->$key;
+ }
+ }
+ $instance->timemodified = time();
+
+ $instance->customtext1 = $data->customtext1['text'];
+ $instance->customtext2 = $data->customtext2['text'];
+ $instance->customtext3 = $data->customtext3['text'];
+
+ $update = $DB->update_record('enrol', $instance);
+ if ($update) {
+ \core\event\enrol_instance_updated::create_from_record($instance)->trigger();
+ }
+
+ return $update;
+ }
+
+ /**
+ * Perform custom validation of the data used to edit the instance.
+ *
+ * @param array $data array of ("fieldname"=>value) of submitted data
+ * @param array $files array of uploaded files "element_name"=>tmp_file_path
+ * @param object $instance The instance loaded from the DB
+ * @param context $context The context of the instance we are editing
+ * @return array of "element_name"=>"error_description" if there are errors,
+ * or an empty array if everything is OK.
+ * @return void
+ */
+ public function edit_instance_validation($data, $files, $instance, $context) {
+ $errors = array();
+ $validstatus = array_keys($this->get_status_options());
+ $tovalidate = array('status' => $validstatus);
+
+ $typeerrors = $this->validate_param_types($data, $tovalidate);
+ $errors = array_merge($errors, $typeerrors);
+
+ return $errors;
+ }
} // End of class.
diff --git a/readme.md b/readme.md
index 5379f66..fc4bd62 100644
--- a/readme.md
+++ b/readme.md
@@ -1,4 +1,4 @@
-# Notificationeabc plugin
+# Notification plugin
Send notifications to users when any enrolment event is executed
diff --git a/settings.php b/settings.php
index 4d2c738..4fe4dff 100644
--- a/settings.php
+++ b/settings.php
@@ -16,11 +16,11 @@
/**
- * 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
@@ -34,82 +34,43 @@
// Enrol notification.
$settings->add(new admin_setting_configcheckbox(
- 'enrol_notificationeabc/activeenrolalert',
- get_string('activeenrolalert', 'enrol_notificationeabc'),
- get_string('activeenrolalert_help', 'enrol_notificationeabc'),
- '',
- '1')
- );
- $settings->add(new admin_setting_configcheckbox(
- 'enrol_notificationeabc/activarglobal',
- get_string('activarglobal', 'enrol_notificationeabc'),
- get_string('activarglobal_help', 'enrol_notificationeabc'),
- '')
- );
- $settings->add(new admin_setting_heading(
- 'enrol_notificationeabc_settings',
- '',
- get_string('pluginname_desc', 'enrol_notificationeabc'),
+ 'enrol_notification/globalenrolalert',
+ get_string('globalenrolalert', 'enrol_notification'),
+ get_string('globalenrolalert_help', 'enrol_notification'),
'')
);
$settings->add(new admin_setting_confightmleditor(
- 'enrol_notificationeabc/location',
- get_string('location', 'enrol_notificationeabc'),
- get_string('location_help', 'enrol_notificationeabc'),
- '')
+ 'enrol_notification/enrolmessage',
+ get_string('enrolmessage', 'enrol_notification'),
+ get_string('enrolmessage_help', 'enrol_notification'),
+ new lang_string('enrolmessagedefault', 'enrol_notification'))
);
// Unenrol notification.
$settings->add(new admin_setting_configcheckbox(
- 'enrol_notificationeabc/activeunenrolalert',
- get_string('activeunenrolalert', 'enrol_notificationeabc'),
- get_string('activeunenrolalert_help', 'enrol_notificationeabc'),
- '',
- '1')
- );
- $settings->add(new admin_setting_configcheckbox(
- 'enrol_notificationeabc/activarglobalunenrolalert',
- get_string('activarglobalunenrolalert', 'enrol_notificationeabc'),
- get_string('activarglobalunenrolalert_help', 'enrol_notificationeabc'),
+ 'enrol_notification/globalunenrolalert',
+ get_string('globalunenrolalert', 'enrol_notification'),
+ get_string('globalunenrolalert_help', 'enrol_notification'),
'')
);
$settings->add(new admin_setting_confightmleditor(
- 'enrol_notificationeabc/unenrolmessage',
- get_string('unenrolmessage', 'enrol_notificationeabc'),
- get_string('unenrolmessage_help', 'enrol_notificationeabc'),
- '')
+ 'enrol_notification/unenrolmessage',
+ get_string('unenrolmessage', 'enrol_notification'),
+ get_string('unenrolmessage_help', 'enrol_notification'),
+ new lang_string('unenrolmessagedefault', 'enrol_notification'))
);
// Update enrol notification.
$settings->add(new admin_setting_configcheckbox(
- 'enrol_notificationeabc/activeenrolupdatedalert',
- get_string('activeenrolupdatedalert', 'enrol_notificationeabc'),
- get_string('activeenrolupdatedalert_help', 'enrol_notificationeabc'),
- '',
- '1')
- );
- $settings->add(new admin_setting_configcheckbox(
- 'enrol_notificationeabc/activarglobalenrolupdated',
- get_string('activarglobalenrolupdated', 'enrol_notificationeabc'),
- get_string('activarglobalenrolupdated_help', 'enrol_notificationeabc'),
+ 'enrol_notification/globalenrolmentupdatealert',
+ get_string('globalenrolmentupdatealert', 'enrol_notification'),
+ get_string('globalenrolmentupdatealert_help', 'enrol_notification'),
'')
);
$settings->add(new admin_setting_confightmleditor(
- 'enrol_notificationeabc/updatedenrolmessage',
- get_string('updatedenrolmessage', 'enrol_notificationeabc'),
- get_string('updatedenrolmessage_help', 'enrol_notificationeabc'),
- '')
- );
- $settings->add(new admin_setting_configtext(
- 'enrol_notificationeabc/emailsender',
- get_string('emailsender', 'enrol_notificationeabc'),
- get_string('emailsender_help', 'enrol_notificationeabc'),
- '')
- );
- $settings->add(new admin_setting_configtext(
- 'enrol_notificationeabc/namesender',
- get_string('namesender', 'enrol_notificationeabc'),
- get_string('namesender_help', 'enrol_notificationeabc'),
- '')
+ 'enrol_notification/enrolmentupdatemessage',
+ get_string('enrolmentupdatemessage', 'enrol_notification'),
+ get_string('enrolmentupdatemessage_help', 'enrol_notification'),
+ new lang_string('enrolmentupdatemessagedefault', 'enrol_notification'))
);
}
diff --git a/version.php b/version.php
index c67dd02..79e1b6d 100644
--- a/version.php
+++ b/version.php
@@ -15,20 +15,20 @@
// along with Moodle. If not, see .
/**
- * 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
*/
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2017111700;
+$plugin->version = 2018022200;
$plugin->requires = 2016120503;
-$plugin->component = 'enrol_notificationeabc';
+$plugin->component = 'enrol_notification';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '3.2.0.1';
$plugin->cron = 30;