Skip to content

Commit

Permalink
Fixed moodle 4.1 support issues
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Sep 20, 2023
1 parent c8c04a5 commit 6a60483
Show file tree
Hide file tree
Showing 30 changed files with 276 additions and 128 deletions.
2 changes: 1 addition & 1 deletion actions/notification/amd/build/chaptersource.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion actions/notification/amd/build/chaptersource.min.js.map

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions actions/notification/amd/src/chaptersource.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,23 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/modal_factory', 'core/

const previewModalBody = function(contextID, userid=null) {

if (window.tinyMCE !== null) {
editorPlugin = window.tinyMCE;
if (window.tinyMCE !== undefined) {
// editorPlugin = window.tinyMCE;
var params = {
contentheader: window.tinyMCE.get('id_pulsenotification_headercontent_editor').getContent(),
contentstatic: window.tinyMCE.get('id_pulsenotification_staticcontent_editor').getContent(),
contentfooter: window.tinyMCE.get('id_pulsenotification_footercontent_editor').getContent(),
userid: userid
};
} else {
editorPlugin = document;
// editorPlugin = document;
var params = {
contentheader: document.querySelector('id_pulsenotification_headercontent_editoreditable').html(),
contentstatic: document.querySelector('id_pulsenotification_staticcontent_editoreditable').html(),
contentfooter: document.querySelector('id_pulsenotification_footercontent_editoreditable').html(),
contentheader: document.querySelector('#id_pulsenotification_headercontent_editoreditable').innerHTML,
contentstatic: document.querySelector('#id_pulsenotification_staticcontent_editoreditable').innerHTML,
contentfooter: document.querySelector('#id_pulsenotification_footercontent_editoreditable').innerHTML,
userid: userid
};
}

}

var dynamicparams = {};
if (document.querySelector('[name=pulsenotification_dynamiccontent]') !== null) {
Expand Down
7 changes: 6 additions & 1 deletion actions/notification/classes/actionform.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ public function trigger_action($instancedata, $userid, $expectedtime=null, $newu
$notification = notification::instance($instancedata->pulsenotification_id);
$notificationinstance = helper::filter_record_byprefix($instancedata, $this->config_shortname());

// print_object($instancedata);exit;
$notification->set_notification_data($notificationinstance, $instancedata);

// Create a schedule for user. This method verify the user activity completion before creating schedules.
Expand Down Expand Up @@ -324,6 +323,8 @@ public function process_instance_save($instanceid, $record) {
$DB->update_record($tablename, $actiondata);
} else {
// Create new instance for this tempalte.
/* print_object($actiondata);
exit; */
$notificationinstance = $DB->insert_record($tablename, $actiondata);
}
// TODO: Create a schedules based on receipents role.
Expand Down Expand Up @@ -401,6 +402,7 @@ public function load_instance_form(&$mform, $forminstance) {
$list = array_merge($books, $pages);
foreach ($list as $page) {
$modules[$page->id] = $page->get_formatted_name();

}

$dynamic = $mform->createElement('select', 'pulsenotification_dynamiccontent', get_string('dynamiccontent', 'pulseaction_notification'), $modules);
Expand Down Expand Up @@ -431,6 +433,9 @@ public function load_instance_form(&$mform, $forminstance) {
$mform->insertElementBefore($chapter, 'pulsenotification_footercontent_editor');
$mform->addHelpButton('pulsenotification_chapterid', 'chapters', 'pulseaction_notification');
$mform->hideIf('pulsenotification_chapterid', 'pulsenotification_dynamiccontent', 'eq', 0);
foreach ($pages as $page) {
$mform->hideIf('pulsenotification_chapterid', 'pulsenotification_dynamiccontent', 'eq', $page->id);
}

// Content Length Group.
$content_length_options = array(
Expand Down
16 changes: 9 additions & 7 deletions actions/notification/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
use core_external\external_multiple_structure;
use core_external\external_single_structure;

class external extends external_api {
require_once($CFG->libdir.'/externallib.php');

class external extends \external_api {

/**
* Get list of chapters for the book module function parameters.
* @return object type of the badge type.
*/
public static function get_chapters_parameters() {
return new external_function_parameters(
array('mod' => new external_value(PARAM_INT, 'Book module cmid ', VALUE_OPTIONAL))
return new \external_function_parameters(
array('mod' => new \external_value(PARAM_INT, 'Book module cmid ', VALUE_OPTIONAL))
);
}

Expand Down Expand Up @@ -46,11 +48,11 @@ public static function get_chapters($mod = null) {
* @return array list of chapaters.
*/
public static function get_chapters_returns() {
return new external_multiple_structure(
new external_single_structure(
return new \external_multiple_structure(
new \external_single_structure(
array(
'value' => new external_value(PARAM_INT, 'Chapter ID', VALUE_OPTIONAL),
'label' => new external_value(PARAM_TEXT, 'Chapter title', VALUE_OPTIONAL),
'value' => new \external_value(PARAM_INT, 'Chapter ID', VALUE_OPTIONAL),
'label' => new \external_value(PARAM_TEXT, 'Chapter title', VALUE_OPTIONAL),
)
), '', VALUE_OPTIONAL
);
Expand Down
12 changes: 3 additions & 9 deletions actions/notification/classes/local/entities/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,9 @@ protected function get_all_columns(): array {
{$notificationinsalias}.subject, {$notificationalias}.subject)", "subject")
->add_field("{$templatesinsalias}.instanceid")
->add_field("{$notificationschalias}.userid")
->add_callback(static function($value, $row): string {

return $value . html_writer::link('javascript:void(0);', '<i class="fa fa-info"></i>', [
'class' => 'pulse-automation-info-block',
'data-target' => 'view-content',
'data-instanceid' => $row->instanceid,
'data-userid' => $row->userid
]);
});
->add_callback([pulsenotification::class, 'get_schedule_subject']);



// Status of the schedule.
$columns[] = (new column(
Expand Down
20 changes: 19 additions & 1 deletion actions/notification/classes/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ protected function get_users_withroles(array $roles, $context) {
list($insql, $inparams) = $DB->get_in_or_equal($roles, SQL_PARAMS_NAMED, 'rle');

// TODO: Define user fields, never get entire fields.
$rolesql = "SELECT DISTINCT u.*, ra.roleid FROM {role_assignments} ra
$rolesql = "SELECT DISTINCT u.id, u.*, ra.roleid FROM {role_assignments} ra
JOIN {user} u ON u.id = ra.userid
JOIN {role} r ON ra.roleid = r.id
LEFT JOIN {role_names} rn ON (rn.contextid = :ctxid AND rn.roleid = r.id)
Expand Down Expand Up @@ -668,6 +668,24 @@ public static function get_schedule_status($value) {
}
}

public static function get_schedule_subject($value, $row) {
global $DB;

$sender = \core_user::get_support_user();
$courseid = $DB->get_field('pulse_autoinstances', 'courseid', ['id' => $row->instanceid]);
$user = (object) \core_user::get_user($row->userid);
$course = get_course($courseid ?? SITEID);

list($subject, $messagehtml) = \mod_pulse\helper::update_emailvars('', $value, $course, $user, null, $sender);

return $subject . html_writer::link('javascript:void(0);', '<i class="fa fa-info"></i>', [
'class' => 'pulse-automation-info-block',
'data-target' => 'view-content',
'data-instanceid' => $row->instanceid,
'data-userid' => $row->userid
]);
}

public static function get_modules_data($modules) {
global $DB, $CFG;

Expand Down
5 changes: 1 addition & 4 deletions actions/notification/classes/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public function send_scheduled_notification($userid=null) {

$messagesend = email_to_user($detail->recepient, $sender, $subject, $messageplain, $messagehtml, '', '', true, $replyto ?? '');


if ($messagesend) {
// Update the current time as lastrun.
// Update the lastrun and increase the limit.
Expand All @@ -131,16 +130,14 @@ public function send_scheduled_notification($userid=null) {
$update = [
'id' => $this->schedule->id,
'notifycount' => $notifycount,
'status' => notification::STATUS_SEND,
'status' => notification::STATUS_SENT,
'notifiedtime' => $notifiedtime,
];

// Generate a next runtime. Only if user has limit to receive notifications. otherwise made the nextrun null.

// Update the schedule.
$DB->update_record('pulseaction_notification_sch', $update);


if ($notifycount < $this->notificationdata->notifylimit
&& $this->notificationdata->notifyinterval['interval'] != notification::INTERVALONCE) {
$newschedule = true;
Expand Down
6 changes: 3 additions & 3 deletions actions/notification/lang/en/pulseaction_notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
$string['notification:sender'] = 'Sender of the automation notification';


$string['courseteacher'] = 'Courseteacher';
$string['groupteacher'] = 'Groupteacher';
$string['tenantrole'] = 'Tenantrole';
$string['courseteacher'] = 'Course teacher';
$string['groupteacher'] = 'Group teacher';
$string['tenantrole'] = 'Tenant role';
$string['custom'] = 'Custom';
$string['senderemail'] = 'Sender email';
$string['once'] = 'Once';
Expand Down
2 changes: 1 addition & 1 deletion actions/notification/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ function pulseaction_notification_output_fragment_preview_instance_content($args

$context = $args['context'];
if (isset($args['instanceid'])) {

$insobj = new \mod_pulse\automation\instances($args['instanceid']);
$formdata = (object) $insobj->get_instance_data();

$notificationid = $formdata->actions['notification']['id'];
$notificationobj = pulseaction_notification\notification::instance($notificationid);

$notificationobj->set_notification_data($formdata->actions['notification'], $formdata);

$content = $notificationobj->build_notification_content(null, null, $formdata->override);

$sender = core_user::get_support_user();
Expand Down
Loading

0 comments on commit 6a60483

Please sign in to comment.