From 1262e1b56417a2658e3209020779cc821bfbd887 Mon Sep 17 00:00:00 2001 From: Daniel Neis Araujo Date: Wed, 29 Sep 2021 17:38:47 -0300 Subject: [PATCH 01/10] create/edit audience filters for notifications --- classes/notifications_table.php | 5 +- classes/output/form/audience.php | 150 +++++++++++++++++++++++++++++ db/install.xml | 44 ++++++++- db/upgrade.php | 63 +++++++++++- lang/en/block_advnotifications.php | 7 ++ pages/audience.php | 108 +++++++++++++++++++++ version.php | 2 +- 7 files changed, 373 insertions(+), 6 deletions(-) create mode 100644 classes/output/form/audience.php mode change 100644 => 100755 db/install.xml create mode 100644 pages/audience.php diff --git a/classes/notifications_table.php b/classes/notifications_table.php index 086a1ed..4f7929b 100644 --- a/classes/notifications_table.php +++ b/classes/notifications_table.php @@ -70,7 +70,8 @@ public function col_actions($values) { - '; + + '; } } -} \ No newline at end of file +} diff --git a/classes/output/form/audience.php b/classes/output/form/audience.php new file mode 100644 index 0000000..4d6b20d --- /dev/null +++ b/classes/output/form/audience.php @@ -0,0 +1,150 @@ +. + +/** + * Reports form. + * + * @package block_advnotifications + * @copyright 2020 Daniel Neis Araujo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_advnotifications\output\form; +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->libdir . '/formslib.php'); + +use moodleform; + +/** + * Audience form class. + * + * @package block_advnotifications + * @copyright 2020 Daniel Neis Araujo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class audience extends moodleform { + + public function definition() { + global $DB; + + $mform = $this->_form; + + // $mform->addElement('hidden', 'id'); + // $mform->setType('id', PARAM_INT); + + $options = []; + $values = []; + + $notificationid = $this->_customdata['notificationid']; + + $cohortssql = + 'SELECT c.id, c.name, nc.id as inuse + FROM {cohort} c + LEFT JOIN {block_advnotifications_coh} nc + ON c.id = nc.cohortid AND nc.notificationid = ?'; + $cohorts = $DB->get_records_sql($cohortssql, [$notificationid]); + foreach ($cohorts as $c) { + $options[$c->id] = $c->name; + if (!is_null($c->inuse)) { + $values[] = $c->id; + } + } + + $autocomplete = $mform->addElement( + 'autocomplete', + 'cohorts', + get_string('cohorts', 'cohort' ), + $options, + ['multiple' => true] + ); + $autocomplete->setSelected($values); + + $roles = role_get_names(); + $selectedroles = $DB->get_fieldset_select('block_advnotifications_roles', 'roleid', 'notificationid = ?', [$notificationid]); + $options = []; + $values = []; + foreach ($roles as $r) { + $options[$r->id] = $r->localname; + if (in_array($r->id, $selectedroles)) { + $values[] = $r->id; + } + } + $autocomplete = $mform->addElement( + 'autocomplete', + 'roles', + get_string('roles'), + $options, + ['multiple' => true] + ); + $autocomplete->setSelected($values); + + $elements = [ + $mform->createElement('select', 'userfield', '', $this->filter_options()), + $mform->createElement('select', 'operator', '', $this->operator_options()), + $mform->createElement('text', 'fieldvalue', '', ['size' => 12]), + ]; + $filters = $mform->createElement('group', 'userfieldfilters', get_string('filter_userfield', 'block_advnotifications'), $elements); + + $rules = [ + 'userfieldfilters[userfield]' => ['type' => PARAM_TEXT], + 'userfieldfilters[operator]' => ['type' => PARAM_TEXT], + 'userfieldfilters[fieldvalue]' => ['type' => PARAM_TEXT] + ]; + $this->repeat_elements([$filters], $this->_customdata['filterscount'], $rules, + 'filterscount', 'adduserfieldfilter', 1, get_string('adduserfieldfilter', 'block_advnotifications')); + + $this->add_action_buttons(); + } + + protected function filter_options() { + global $DB; + + $filters = [ + 'id' => 'id', + 'username' => get_string('username'), + 'idnumber' => get_string('idnumber'), + 'firstname' => get_string('firstname'), + 'lastname' => get_string('lastname'), + 'fullname' => get_string('fullnameuser'), + 'email' => get_string('email'), + 'phone1' => get_string('phone1'), + 'phone2' => get_string('phone2'), + 'institution' => get_string('institution'), + 'department' => get_string('department'), + 'address' => get_string('address'), + 'city' => get_string('city'), + 'timezone' => get_string('timezone'), + 'url' => get_string('webpage'), + ]; + + if ($profilefields = $DB->get_records('user_info_field', [], 'sortorder ASC')) { + foreach ($profilefields as $f) { + $filters['profile_field_' . $f->shortname] = format_string($f->name); + } + } + + return $filters; + } + + protected function operator_options() { + return [ + 'beginwith' => get_string('operator_beginwith', 'block_advnotifications'), + 'contains' => get_string('operator_contains', 'block_advnotifications'), + 'equals' => get_string('operator_equals', 'block_advnotifications') + ]; + } +} diff --git a/db/install.xml b/db/install.xml old mode 100644 new mode 100755 index 9637414..46987a1 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,8 @@ - + @@ -36,5 +39,42 @@
+ + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + +
-
\ No newline at end of file +
diff --git a/db/upgrade.php b/db/upgrade.php index 171043f..8d17ef6 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -102,7 +102,68 @@ function xmldb_block_advnotifications_upgrade($oldversion) { upgrade_block_savepoint(true, 2021010616, 'advnotifications'); } + if ($oldversion < 2021101400) { + + // Define table block_advnotifications_coh to be created. + $table = new xmldb_table('block_advnotifications_coh'); + + // Adding fields to table block_advnotifications_coh. + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('notificationid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('cohortid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + + // Adding keys to table block_advnotifications_coh. + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_key('notificationid', XMLDB_KEY_FOREIGN, ['notificationid'], 'block_advnotifications', ['id']); + $table->add_key('cohortid', XMLDB_KEY_FOREIGN, ['cohortid'], 'cohort', ['id']); + + // Conditionally launch create table for block_advnotifications_coh. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + // Define table block_advnotifications_field to be created. + $table = new xmldb_table('block_advnotifications_field'); + + // Adding fields to table block_advnotifications_field. + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('notificationid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('userfield', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); + $table->add_field('operator', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); + $table->add_field('fieldvalue', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); + + // Adding keys to table block_advnotifications_field. + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_key('notificationid', XMLDB_KEY_FOREIGN, ['notificationid'], 'block_advnotifications', ['id']); + + // Conditionally launch create table for block_advnotifications_field. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + // Define table block_advnotifications_roles to be created. + $table = new xmldb_table('block_advnotifications_roles'); + + // Adding fields to table block_advnotifications_roles. + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('notificationid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + + // Adding keys to table block_advnotifications_roles. + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_key('notificationid', XMLDB_KEY_FOREIGN, ['notificationid'], 'block_advnotifications', ['id']); + $table->add_key('roleid', XMLDB_KEY_FOREIGN, ['roleid'], 'role', ['id']); + + // Conditionally launch create table for block_advnotifications_roles. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + // Advnotifications savepoint reached. + upgrade_block_savepoint(true, 2021101400, 'advnotifications'); + } + // Add future upgrade points here. return true; -} \ No newline at end of file +} diff --git a/lang/en/block_advnotifications.php b/lang/en/block_advnotifications.php index 46957e5..bb4e71b 100644 --- a/lang/en/block_advnotifications.php +++ b/lang/en/block_advnotifications.php @@ -150,9 +150,16 @@ // Misc. $string['advnotifications_join'] = ' & '; +$string['adduserfieldfilter'] = 'Add another user field filter'; +$string['audiencesaved'] = 'Audience save successfully.'; +$string['editing_audiences'] = 'Editing audiences'; $string['event_notification_created'] = 'Advanced notification created'; $string['event_notification_deleted'] = 'Advanced notification deleted'; $string['event_notification_updated'] = 'Advanced notification updated'; +$string['filter_userfield'] = 'User field'; +$string['operator_beginwith'] = 'Begin with'; +$string['operator_contains'] = 'Contains'; +$string['operator_equals'] = 'Equals'; // Privacy API. $string['privacy:metadata:block_advnotifications'] = 'Information about notifications the user has been exposed to and recorded interactions.'; diff --git a/pages/audience.php b/pages/audience.php new file mode 100644 index 0000000..c067993 --- /dev/null +++ b/pages/audience.php @@ -0,0 +1,108 @@ +. + +/** + * Manage notifications audiences. + * + * @package block_advnotifications + * @copyright 2021 Daniel Neis Araujo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('../../../config.php'); + +$id = required_param('id', PARAM_INT); + +$notification = $DB->get_record('block_advnotifications', ['id' => $id]); + +if ($notification->blockid) { + $bcontext = context_block::instance($notification->blockid); + $ctx = $bcontext->get_course_context(false); +} +if (empty($ctx)) { + $ctx = context_system::instance(); +} + +require_login(); + +$url = new moodle_url('/blocks/advnotifications/pages/audience.php', ['id' => $id]); + +$str = get_string('editing_audiences', 'block_advnotifications'); + +$manageurl = new moodle_url('/blocks/advnotifications/pages/notifications.php'); + +$PAGE->set_context($ctx); +$PAGE->set_pagelayout('standard'); +$PAGE->set_url($url); +$PAGE->set_title($str); +$PAGE->set_heading($str); + +$PAGE->navbar->add(get_string('blocks')); +$PAGE->navbar->add(get_string('pluginname', 'block_advnotifications')); +$PAGE->navbar->add(get_string('advnotifications_table_title_short', 'block_advnotifications'), $manageurl); +$PAGE->navbar->add($str); + +$output = $PAGE->get_renderer('block_advnotifications'); + +// TODO! +$userfieldfilters = $DB->get_records('block_advnotifications_field', ['notificationid' => $id]); +$notification->userfieldfilters = []; +foreach ($userfieldfilters as $f) { + $notification->userfieldfilters[] = [ + 'userfield' => $f->userfield, + 'operator' => $f->operator, + 'fieldvalue' => $f->fieldvalue, + ]; +} +if ($userfieldfilters) { + $filterscount = count($userfieldfilters); +} else { + $filterscount = 1; +} +$form = new \block_advnotifications\output\form\audience($url->out(false), + ['notificationid' => $id, 'filterscount' => $filterscount]); + +if ($form->is_cancelled()) { + redirect($manageurl); +} else if ($data = $form->get_data()) { + $DB->delete_records('block_advnotifications_coh', ['notificationid' => $id]); + $DB->delete_records('block_advnotifications_field', ['notificationid' => $id]); + $DB->delete_records('block_advnotifications_roles', ['notificationid' => $id]); + $coh = (object)['notificationid' => $id]; + foreach ($data->cohorts as $c) { + $coh->cohortid = $c; + $DB->insert_record_raw('block_advnotifications_coh', $coh); + } + $field = (object)['notificationid' => $id]; + foreach ($data->userfieldfilters as $f) { + $field->userfield = $f['userfield']; + $field->operator = $f['operator']; + $field->fieldvalue = $f['fieldvalue']; + $DB->insert_record_raw('block_advnotifications_field', $field); + } + $role = (object)['notificationid' => $id]; + foreach ($data->roles as $r) { + $role->roleid = $r; + $DB->insert_record_raw('block_advnotifications_roles', $role); + } + redirect($url, get_string('audiencesaved', 'block_advnotifications')); +} +$form->set_data($notification); + +echo $output->header(), + $output->heading($notification->title), + $form->render(), + $output->footer(); diff --git a/version.php b/version.php index 716f2f7..601a1ee 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die; $plugin->component = 'block_advnotifications'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494). -$plugin->version = 2021092301; // YYYYMMDDHH (year, month, day, 24-hr format hour). +$plugin->version = 2021101400; // YYYYMMDDHH (year, month, day, 24-hr format hour). $plugin->requires = 2018051703; // YYYYMMDDHH (Version number for Moodle v3.5.3 as at 21/01/2019). $plugin->maturity = MATURITY_STABLE; // Code maturity/stability. $plugin->release = 'v1.4.2'; // Human-readable release version. From e7d165ce737e136e4dc369ba35e96604b29e39db Mon Sep 17 00:00:00 2001 From: Daniel Neis Araujo Date: Tue, 5 Oct 2021 17:33:09 -0300 Subject: [PATCH 02/10] filter display by audience - cohorts, roles and profile fields --- classes/audience.php | 141 +++++++++++++++++++++++++++++++ classes/output/form/audience.php | 46 +++------- locallib.php | 12 ++- pages/audience.php | 15 ++-- 4 files changed, 173 insertions(+), 41 deletions(-) create mode 100644 classes/audience.php diff --git a/classes/audience.php b/classes/audience.php new file mode 100644 index 0000000..c24bb1c --- /dev/null +++ b/classes/audience.php @@ -0,0 +1,141 @@ +. + +/** + * Class for audience rules. + * + * @package block_advnotifications + * @copyright 2016 onwards LearningWorks Ltd {@link https://learningworks.co.nz/} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Zander Potgieter + */ + +namespace block_advnotifications; + +defined('MOODLE_INTERNAL') || die; + +class audience { + + public static function get_cohorts_for_autocomplete($notificationid) { + global $DB; + + $cohortssql = + 'SELECT c.id, c.name, nc.id as inuse + FROM {cohort} c + LEFT JOIN {block_advnotifications_coh} nc + ON c.id = nc.cohortid AND nc.notificationid = ?'; + + $cohorts = $DB->get_records_sql($cohortssql, [$notificationid]); + + $options = []; + $values = []; + + foreach ($cohorts as $c) { + $options[$c->id] = $c->name; + if (!is_null($c->inuse)) { + $values[] = $c->id; + } + } + return [$options, $values]; + } + + public static function get_roles_for_autocomplete($notificationid) { + global $DB; + + $roles = role_get_names(); + $selectedroles = $DB->get_fieldset_select( + 'block_advnotifications_roles', + 'roleid', + 'notificationid = ?', + [$notificationid] + ); + $options = []; + $values = []; + foreach ($roles as $r) { + $options[$r->id] = $r->localname; + if (in_array($r->id, $selectedroles)) { + $values[] = $r->id; + } + } + return [$options, $values]; + } + + public static function meets_profile_requirements($notificationid, $userid) { + global $DB, $USER; + if (!$rules = $DB->get_records('block_advnotifications_field', ['notificationid' => $notificationid])) { + return true; // There is no field restriction. + } + foreach ($rules as $r) { + if (strpos($r->userfield, 'profile_field_') === false) { + $currentvalue = $USER->{$r->userfield}; + } else { + $field = substr($r->userfield, 14); + $currentvalue = $USER->profile[$field]; + } + switch ($r->operator) { + case 'equals': + if ($currentvalue !== $r->fieldvalue) { + return false; + } + break; + case 'contains': + if (strpos($currentvalue, $r->fieldvalue) === false) { + return false; + } + break; + case 'beginwith': + if (strpos($currentvalue, $r->fieldvalue) !== 0) { + return false; + } + break; + } + } + return true; + } + + public static function meets_cohorts_requirements($notificationid, $userid) { + global $DB; + if (!$DB->record_exists('block_advnotifications_coh', ['notificationid' => $notificationid])) { + return true; // There is no cohort restriction. + } + $sql = + 'SELECT 1 + FROM {block_advnotifications_coh} anc + JOIN {cohort_members} cm + ON cm.cohortid = anc.cohortid AND + anc.notificationid = ? AND + cm.userid = ?'; + return $DB->record_exists_sql($sql, [$notificationid, $userid]); + } + + public static function meets_roles_requirements($notificationid, $userid, $blockid) { + global $DB; + if (!$roles = $DB->get_records('block_advnotifications_roles', ['notificationid' => $notificationid])) { + return true; // There is no role restriction. + } + if ($blockid) { + $context = \context_block::instance($blockid); + } else { + $context = \context_system::instance(); + } + foreach ($roles as $r) { + if (!user_has_role_assignment($userid, $r->roleid, $context->id)) { + return false; + } + } + return true; + } +} diff --git a/classes/output/form/audience.php b/classes/output/form/audience.php index 4d6b20d..264ded7 100644 --- a/classes/output/form/audience.php +++ b/classes/output/form/audience.php @@ -39,30 +39,12 @@ class audience extends moodleform { public function definition() { - global $DB; $mform = $this->_form; - // $mform->addElement('hidden', 'id'); - // $mform->setType('id', PARAM_INT); - - $options = []; - $values = []; - $notificationid = $this->_customdata['notificationid']; - $cohortssql = - 'SELECT c.id, c.name, nc.id as inuse - FROM {cohort} c - LEFT JOIN {block_advnotifications_coh} nc - ON c.id = nc.cohortid AND nc.notificationid = ?'; - $cohorts = $DB->get_records_sql($cohortssql, [$notificationid]); - foreach ($cohorts as $c) { - $options[$c->id] = $c->name; - if (!is_null($c->inuse)) { - $values[] = $c->id; - } - } + list($options, $values) = \block_advnotifications\audience::get_cohorts_for_autocomplete($notificationid); $autocomplete = $mform->addElement( 'autocomplete', @@ -73,16 +55,7 @@ public function definition() { ); $autocomplete->setSelected($values); - $roles = role_get_names(); - $selectedroles = $DB->get_fieldset_select('block_advnotifications_roles', 'roleid', 'notificationid = ?', [$notificationid]); - $options = []; - $values = []; - foreach ($roles as $r) { - $options[$r->id] = $r->localname; - if (in_array($r->id, $selectedroles)) { - $values[] = $r->id; - } - } + list($options, $values) = \block_advnotifications\audience::get_roles_for_autocomplete($notificationid); $autocomplete = $mform->addElement( 'autocomplete', 'roles', @@ -98,14 +71,17 @@ public function definition() { $mform->createElement('text', 'fieldvalue', '', ['size' => 12]), ]; $filters = $mform->createElement('group', 'userfieldfilters', get_string('filter_userfield', 'block_advnotifications'), $elements); + $deletebutton = $mform->createElement('submit', 'deletefieldrule', 'X', [], false); $rules = [ 'userfieldfilters[userfield]' => ['type' => PARAM_TEXT], 'userfieldfilters[operator]' => ['type' => PARAM_TEXT], 'userfieldfilters[fieldvalue]' => ['type' => PARAM_TEXT] ]; - $this->repeat_elements([$filters], $this->_customdata['filterscount'], $rules, - 'filterscount', 'adduserfieldfilter', 1, get_string('adduserfieldfilter', 'block_advnotifications')); + + $this->repeat_elements([$filters, $deletebutton], $this->_customdata['filterscount'], $rules, + 'filterscount', 'adduserfieldfilter', 1, get_string('adduserfieldfilter', 'block_advnotifications'), + true, 'deletefieldrule'); $this->add_action_buttons(); } @@ -114,6 +90,7 @@ protected function filter_options() { global $DB; $filters = [ + '' => get_string('choosedots'), 'id' => 'id', 'username' => get_string('username'), 'idnumber' => get_string('idnumber'), @@ -142,9 +119,10 @@ protected function filter_options() { protected function operator_options() { return [ - 'beginwith' => get_string('operator_beginwith', 'block_advnotifications'), - 'contains' => get_string('operator_contains', 'block_advnotifications'), - 'equals' => get_string('operator_equals', 'block_advnotifications') + '' => get_string('choosedots'), + 'beginwith' => get_string('operator_beginwith', 'block_advnotifications'), + 'contains' => get_string('operator_contains', 'block_advnotifications'), + 'equals' => get_string('operator_equals', 'block_advnotifications') ]; } } diff --git a/locallib.php b/locallib.php index da33a2a..459bb55 100644 --- a/locallib.php +++ b/locallib.php @@ -81,6 +81,16 @@ function prep_notifications($instanceid) { $render = false; } + if ($render && !\block_advnotifications\audience::meets_profile_requirements($notif->id, $USER->id)) { + $render = false; + } + if ($render && !\block_advnotifications\audience::meets_cohorts_requirements($notif->id, $USER->id)) { + $render = false; + } + if ($render && !\block_advnotifications\audience::meets_roles_requirements($notif->id, $USER->id, $notif->blockid)) { + $render = false; + } + if ($render) { // Update how many times the user has seen the notification. if ($userseen === false) { @@ -154,4 +164,4 @@ function get_date_formats() { $formats['j F Y'] = date('j F Y'); return $formats; -} \ No newline at end of file +} diff --git a/pages/audience.php b/pages/audience.php index c067993..b4955f5 100644 --- a/pages/audience.php +++ b/pages/audience.php @@ -57,7 +57,6 @@ $output = $PAGE->get_renderer('block_advnotifications'); -// TODO! $userfieldfilters = $DB->get_records('block_advnotifications_field', ['notificationid' => $id]); $notification->userfieldfilters = []; foreach ($userfieldfilters as $f) { @@ -87,11 +86,15 @@ $DB->insert_record_raw('block_advnotifications_coh', $coh); } $field = (object)['notificationid' => $id]; - foreach ($data->userfieldfilters as $f) { - $field->userfield = $f['userfield']; - $field->operator = $f['operator']; - $field->fieldvalue = $f['fieldvalue']; - $DB->insert_record_raw('block_advnotifications_field', $field); + if (isset($data->userfieldfilters)) { + foreach ($data->userfieldfilters as $f) { + if (!empty($f['userfield']) && !empty($f['operator']) && !empty($f['fieldvalue'])) { + $field->userfield = $f['userfield']; + $field->operator = $f['operator']; + $field->fieldvalue = $f['fieldvalue']; + $DB->insert_record_raw('block_advnotifications_field', $field); + } + } } $role = (object)['notificationid' => $id]; foreach ($data->roles as $r) { From 6dc7f59a070866b73da2748a6b6bd9557847bc40 Mon Sep 17 00:00:00 2001 From: Daniel Neis Araujo Date: Mon, 20 Sep 2021 16:01:44 -0300 Subject: [PATCH 03/10] add option to send notification (but not send them yet) --- amd/build/custom.min.js | 4 ++-- amd/build/custom.min.js.map | 2 +- amd/src/custom.js | 14 +++++++++++--- db/install.xml | 3 ++- db/upgrade.php | 9 +++++++++ lang/en/block_advnotifications.php | 1 + pages/process.php | 8 ++++++++ renderer.php | 7 ++++++- 8 files changed, 40 insertions(+), 8 deletions(-) diff --git a/amd/build/custom.min.js b/amd/build/custom.min.js index 3d36733..7652016 100644 --- a/amd/build/custom.min.js +++ b/amd/build/custom.min.js @@ -1,2 +1,2 @@ -define(["jquery"],function(l){return{initialise:function(){l(document).ready(function(){var e=l("#region-main"),t=l("#add_notification_wrapper_id"),s={save:"Save",update:"Update",req:"Required...",preview:"Preview",title:"Title",message:"Message"};e.on("click",".notifications_table tr > td > form > button[type=submit]",function(e){e.preventDefault();var n={call:"ajax",purpose:"",tableaction:"",blockid:""},i=l(this).closest("form").attr("data-edit"),e=l(this).closest("form").attr("data-delete");n.blockid=l(this).closest("form").find("[name=blockid]")[0].value,d(),void 0!==i&&!1!==i?(n.purpose="edit",n.tableaction=i,(i=l("#add_notification_save")).addClass("update"),i.val(s.update)):void 0!==e&&!1!==e&&(n.purpose="delete",n.tableaction=e);e=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey;l.post(e,n).fail(function(){console.error("No 'manage' response received.")}).done(function(e){if(e=JSON.parse(e),0'),l("#add_notification_purpose").val("update")),t=l("#add_notification_wrapper_id").find("#add_notification_"+i),"enabled"!==i&&"global"!==i&&"dismissible"!==i&&"aicon"!==i||1!=e[i]?"enabled"!==i&&"global"!==i&&"dismissible"!==i&&"aicon"!==i||0!=e[i]?t.val(e[i]):t.prop("checked",!1):t.prop("checked",!0))}o()}})}),e.on("click",".notifications_restore_table tr > td > form > button[type=submit]",function(e){e.preventDefault();var i={call:"ajax",purpose:"",tableaction:"",blockid:""},t=l(this).closest("form").attr("data-restore"),e=l(this).closest("form").attr("data-permdelete");i.blockid=l(this).closest("form").find("[name=blockid]")[0].value,void 0!==t&&!1!==t?(i.purpose="restore",i.tableaction=t):void 0!==e&&!1!==e&&(i.purpose="permdelete",i.tableaction=e);e=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey;l.post(e,i).fail(function(){console.error("No 'restore/permdelete' response received.")}).done(function(e){e=JSON.parse(e),0'+s.req+"").insertAfter(t[0].nextSibling));o.hide()}).done(function(){o.find(".saving").hide(),o.find(".done").show(),c(),setTimeout(function(){o.fadeOut(function(){o.find(".done").hide(),o.find(".saving").show()})},1500),l("#advnotifications_table_wrapper").load("# #advnotifications_table_wrapper > *")}))}),t.on("input propertychange paste","#add_notification_title, #add_notification_message",function(){o()}),l("#add_notification_type").on("change",function(){o()}),l("#add_notification_dismissible").on("change",function(){o()}),l("#add_notification_aicon").on("change",function(){o()});var i,n,o=function(){var e=t.find("#add_notification_title");0 img").attr("src",M.util.image_url(e,"block_advnotifications")),l("#add_notification_dismissible")[0].checked?(l(".preview-alert-dismissible").show(),i.addClass("dismissible")):(l(".preview-alert-dismissible").hide(),i.removeClass("dismissible")),l("#add_notification_aicon")[0].checked?(l(".preview-aicon").show(),i.addClass("aicon")):(l(".preview-aicon").hide(),i.removeClass("aicon"))},a=function(){var e=l("#notification_preview_wrapper"),i='
'+s.preview+'
'+s.title+'
'+s.message+'
';0'+s.req+"").insertAfter(l(i[e]).closest("select")[0].nextSibling),!1;return!0},d=function(){l("select.requiredfield").removeClass("requiredfield"),l("strong.requiredfield").remove()},c=function(){l("#add_notification_form")[0].reset(),d(),a();var e=l("#add_notification_save");e.removeClass("update"),l("#add_notification_id").remove(),l("#add_notification_purpose").val("add"),e.val(s.save)};i={call:"ajax",purpose:"strings"},n=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey,l.post(n,i).fail(function(){console.error("No 'strings' response received.")}).done(function(e){s=e}).always(function(){a()}),l("#add_notification_form").append('')})}}}); -//# sourceMappingURL=custom.min.js.map \ No newline at end of file +function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("block_advnotifications/custom",["jquery"],function(a){return{initialise:function initialise(){a(document).ready(function(){var b=a("#region-main"),c=a("#add_notification_wrapper_id"),d={save:"Save",update:"Update",req:"Required...",preview:"Preview",title:"Title",message:"Message"};b.on("click",".notifications_table tr > td > form > button[type=submit]",function(b){b.preventDefault();var c={call:"ajax",purpose:"",tableaction:"",blockid:""},g=a(this).closest("form").attr("data-edit"),j=a(this).closest("form").attr("data-delete");c.blockid=a(this).closest("form").find("[name=blockid]")[0].value;h();if(_typeof(g)!=="undefined"&&!1!==g){c.purpose="edit";c.tableaction=g;var k=a("#add_notification_save");k.addClass("update");k.val(d.update)}else if(_typeof(j)!=="undefined"&&!1!==j){c.purpose="delete";c.tableaction=j}var l=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey;a.post(l,c).fail(function(){console.error("No 'manage' response received.")}).done(function(b){b=JSON.parse(b);if(0");a("#add_notification_purpose").val("update")}var h=a("#add_notification_wrapper_id").find("#add_notification_"+d);if(("enabled"===d||"global"===d||"dismissible"===d||"aicon"===d||"sendnotifications"===d)&&1==b[d]){h.prop("checked",!0)}else if(("enabled"===d||"global"===d||"dismissible"===d||"aicon"===d||"sendnotifications"===d)&&0==b[d]){h.prop("checked",!1)}else{h.val(b[d])}}}e()}})});b.on("click",".notifications_restore_table tr > td > form > button[type=submit]",function(b){b.preventDefault();var c={call:"ajax",purpose:"",tableaction:"",blockid:""},d=a(this).closest("form").attr("data-restore"),e=a(this).closest("form").attr("data-permdelete");c.blockid=a(this).closest("form").find("[name=blockid]")[0].value;if(_typeof(d)!=="undefined"&&!1!==d){c.purpose="restore";c.tableaction=d}else if(_typeof(e)!=="undefined"&&!1!==e){c.purpose="permdelete";c.tableaction=e}var f=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey;a.post(f,c).fail(function(){console.error("No 'restore/permdelete' response received.")}).done(function(b){b=JSON.parse(b);if(0"+d.req+"").insertAfter(h[0].nextSibling)}}c.hide()}).done(function(){c.find(".saving").hide();c.find(".done").show();i();setTimeout(function(){c.fadeOut(function(){c.find(".done").hide();c.find(".saving").show()})},1500);a("#advnotifications_table_wrapper").load("# #advnotifications_table_wrapper > *")})});c.on("input propertychange paste","#add_notification_title, #add_notification_message",function(){e()});a("#add_notification_type").on("change",function(){e()});a("#add_notification_dismissible").on("change",function(){e()});a("#add_notification_aicon").on("change",function(){e()});a("#add_notification_sendnotifications").on("change",function(){e()});var e=function(){var b=c.find("#add_notification_title");if(0 img").attr("src",M.util.image_url(f,"block_advnotifications"));if(!a("#add_notification_dismissible")[0].checked){a(".preview-alert-dismissible").hide();g.removeClass("dismissible")}else{a(".preview-alert-dismissible").show();g.addClass("dismissible")}if(!a("#add_notification_aicon")[0].checked){a(".preview-aicon").hide();g.removeClass("aicon")}else{a(".preview-aicon").show();g.addClass("aicon")}},f=function(){var b=a("#notification_preview_wrapper"),e="
"+d.preview+"
"+d.title+"
"+d.message+"
×
";if(0"+d.req+"").insertAfter(a(b[c]).closest("select")[0].nextSibling);return!1}}}return!0},h=function(){a("select.requiredfield").removeClass("requiredfield");a("strong.requiredfield").remove()},i=function(){a("#add_notification_form")[0].reset();h();f();var b=a("#add_notification_save");b.removeClass("update");a("#add_notification_id").remove();a("#add_notification_purpose").val("add");b.val(d.save)};(function init(){var b=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey;a.post(b,{call:"ajax",purpose:"strings"}).fail(function(){console.error("No 'strings' response received.")}).done(function(a){d=a}).always(function(){f()});a("#add_notification_form").append("")})()})}}}); +//# sourceMappingURL=custom.min.js.map diff --git a/amd/build/custom.min.js.map b/amd/build/custom.min.js.map index 8a1cb0a..189ce84 100644 --- a/amd/build/custom.min.js.map +++ b/amd/build/custom.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/custom.js"],"names":["define","$","initialise","document","ready","mainregion","addregion","strings","save","update","req","preview","title","message","on","e","preventDefault","senddata","call","purpose","tableaction","blockid","eattr","closest","attr","dattr","find","value","refreshRequired","savebutton","addClass","val","callpath","M","cfg","wwwroot","sesskey","post","fail","console","error","done","data","JSON","parse","parseInt","fadeOut","remove","clearForm","refreshPreview","i","hasOwnProperty","form","prepend","affectelement","prop","reloadPreview","rattr","pdattr","status","checkRequired","show","serialize","responseJSON","sfield","insertAfter","nextSibling","hide","setTimeout","load","length","innerHTML","alerttype","previewalert","removeClass","util","image_url","checked","previewelem","previewdom","prependTo","slideDown","disselopt","opt","reset","init","always","append"],"mappings":"mSAWAA,OAAM,iCAAC,CAAC,QAAD,CAAD,CAAa,SAASC,CAAT,CAAY,CAG3B,MAAO,CACHC,UAAU,CAAE,qBAAW,CAEnBD,CAAC,CAACE,QAAD,CAAD,CAAYC,KAAZ,CAAkB,UAAW,IAErBC,CAAAA,CAAU,CAAGJ,CAAC,CAAC,cAAD,CAFO,CAGrBK,CAAS,CAAGL,CAAC,CAAC,8BAAD,CAHQ,CAIrBM,CAAO,CAAG,CACVC,IAAI,CAAE,MADI,CAEVC,MAAM,CAAE,QAFE,CAGVC,GAAG,CAAE,aAHK,CAIVC,OAAO,CAAE,SAJC,CAKVC,KAAK,CAAE,OALG,CAMVC,OAAO,CAAE,SANC,CAJW,CAczBR,CAAU,CAACS,EAAX,CAAc,OAAd,CAAuB,2DAAvB,CAAoF,SAASC,CAAT,CAAY,CAC5FA,CAAC,CAACC,cAAF,GAD4F,GAExFC,CAAAA,CAAQ,CAAG,CACNC,IADM,CACC,MADD,CAENC,OAFM,CAEI,EAFJ,CAGNC,WAHM,CAGQ,EAHR,CAINC,OAJM,CAII,EAJJ,CAF6E,CASxFC,CAAK,CAAGrB,CAAC,CAAC,IAAD,CAAD,CAAQsB,OAAR,CAAgB,MAAhB,EAAwBC,IAAxB,CAA6B,WAA7B,CATgF,CAUxFC,CAAK,CAAGxB,CAAC,CAAC,IAAD,CAAD,CAAQs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ACA4B,CAAU,CAAC6C,WAAX,CAAuB,QAAvB,EACAzE,CAAC,CAAC,sBAAD,CAAD,CAA0B8C,MAA1B,GACA9C,CAAC,CAAC,2BAAD,CAAD,CAA+B8B,GAA/B,CAAmC,KAAnC,EAEAF,CAAU,CAACE,GAAX,CAAexB,CAAO,CAACC,IAAvB,CACH,CAnXwB,CAqXzB,CAxFW,QAAP6E,CAAAA,IAAO,EAAW,IAMdrD,CAAAA,CAAQ,CAAGC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,qDAAhB,CAAwEF,CAAC,CAACC,GAAF,CAAME,OAN3E,CAQlBnC,CAAC,CAACoC,IAAF,CAAOL,CAAP,CANe,CACNd,IADM,CACC,MADD,CAENC,OAFM,CAEI,SAFJ,CAMf,EAA2BmB,IAA3B,CAAgC,UAAW,CACvCC,OAAO,CAACC,KAAR,CAAc,iCAAd,CACH,CAFD,EAEGC,IAFH,CAEQ,SAASC,CAAT,CAAe,CAGnBnC,CAAO,CAAGmC,CACb,CAND,EAMG4C,MANH,CAMU,UAAW,CAEjBrC,CAAc,EACjB,CATD,EAYAhD,CAAC,CAAC,wBAAD,CAAD,CAA4BsF,MAA5B,CACI,oFADJ,CAGH,CAiED,GACH,CAtXD,CAuXH,CA1XE,CA4XV,CA/XK,CAAN","sourcesContent":["/* eslint no-console: [\"error\", { allow: [\"error\"] }], max-nested-callbacks: [\"error\", 7] */\n/**\n * @package block_advnotifications\n * @copyright 2019 onwards LearningWorks Ltd {@link https://learningworks.co.nz/}\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @author Zander Potgieter \n */\n\n/**\n * @module block_advnotifications/custom\n */\ndefine(['jquery'], function($) {\n // JQuery is available via $.\n\n return {\n initialise: function() {\n // Module initialised.\n $(document).ready(function() {\n // Commonly (multiple times) used elements.\n var mainregion = $('#region-main');\n var addregion = $('#add_notification_wrapper_id');\n var strings = {\n save: 'Save',\n update: 'Update',\n req: 'Required...',\n preview: 'Preview',\n title: 'Title',\n message: 'Message'\n };\n\n // MANAGING NOTIFICATIONS.\n mainregion.on('click', '.notifications_table tr > td > form > button[type=submit]', function(e) {\n e.preventDefault();\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = '';\n senddata.tableaction = '';\n senddata.blockid = '';\n\n // Check if user wants to edit/delete.\n var eattr = $(this).closest('form').attr('data-edit');\n var dattr = $(this).closest('form').attr('data-delete');\n senddata.blockid = $(this).closest('form').find('[name=blockid]')[0].value;\n refreshRequired();\n\n // Check if anchor element has attribute, retrieved from above.\n if (typeof eattr !== typeof undefined && eattr !== false) {\n senddata.purpose = 'edit';\n senddata.tableaction = eattr;\n\n var savebutton = $('#add_notification_save');\n savebutton.addClass('update');\n savebutton.val(strings.update);\n } else if (typeof dattr !== typeof undefined && dattr !== false) {\n senddata.purpose = 'delete';\n senddata.tableaction = dattr;\n }\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'manage' response received.\");\n }).done(function(data) {\n data = JSON.parse(data);\n\n // User deleted/edited notification.\n if (parseInt(data.done, 10) > 0) {\n $('#tr' + senddata.purpose + data.done).closest(\"tr\").fadeOut(250, function() {\n $(this).remove();\n clearForm();\n refreshPreview();\n });\n } else if (senddata.purpose === \"edit\") {\n for (var i in data) {\n if (data.hasOwnProperty(i)) {\n\n // Need this for updating.\n if (i === \"id\") {\n var form = $('#add_notification_form');\n\n // Because we're doing a standard submit, we need extra inputs to pass params.\n // But first, remove old hidden inputs.\n $('#add_notification_id').remove();\n form.prepend(\n ''\n );\n\n $('#add_notification_purpose').val('update');\n }\n\n var affectelement = $('#add_notification_wrapper_id').find('#add_notification_' + i);\n\n // Check whether checkboxes should be checked or not.\n // We also don't assign a value to checkbox input fields.\n if (\n (\n i === 'enabled' ||\n i === 'global' ||\n i === 'dismissible' ||\n i === 'aicon'\n ) && data[i] == 1) {\n affectelement.prop('checked', true);\n } else if (\n (i === 'enabled' ||\n i === 'global' ||\n i === 'dismissible' ||\n i === 'aicon') && data[i] == 0) {\n affectelement.prop('checked', false);\n } else {\n affectelement.val(data[i]);\n }\n }\n }\n reloadPreview();\n }\n });\n });\n\n // Restore & Permanently delete notifications.\n mainregion.on('click', '.notifications_restore_table tr > td > form > button[type=submit]', function(e) {\n\n e.preventDefault();\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = '';\n senddata.tableaction = '';\n senddata.blockid = '';\n\n // Check if user wants to restore/delete.\n var rattr = $(this).closest('form').attr('data-restore');\n var pdattr = $(this).closest('form').attr('data-permdelete');\n senddata.blockid = $(this).closest('form').find('[name=blockid]')[0].value;\n\n // Check if anchor element has attribute, retrieved from above.\n if (typeof rattr !== typeof undefined && rattr !== false) {\n senddata.purpose = 'restore';\n senddata.tableaction = rattr;\n } else if (typeof pdattr !== typeof undefined && pdattr !== false) {\n senddata.purpose = 'permdelete';\n senddata.tableaction = pdattr;\n }\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'restore/permdelete' response received.\");\n }).done(function(data) {\n data = JSON.parse(data);\n\n // User deleted/restored notification.\n // Object 'done' is returned for both restore & delete.\n if (parseInt(data.done, 10) > 0) {\n $('#tr' + senddata.purpose + data.done).closest(\"tr\").fadeOut(250, function() {\n $(this).remove();\n });\n }\n });\n });\n\n // Clear form.\n addregion.on('click', '#add_notification_cancel', function(e) {\n e.preventDefault();\n clearForm();\n });\n\n // Managing more notifications.\n mainregion.on('submit', '#add_notification_form', function(e) {\n e.preventDefault();\n var status = $('#add_notification_status');\n var form = $('#add_notification_form');\n\n refreshRequired();\n if (!checkRequired()) {\n // Stop if required fields are not supplied.\n return;\n }\n\n status.show();\n\n var senddata = $(this).serialize(); // Data Object.\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php\";\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function(data) {\n console.error(\"No 'add' response received.\");\n\n var error = data.responseJSON.error;\n\n for (var i in error) {\n if (error.hasOwnProperty(i)) {\n var sfield = form.find('select[name=' + error[i] + ']');\n sfield.addClass('requiredfield');\n $(\n '' + strings.req + ''\n ).insertAfter(sfield[0].nextSibling);\n }\n }\n\n status.hide();\n }).done(function() {\n // User saved notification.\n status.find('.saving').hide();\n status.find('.done').show();\n\n // Clear Form.\n clearForm();\n\n setTimeout(function() {\n status.fadeOut(function() {\n status.find('.done').hide();\n status.find('.saving').show();\n });\n }, 1500);\n\n $('#advnotifications_table_wrapper').load('# #advnotifications_table_wrapper > *');\n });\n });\n\n // LIVE PREVIEW.\n // Dynamically update preview alert as user changes textbox content.\n addregion.on('input propertychange paste', '#add_notification_title, #add_notification_message', function() {\n reloadPreview();\n });\n\n // Dynamically update preview alert type.\n $('#add_notification_type').on('change', function() {\n reloadPreview();\n });\n\n $('#add_notification_dismissible').on('change', function() {\n // Checking specifically whether ticked/checked or not to ensure it's displayed correctly (not toggling).\n reloadPreview();\n });\n\n $('#add_notification_aicon').on('change', function() {\n // Checking specifically whether ticked/checked or not to ensure it's displayed correctly (not toggling).\n reloadPreview();\n });\n\n // Check if preview is displaying correct (Update it).\n var reloadPreview = function() {\n // Update title.\n var title = addregion.find('#add_notification_title');\n if (title.val().length > 0) {\n addregion.find('.preview-title')[0].innerHTML = title.val();\n } else {\n addregion.find('.preview-title')[0].innerHTML = strings.title;\n }\n\n // Update message.\n var message = addregion.find('#add_notification_message');\n if (message.val().length > 0) {\n addregion.find('.preview-message')[0].innerHTML = message.val();\n } else {\n addregion.find('.preview-message')[0].innerHTML = strings.message;\n }\n\n // Check notification type.\n var alerttype = $('#add_notification_type').val();\n var previewalert = $('#add_notification_wrapper_id .preview-alert');\n\n // Clear existing classes.\n previewalert.removeClass('alert-info alert-success alert-danger alert-warning announcement');\n\n // Special check for announcement type.\n if (alerttype === 'announcement') {\n previewalert.addClass(alerttype);\n alerttype = 'info';\n }\n\n // If anything unexpected, set to info type.\n if (alerttype !== 'info' && alerttype !== 'success' && alerttype !== 'warning' && alerttype !== 'danger') {\n alerttype = 'info';\n }\n\n // Add type of alert class.\n previewalert.addClass('alert-' + alerttype);\n\n $('.preview-aicon').find('> img').attr('src', M.util.image_url(alerttype, 'block_advnotifications'));\n\n // Check if dismissable.\n if (!$('#add_notification_dismissible')[0].checked) {\n $('.preview-alert-dismissible').hide();\n previewalert.removeClass('dismissible');\n } else {\n $('.preview-alert-dismissible').show();\n previewalert.addClass('dismissible');\n }\n\n // Check if icon should be shown.\n if (!$('#add_notification_aicon')[0].checked) {\n $('.preview-aicon').hide();\n previewalert.removeClass('aicon');\n } else {\n $('.preview-aicon').show();\n previewalert.addClass('aicon');\n }\n };\n\n var init = function() {\n // Get strings.\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = 'strings';\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'strings' response received.\");\n }).done(function(data) {\n // TODO: ONLY DO THIS IF AJAX SUCCESSFUL - don't render with English first?).\n // Store strings and update preview.\n strings = data;\n }).always(function() {\n // Always prepend live preview. Use langstrings if AJAX successful, otherwise use strings declared at top.\n refreshPreview();\n });\n\n // JS is enabled, so we can use AJAX in the new notification form.\n $('#add_notification_form').append(\n ''\n );\n };\n\n // Shiny new and fresh preview.\n var refreshPreview = function() {\n var previewelem = $('#notification_preview_wrapper');\n var previewdom =\n '
' +\n '' + strings.preview + '
' +\n '
' +\n '
' +\n '' +\n '
' +\n '' + strings.title + ' ' +\n '
' + strings.message + '
' +\n '
×
' +\n '
' +\n '
';\n\n // If it exists already, remove before adding again.\n if (previewelem.length > 0) {\n previewelem.remove();\n // Don't slide in.\n $(previewdom).prependTo($(addregion));\n } else {\n // Slide in.\n $(previewdom).prependTo($(addregion)).hide().slideDown();\n }\n };\n\n var checkRequired = function() {\n var disselopt = $('#add_notification_form select option:selected:disabled');\n\n for (var opt in disselopt) {\n if (disselopt.hasOwnProperty(opt)) {\n if ($(disselopt[opt]).prop('disabled')) {\n $(disselopt[opt]).closest('select').addClass('requiredfield');\n $('' + strings.req + '')\n .insertAfter($(disselopt[opt]).closest('select')[0].nextSibling);\n\n return false;\n }\n }\n }\n return true;\n };\n\n var refreshRequired = function() {\n $('select.requiredfield').removeClass('requiredfield');\n $('strong.requiredfield').remove();\n };\n\n var clearForm = function() {\n $('#add_notification_form')[0].reset();\n refreshRequired();\n refreshPreview();\n\n // Change save button back to normal.\n var savebutton = $('#add_notification_save');\n savebutton.removeClass('update');\n $('#add_notification_id').remove();\n $('#add_notification_purpose').val('add');\n\n savebutton.val(strings.save);\n };\n\n init();\n });\n }\n };\n});"],"file":"custom.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/custom.js"],"names":["define","$","initialise","document","ready","mainregion","addregion","strings","save","update","req","preview","title","message","on","e","preventDefault","senddata","call","purpose","tableaction","blockid","eattr","closest","attr","dattr","find","value","refreshRequired","savebutton","addClass","val","callpath","M","cfg","wwwroot","sesskey","post","fail","console","error","done","data","JSON","parse","parseInt","fadeOut","remove","clearForm","refreshPreview","i","hasOwnProperty","form","prepend","affectelement","prop","reloadPreview","rattr","pdattr","status","checkRequired","show","serialize","responseJSON","sfield","insertAfter","nextSibling","hide","setTimeout","load","length","innerHTML","alerttype","previewalert","removeClass","util","image_url","checked","previewelem","previewdom","prependTo","slideDown","disselopt","opt","reset","init","always","append"],"mappings":"mSAWAA,OAAM,iCAAC,CAAC,QAAD,CAAD,CAAa,SAASC,CAAT,CAAY,CAG3B,MAAO,CACHC,UAAU,CAAE,qBAAW,CAEnBD,CAAC,CAACE,QAAD,CAAD,CAAYC,KAAZ,CAAkB,UAAW,IAErBC,CAAAA,CAAU,CAAGJ,CAAC,CAAC,cAAD,CAFO,CAGrBK,CAAS,CA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FJ,CAMf,EAA2BmB,IAA3B,CAAgC,UAAW,CACvCC,OAAO,CAACC,KAAR,CAAc,iCAAd,CACH,CAFD,EAEGC,IAFH,CAEQ,SAASC,CAAT,CAAe,CAGnBnC,CAAO,CAAGmC,CACb,CAND,EAMG4C,MANH,CAMU,UAAW,CAEjBrC,CAAc,EACjB,CATD,EAYAhD,CAAC,CAAC,wBAAD,CAAD,CAA4BsF,MAA5B,CACI,oFADJ,CAGH,CAiED,GACH,CA9XD,CA+XH,CAlYE,CAoYV,CAvYK,CAAN","sourcesContent":["/* eslint no-console: [\"error\", { allow: [\"error\"] }], max-nested-callbacks: [\"error\", 7] */\n/**\n * @package block_advnotifications\n * @copyright 2019 onwards LearningWorks Ltd {@link https://learningworks.co.nz/}\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @author Zander Potgieter \n */\n\n/**\n * @module block_advnotifications/custom\n */\ndefine(['jquery'], function($) {\n // JQuery is available via $.\n\n return {\n initialise: function() {\n // Module initialised.\n $(document).ready(function() {\n // Commonly (multiple times) used elements.\n var mainregion = $('#region-main');\n var addregion = $('#add_notification_wrapper_id');\n var strings = {\n save: 'Save',\n update: 'Update',\n req: 'Required...',\n preview: 'Preview',\n title: 'Title',\n message: 'Message'\n };\n\n // MANAGING NOTIFICATIONS.\n mainregion.on('click', '.notifications_table tr > td > form > button[type=submit]', function(e) {\n e.preventDefault();\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = '';\n senddata.tableaction = '';\n senddata.blockid = '';\n\n // Check if user wants to edit/delete.\n var eattr = $(this).closest('form').attr('data-edit');\n var dattr = $(this).closest('form').attr('data-delete');\n senddata.blockid = $(this).closest('form').find('[name=blockid]')[0].value;\n refreshRequired();\n\n // Check if anchor element has attribute, retrieved from above.\n if (typeof eattr !== typeof undefined && eattr !== false) {\n senddata.purpose = 'edit';\n senddata.tableaction = eattr;\n\n var savebutton = $('#add_notification_save');\n savebutton.addClass('update');\n savebutton.val(strings.update);\n } else if (typeof dattr !== typeof undefined && dattr !== false) {\n senddata.purpose = 'delete';\n senddata.tableaction = dattr;\n }\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'manage' response received.\");\n }).done(function(data) {\n data = JSON.parse(data);\n\n // User deleted/edited notification.\n if (parseInt(data.done, 10) > 0) {\n $('#tr' + senddata.purpose + data.done).closest(\"tr\").fadeOut(250, function() {\n $(this).remove();\n clearForm();\n refreshPreview();\n });\n } else if (senddata.purpose === \"edit\") {\n for (var i in data) {\n if (data.hasOwnProperty(i)) {\n\n // Need this for updating.\n if (i === \"id\") {\n var form = $('#add_notification_form');\n\n // Because we're doing a standard submit, we need extra inputs to pass params.\n // But first, remove old hidden inputs.\n $('#add_notification_id').remove();\n form.prepend(\n ''\n );\n\n $('#add_notification_purpose').val('update');\n }\n\n var affectelement = $('#add_notification_wrapper_id').find('#add_notification_' + i);\n\n // Check whether checkboxes should be checked or not.\n // We also don't assign a value to checkbox input fields.\n if (\n (\n i === 'enabled' ||\n i === 'global' ||\n i === 'dismissible' ||\n i === 'aicon' ||\n i === 'sendnotifications'\n ) && data[i] == 1) {\n affectelement.prop('checked', true);\n } else if (\n (i === 'enabled' ||\n i === 'global' ||\n i === 'dismissible' ||\n i === 'aicon' ||\n i === 'sendnotifications'\n ) && data[i] == 0) {\n affectelement.prop('checked', false);\n } else {\n affectelement.val(data[i]);\n }\n }\n }\n reloadPreview();\n }\n });\n });\n\n // Restore & Permanently delete notifications.\n mainregion.on('click', '.notifications_restore_table tr > td > form > button[type=submit]', function(e) {\n\n e.preventDefault();\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = '';\n senddata.tableaction = '';\n senddata.blockid = '';\n\n // Check if user wants to restore/delete.\n var rattr = $(this).closest('form').attr('data-restore');\n var pdattr = $(this).closest('form').attr('data-permdelete');\n senddata.blockid = $(this).closest('form').find('[name=blockid]')[0].value;\n\n // Check if anchor element has attribute, retrieved from above.\n if (typeof rattr !== typeof undefined && rattr !== false) {\n senddata.purpose = 'restore';\n senddata.tableaction = rattr;\n } else if (typeof pdattr !== typeof undefined && pdattr !== false) {\n senddata.purpose = 'permdelete';\n senddata.tableaction = pdattr;\n }\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'restore/permdelete' response received.\");\n }).done(function(data) {\n data = JSON.parse(data);\n\n // User deleted/restored notification.\n // Object 'done' is returned for both restore & delete.\n if (parseInt(data.done, 10) > 0) {\n $('#tr' + senddata.purpose + data.done).closest(\"tr\").fadeOut(250, function() {\n $(this).remove();\n });\n }\n });\n });\n\n // Clear form.\n addregion.on('click', '#add_notification_cancel', function(e) {\n e.preventDefault();\n clearForm();\n });\n\n // Managing more notifications.\n mainregion.on('submit', '#add_notification_form', function(e) {\n e.preventDefault();\n var status = $('#add_notification_status');\n var form = $('#add_notification_form');\n\n refreshRequired();\n if (!checkRequired()) {\n // Stop if required fields are not supplied.\n return;\n }\n\n status.show();\n\n var senddata = $(this).serialize(); // Data Object.\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php\";\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function(data) {\n console.error(\"No 'add' response received.\");\n\n var error = data.responseJSON.error;\n\n for (var i in error) {\n if (error.hasOwnProperty(i)) {\n var sfield = form.find('select[name=' + error[i] + ']');\n sfield.addClass('requiredfield');\n $(\n '' + strings.req + ''\n ).insertAfter(sfield[0].nextSibling);\n }\n }\n\n status.hide();\n }).done(function() {\n // User saved notification.\n status.find('.saving').hide();\n status.find('.done').show();\n\n // Clear Form.\n clearForm();\n\n setTimeout(function() {\n status.fadeOut(function() {\n status.find('.done').hide();\n status.find('.saving').show();\n });\n }, 1500);\n\n $('#advnotifications_table_wrapper').load('# #advnotifications_table_wrapper > *');\n });\n });\n\n // LIVE PREVIEW.\n // Dynamically update preview alert as user changes textbox content.\n addregion.on('input propertychange paste', '#add_notification_title, #add_notification_message', function() {\n reloadPreview();\n });\n\n // Dynamically update preview alert type.\n $('#add_notification_type').on('change', function() {\n reloadPreview();\n });\n\n $('#add_notification_dismissible').on('change', function() {\n // Checking specifically whether ticked/checked or not to ensure it's displayed correctly (not toggling).\n reloadPreview();\n });\n\n $('#add_notification_aicon').on('change', function() {\n // Checking specifically whether ticked/checked or not to ensure it's displayed correctly (not toggling).\n reloadPreview();\n });\n\n $('#add_notification_sendnotifications').on('change', function() {\n // Checking specifically whether ticked/checked or not to ensure it's displayed correctly (not toggling).\n reloadPreview();\n });\n\n // Check if preview is displaying correct (Update it).\n var reloadPreview = function() {\n // Update title.\n var title = addregion.find('#add_notification_title');\n if (title.val().length > 0) {\n addregion.find('.preview-title')[0].innerHTML = title.val();\n } else {\n addregion.find('.preview-title')[0].innerHTML = strings.title;\n }\n\n // Update message.\n var message = addregion.find('#add_notification_message');\n if (message.val().length > 0) {\n addregion.find('.preview-message')[0].innerHTML = message.val();\n } else {\n addregion.find('.preview-message')[0].innerHTML = strings.message;\n }\n\n // Check notification type.\n var alerttype = $('#add_notification_type').val();\n var previewalert = $('#add_notification_wrapper_id .preview-alert');\n\n // Clear existing classes.\n previewalert.removeClass('alert-info alert-success alert-danger alert-warning announcement');\n\n // Special check for announcement type.\n if (alerttype === 'announcement') {\n previewalert.addClass(alerttype);\n alerttype = 'info';\n }\n\n // If anything unexpected, set to info type.\n if (alerttype !== 'info' && alerttype !== 'success' && alerttype !== 'warning' && alerttype !== 'danger') {\n alerttype = 'info';\n }\n\n // Add type of alert class.\n previewalert.addClass('alert-' + alerttype);\n\n $('.preview-aicon').find('> img').attr('src', M.util.image_url(alerttype, 'block_advnotifications'));\n\n // Check if dismissable.\n if (!$('#add_notification_dismissible')[0].checked) {\n $('.preview-alert-dismissible').hide();\n previewalert.removeClass('dismissible');\n } else {\n $('.preview-alert-dismissible').show();\n previewalert.addClass('dismissible');\n }\n\n // Check if icon should be shown.\n if (!$('#add_notification_aicon')[0].checked) {\n $('.preview-aicon').hide();\n previewalert.removeClass('aicon');\n } else {\n $('.preview-aicon').show();\n previewalert.addClass('aicon');\n }\n };\n\n var init = function() {\n // Get strings.\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = 'strings';\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'strings' response received.\");\n }).done(function(data) {\n // TODO: ONLY DO THIS IF AJAX SUCCESSFUL - don't render with English first?).\n // Store strings and update preview.\n strings = data;\n }).always(function() {\n // Always prepend live preview. Use langstrings if AJAX successful, otherwise use strings declared at top.\n refreshPreview();\n });\n\n // JS is enabled, so we can use AJAX in the new notification form.\n $('#add_notification_form').append(\n ''\n );\n };\n\n // Shiny new and fresh preview.\n var refreshPreview = function() {\n var previewelem = $('#notification_preview_wrapper');\n var previewdom =\n '
' +\n '' + strings.preview + '
' +\n '
' +\n '
' +\n '' +\n '
' +\n '' + strings.title + ' ' +\n '
' + strings.message + '
' +\n '
×
' +\n '
' +\n '
';\n\n // If it exists already, remove before adding again.\n if (previewelem.length > 0) {\n previewelem.remove();\n // Don't slide in.\n $(previewdom).prependTo($(addregion));\n } else {\n // Slide in.\n $(previewdom).prependTo($(addregion)).hide().slideDown();\n }\n };\n\n var checkRequired = function() {\n var disselopt = $('#add_notification_form select option:selected:disabled');\n\n for (var opt in disselopt) {\n if (disselopt.hasOwnProperty(opt)) {\n if ($(disselopt[opt]).prop('disabled')) {\n $(disselopt[opt]).closest('select').addClass('requiredfield');\n $('' + strings.req + '')\n .insertAfter($(disselopt[opt]).closest('select')[0].nextSibling);\n\n return false;\n }\n }\n }\n return true;\n };\n\n var refreshRequired = function() {\n $('select.requiredfield').removeClass('requiredfield');\n $('strong.requiredfield').remove();\n };\n\n var clearForm = function() {\n $('#add_notification_form')[0].reset();\n refreshRequired();\n refreshPreview();\n\n // Change save button back to normal.\n var savebutton = $('#add_notification_save');\n savebutton.removeClass('update');\n $('#add_notification_id').remove();\n $('#add_notification_purpose').val('add');\n\n savebutton.val(strings.save);\n };\n\n init();\n });\n }\n };\n});\n"],"file":"custom.min.js"} \ No newline at end of file diff --git a/amd/src/custom.js b/amd/src/custom.js index 9be77a8..49dfec6 100644 --- a/amd/src/custom.js +++ b/amd/src/custom.js @@ -98,14 +98,17 @@ define(['jquery'], function($) { i === 'enabled' || i === 'global' || i === 'dismissible' || - i === 'aicon' + i === 'aicon' || + i === 'sendnotifications' ) && data[i] == 1) { affectelement.prop('checked', true); } else if ( (i === 'enabled' || i === 'global' || i === 'dismissible' || - i === 'aicon') && data[i] == 0) { + i === 'aicon' || + i === 'sendnotifications' + ) && data[i] == 0) { affectelement.prop('checked', false); } else { affectelement.val(data[i]); @@ -240,6 +243,11 @@ define(['jquery'], function($) { reloadPreview(); }); + $('#add_notification_sendnotifications').on('change', function() { + // Checking specifically whether ticked/checked or not to ensure it's displayed correctly (not toggling). + reloadPreview(); + }); + // Check if preview is displaying correct (Update it). var reloadPreview = function() { // Update title. @@ -392,4 +400,4 @@ define(['jquery'], function($) { }); } }; -}); \ No newline at end of file +}); diff --git a/db/install.xml b/db/install.xml index 46987a1..4b5f825 100755 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -11,6 +11,7 @@ + diff --git a/db/upgrade.php b/db/upgrade.php index 8d17ef6..cfd0b34 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -159,6 +159,15 @@ function xmldb_block_advnotifications_upgrade($oldversion) { $dbman->create_table($table); } + // Define field id to be added to block_advnotifications. + $table = new xmldb_table('block_advnotifications'); + $field = new xmldb_field('sendnotifications', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'aicon'); + + // Conditionally launch add field id. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + // Advnotifications savepoint reached. upgrade_block_savepoint(true, 2021101400, 'advnotifications'); } diff --git a/lang/en/block_advnotifications.php b/lang/en/block_advnotifications.php index bb4e71b..40e9700 100644 --- a/lang/en/block_advnotifications.php +++ b/lang/en/block_advnotifications.php @@ -85,6 +85,7 @@ $string['advnotifications_cancel'] = 'Cancel'; $string['advnotifications_req'] = 'Required...'; $string['advnotifications_preview'] = 'Preview'; +$string['advnotifications_sendnotifications'] = 'Send notitications via site notification system (usually will appear on the bell icon on top)'; // Renderer. $string['advnotifications_add_heading'] = 'New notification'; diff --git a/pages/process.php b/pages/process.php index 28010d4..b095af8 100644 --- a/pages/process.php +++ b/pages/process.php @@ -61,6 +61,7 @@ $type = optional_param('type', null, PARAM_TEXT); $times = optional_param('times', null, PARAM_INT); $aicon = optional_param('aicon', null, PARAM_TEXT); +$sendnotifications = optional_param('sendnotifications', null, PARAM_TEXT); $dismissible = optional_param('dismissible', null, PARAM_TEXT); $datefrom = optional_param('date_from', null, PARAM_TEXT); $dateto = optional_param('date_to', null, PARAM_TEXT); @@ -101,6 +102,11 @@ } else { $dismissible = 0; } +if ($sendnotifications == 'on' || $sendnotifications == '1') { + $sendnotifications = 1; +} else { + $sendnotifications = 0; +} // TODO: Check if successful? // Convert dates to epoch for DB. If empty, set to 0 (forever) by default. @@ -265,6 +271,7 @@ $urow->message = $message; $urow->type = $type; $urow->aicon = $aicon; + $urow->sendnotifications = $sendnotifications; $urow->enabled = $enabled; $urow->global = $global; $urow->blockid = $blockinstance; @@ -347,6 +354,7 @@ $row->message = $message; $row->type = $type; $row->aicon = $aicon; + $row->sendnotifications = $sendnotifications; $row->enabled = $enabled; $row->global = $global; $row->blockid = $blockinstance; diff --git a/renderer.php b/renderer.php index 1647aec..91b5ae4 100644 --- a/renderer.php +++ b/renderer.php @@ -189,6 +189,11 @@ class="form-check-input" +
+ + +