Skip to content

Commit

Permalink
Fixed session based issues
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Sep 13, 2023
1 parent 5a13b01 commit d7ea72c
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 61 deletions.
89 changes: 53 additions & 36 deletions actions/notification/classes/actionform.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function trigger_action($instancedata, $userid, $expectedtime=null, $newu
}

$notification->create_schedule_foruser($userid, '', null, $runtime ?? null, $newuser);

schedule::instance()->send_scheduled_notification($userid);
}

Expand Down Expand Up @@ -243,6 +243,13 @@ protected function update_data_structure(&$actiondata) {
});
}

/**
* Save the template config.
*
* @param stdclass $record
* @param string $component
* @return void
*/
public function process_save($record, $component) {
global $DB;

Expand Down Expand Up @@ -324,8 +331,30 @@ public function process_instance_save($instanceid, $record) {
return true;
}

/**
* Default override elements.
*
* @return array
*/
public function default_override_elements() {
// List of pulse notification elements those are available in only instances.
return [
'pulsenotification_suppress',
'pulsenotification_suppressoperator',
'pulsenotification_dynamiccontent',
'pulsenotification_contenttype',
'pulsenotification_chapterid',
'pulsenotification_contentlength',
];
}


/**
* Load the instance elements for the form.
*
* @param moodle_form $mform
* @param actionform $forminstance
* @return void
*/
public function load_instance_form(&$mform, $forminstance) {
global $CFG, $PAGE;

Expand All @@ -345,12 +374,9 @@ public function load_instance_form(&$mform, $forminstance) {
$value = $value->name;
});

$suppress = $mform->createElement('autocomplete', 'pulsenotification_suppress',
$suppress = $mform->createElement('autocomplete', 'pulsenotification_suppress',
get_string('suppressmodule', 'pulseaction_notification'), $activities, array('multiple' => 'multiple'));

$mform->addElement('hidden', "override[pulsenotification_suppress]", 1);
$mform->setType("override[pulsenotification_suppress]", PARAM_BOOL);


$mform->insertElementBefore($suppress, 'pulsenotification_notifylimit');
$mform->addHelpButton('pulsenotification_suppress', 'suppressmodule', 'pulseaction_notification');

Expand All @@ -364,10 +390,6 @@ public function load_instance_form(&$mform, $forminstance) {
$mform->insertElementBefore($suppressopertor, 'pulsenotification_notifylimit');
$mform->addHelpButton('pulsenotification_suppressoperator', 'suppressoperator', 'pulseaction_notification');

$mform->addElement('hidden', "override[pulsenotification_suppressoperator]", 1);
$mform->setType("override[pulsenotification_suppressoperator]", PARAM_BOOL);


$modules = [0 => get_string('none')];
$books = $modinfo->get_instances_of('book');
$pages = $modinfo->get_instances_of('page');
Expand All @@ -376,7 +398,6 @@ public function load_instance_form(&$mform, $forminstance) {
$modules[$page->id] = $page->get_formatted_name();
}

// array_unshift($modules, get_string('none'));
$dynamic = $mform->createElement('select', 'pulsenotification_dynamiccontent', get_string('dynamiccontent', 'pulseaction_notification'), $modules);
$mform->insertElementBefore($dynamic, 'pulsenotification_footercontent_editor');
$mform->addHelpButton('pulsenotification_dynamiccontent', 'dynamiccontent', 'pulseaction_notification');
Expand Down Expand Up @@ -418,9 +439,7 @@ public function load_instance_form(&$mform, $forminstance) {

asort($mform->_elementIndex);

// TODO: Merge both.
$PAGE->requires->js_call_amd('pulseaction_notification/chaptersource', 'updateChapter', ['contextid' => $PAGE->context->id]);
// $PAGE->requires->js_call_amd('pulseaction_notification/chaptersource', 'previewNotification', ['contextid' => $PAGE->context->id]);
}

/**
Expand All @@ -444,8 +463,8 @@ public function load_global_form(&$mform, $forminstance) {
);
$mform->addElement('select', 'pulsenotification_sender', get_string('sender', 'pulseaction_notification'), $sender_options);
$mform->addHelpButton('pulsenotification_sender', 'sender', 'pulseaction_notification');
// Add additional settings for the 'custom' option, if selected.

// Add additional settings for the 'custom' option, if selected.
$mform->addElement('text', 'pulsenotification_senderemail', get_string('senderemail', 'pulseaction_notification'));
$mform->setType('pulsenotification_senderemail', PARAM_EMAIL);
$mform->hideIf('pulsenotification_senderemail', 'pulsenotification_sender', 'neq', notification::SENDERCUSTOM);
Expand All @@ -459,8 +478,8 @@ public function load_global_form(&$mform, $forminstance) {
notification::INTERVALMONTHLY => get_string('monthly', 'pulseaction_notification'),
);
$interval[] =& $mform->createElement('select', 'pulsenotification_notifyinterval[interval]', get_string('interval', 'pulseaction_notification'), $intervaloptions);
// Add additional settings based on the selected interval.

// Add additional settings based on the selected interval.
$dayweeks = array(
'monday' => get_string('monday', 'pulseaction_notification'),
'tuesday' => get_string('tuesday', 'pulseaction_notification'),
Expand All @@ -470,6 +489,7 @@ public function load_global_form(&$mform, $forminstance) {
'saturday' => get_string('saturday', 'pulseaction_notification'),
'sunday' => get_string('sunday', 'pulseaction_notification'),
);

// Add 'day_of_week' element if 'weekly' is selected in the 'interval' element.
$interval[] =& $mform->createElement('select', 'pulsenotification_notifyinterval[weekday]', get_string('interval', 'pulseaction_notification'), $dayweeks);
$mform->hideIf('pulsenotification_notifyinterval[weekday]', 'pulsenotification_notifyinterval[interval]', 'neq', notification::INTERVALWEEKLY);
Expand Down Expand Up @@ -510,12 +530,11 @@ public function load_global_form(&$mform, $forminstance) {
$mform->setType('pulsenotification_notifylimit', PARAM_INT);
$mform->addHelpButton('pulsenotification_notifylimit', 'limit', 'pulseaction_notification');

// Recipients Group
// Recipients Group.
// Add 'recipients' element with all roles that can receive notifications.
$roles = get_roles_with_capability('pulseaction/notification:receivenotification');
$rolenames = role_fix_names($roles);
$roleoptions = array_combine(array_column($rolenames, 'id'), array_column($rolenames, 'localname'));

$mform->addElement('autocomplete', 'pulsenotification_recipients', get_string('recipients', 'pulseaction_notification'), $roleoptions, array('multiple' => 'multiple'));
$mform->addHelpButton('pulsenotification_recipients', 'recipients', 'pulseaction_notification');

Expand All @@ -540,51 +559,49 @@ public function load_global_form(&$mform, $forminstance) {
$mform->addHelpButton('pulsenotification_headercontent_editor', 'headercontent', 'pulseaction_notification');
$forminstance->pulse_email_placeholders($mform);

// Statecontent editor.
$mform->addElement('editor', 'pulsenotification_staticcontent_editor', get_string('staticcontent', 'pulseaction_notification'),
['class' => 'fitem_id_templatevars_editor'], $this->get_editor_options($context));
$mform->addHelpButton('pulsenotification_staticcontent_editor', 'staticcontent', 'pulseaction_notification');
$forminstance->pulse_email_placeholders($mform);
// Dynamic content goes here.

// Footer Content
// Footer Content.
$mform->addElement('editor', 'pulsenotification_footercontent_editor', get_string('footercontent', 'pulseaction_notification'),
['class' => 'fitem_id_templatevars_editor'], $this->get_editor_options($context));
$mform->addHelpButton('pulsenotification_footercontent_editor', 'footercontent', 'pulseaction_notification');
$forminstance->pulse_email_placeholders($mform);

// Preview Button
// Preview Button.
$mform->addElement('button', 'pulsenotification_preview', get_string('preview', 'pulseaction_notification'));
$mform->addHelpButton('pulsenotification_preview', 'preview', 'pulseaction_notification');

// $mform->addElement('html', html_writer::end_div()); // E.O of actions triggere tab.

// Email tempalte placholders.
// Email tempalte placholders.
$PAGE->requires->js_call_amd('mod_pulse/module', 'init');
$PAGE->requires->js_call_amd('pulseaction_notification/chaptersource', 'previewNotification', ['contextid' => $PAGE->context->id]);
}

/**
* Get list of options in 30 mins timeinterval for 24 hrs.
*
* @return array
*/
public function get_times() {

$starttime = new DateTime('00:00'); // Set the start time to midnight
$endtime = new DateTime('23:59'); // Set the end time to just before midnight of the next day
$starttime = new DateTime('00:00'); // Set the start time to midnight.
$endtime = new DateTime('23:59'); // Set the end time to just before midnight of the next day.

// Create an interval of 30 minutes
$interval = new \DateInterval('PT30M'); // PT30M represents 30 minutes
// Create an interval of 30 minutes.
$interval = new \DateInterval('PT30M'); // PT30M represents 30 minutes.

// Create a DatePeriod to iterate through the day with the specified interval
// Create a DatePeriod to iterate through the day with the specified interval.
$timeperiod = new DatePeriod($starttime, $interval, $endtime);


// Loop through the DatePeriod and add each timestamp to the array
// Loop through the DatePeriod and add each timestamp to the array.
$timelist = array();
foreach ($timeperiod as $time) {
$timelist[$time->format('H:i')] = $time->format('H:i'); // Format the timestamp as HH:MM
$timelist[$time->format('H:i')] = $time->format('H:i'); // Format the timestamp as HH:MM.
}

return $timelist;
}


}


44 changes: 38 additions & 6 deletions actions/notification/classes/local/entities/notification.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Pulse notification entities for report builder
*
* @package pulseaction_notification
* @copyright 2023, bdecent gmbh bdecent.de
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace pulseaction_notification\local\entities;

use core_reportbuilder\local\entities\base;
Expand All @@ -10,6 +31,9 @@
use pulseaction_notification\notification as pulsenotification;
use lang_string;

/**
* Pulse notification entity base for report source.
*/
class notification extends base {

/**
Expand Down Expand Up @@ -62,7 +86,11 @@ public function initialise(): base {
return $this;
}


/**
* List of columns available for this notfication datasource.
*
* @return array
*/
protected function get_all_columns(): array {

$notificationschalias = $this->get_table_alias('pulseaction_notification_sch');
Expand Down Expand Up @@ -112,7 +140,8 @@ protected function get_all_columns(): array {
$this->get_entity_name()
))
->set_is_sortable(true)
->add_field("IF ({$notificationinsalias}.subject <> '', {$notificationinsalias}.subject, {$notificationalias}.subject)", "subject")
->add_field("IF ({$notificationinsalias}.subject <> '',
{$notificationinsalias}.subject, {$notificationalias}.subject)", "subject")
->add_field("{$templatesinsalias}.instanceid")
->add_field("{$notificationschalias}.userid")
->add_callback(static function($value, $row): string {
Expand Down Expand Up @@ -266,8 +295,11 @@ public function schedulejoin() {
return "
JOIN {pulse_autoinstances} AS {$autoinstancesalias} ON {$autoinstancesalias}.id = {$notificationschalias}.instanceid
JOIN {pulse_autotemplates} AS {$autotemplatesalias} ON {$autotemplatesalias}.id = {$autoinstancesalias}.templateid
JOIN {pulse_autotemplates_ins} AS {$autotemplatesinsalias} ON {$autotemplatesinsalias}.instanceid = {$autoinstancesalias}.id
JOIN {pulseaction_notification_ins} AS {$notificationinsalias} ON {$notificationinsalias}.instanceid = {$notificationschalias}.instanceid
JOIN {pulseaction_notification} AS {$notificationalias} ON {$notificationalias}.templateid = {$autoinstancesalias}.templateid";
JOIN {pulse_autotemplates_ins} AS {$autotemplatesinsalias}
ON {$autotemplatesinsalias}.instanceid = {$autoinstancesalias}.id
JOIN {pulseaction_notification_ins} AS {$notificationinsalias}
ON {$notificationinsalias}.instanceid = {$notificationschalias}.instanceid
JOIN {pulseaction_notification} AS {$notificationalias}
ON {$notificationalias}.templateid = {$autoinstancesalias}.templateid";
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Pulse notification datasource for the schedules.
*
* @package pulseaction_notification
* @copyright 2023, bdecent gmbh bdecent.de
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace pulseaction_notification\reportbuilder\datasource;

use core_reportbuilder\datasource;
use core_reportbuilder\local\entities\course;
use core_reportbuilder\local\entities\user;

/**
* Notification datasource definition for the list of schedules.
*/
class notification extends datasource {

/**
Expand All @@ -23,7 +48,6 @@ public static function get_name(): string {
protected function initialise(): void {
global $PAGE;

// require_once($CFG->dirroot.'/mod/attendance/locallib.php');
$notificationentity = new \pulseaction_notification\local\entities\notification();
$notificationalias = $notificationentity->get_table_alias('pulse_autoinstances');

Expand All @@ -49,9 +73,11 @@ protected function initialise(): void {
$this->add_base_condition_simple("{$notificationschalias}.instanceid", $instance);
}

// Support for 4.2.
if (method_exists($this, 'add_all_from_entities')) {
$this->add_all_from_entities();
} else {
// Add all the entities used in notification datasource. moodle 4.0 support.
$this->add_columns_from_entity($notificationentity->get_entity_name());
$this->add_filters_from_entity($notificationentity->get_entity_name());
$this->add_conditions_from_entity($notificationentity->get_entity_name());
Expand All @@ -65,7 +91,9 @@ protected function initialise(): void {
$this->add_conditions_from_entity($coursentity->get_entity_name());
}

$PAGE->requires->js_call_amd('pulseaction_notification/chaptersource', 'reportModal', ['contextid' => \context_system::instance()->id]);
// Init the script to show the notification content in the modal.
$params = ['contextid' => \context_system::instance()->id];
$PAGE->requires->js_call_amd('pulseaction_notification/chaptersource', 'reportModal', $params);
}

/**
Expand All @@ -89,7 +117,7 @@ public function get_default_columns(): array {
/**
* Return the filters that will be added to the report once is created
*
* @return string[]
* @return array
*/
public function get_default_filters(): array {
return [];
Expand All @@ -98,13 +126,11 @@ public function get_default_filters(): array {
/**
* Return the conditions that will be added to the report once is created
*
* @return string[]
* @return array
*/
public function get_default_conditions(): array {
return [
'notification:instanceid'
];
}


}
Loading

0 comments on commit d7ea72c

Please sign in to comment.