Skip to content

Commit

Permalink
Added all modules for dynamic content
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Oct 1, 2023
1 parent dff7931 commit ebc06d0
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 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.

24 changes: 23 additions & 1 deletion actions/notification/amd/src/chaptersource.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,35 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/modal_factory', 'core/
}).fail(failure);
},

updateChapter: function() {
updateChapter: function(ctxID, contentMods) {

const SELECTORS = {
chaperType: "#id_pulsenotification_contenttype",
mod: "#id_pulsenotification_dynamiccontent"
};

// Disable the content type option for modules other than book and page.
if (contentMods !== null) {
var type = document.querySelector(SELECTORS.chaperType);
document.querySelector(SELECTORS.mod).addEventListener("change", (e) => {
var target = e.currentTarget;
var selected = target.value;
if (contentMods.includes(selected.toString())) {
Array.prototype.find.call(type.options, function(cmid) {
if (cmid.value == '2') {
cmid.disabled = false;
}
});
} else {
Array.prototype.find.call(type.options, function(cmid) {
if (cmid.value == '2') {
cmid.disabled = true;
}
});
}
});
}

document.querySelector(SELECTORS.chaperType).addEventListener("change", () => resetChapter());
document.querySelector(SELECTORS.mod).addEventListener("change", () => resetChapter());
var chapter = document.querySelector("#id_pulsenotification_chapterid");
Expand Down
18 changes: 12 additions & 6 deletions actions/notification/classes/actionform.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,18 @@ public function load_instance_form(&$mform, $forminstance) {
$mform->addHelpButton('pulsenotification_suppressoperator', 'suppressoperator', 'pulseaction_notification');

$modules = [0 => get_string('none')];
$books = $modinfo->get_instances_of('book');
$pages = $modinfo->get_instances_of('page');
$list = array_merge($books, $pages);
foreach ($list as $page) {
$modules[$page->id] = $page->get_formatted_name();
$list = $modinfo->get_instances();
$contentmods = [];
foreach ($list as $modname => $mods) {
foreach ($mods as $mod) {
$modules[$mod->id] = $mod->get_formatted_name();
if ($mod->modname == 'page' || $mod->modname == 'book') {
$contentmods[] = $mod->id;
}
}
}
// PAGE modules in this course.
$pages = $modinfo->get_instances_of('page');

$dynamic = $mform->createElement('select', 'pulsenotification_dynamiccontent',
get_string('dynamiccontent', 'pulseaction_notification'), $modules);
Expand Down Expand Up @@ -584,7 +590,7 @@ public function load_instance_form(&$mform, $forminstance) {
asort($mform->_elementIndex);

$PAGE->requires->js_call_amd('pulseaction_notification/chaptersource', 'updateChapter',
['contextid' => $PAGE->context->id]
['contextid' => $PAGE->context->id, 'contentmods' => $contentmods]
);
}

Expand Down
4 changes: 2 additions & 2 deletions actions/notification/classes/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ public static function generate_dynamic_content($contenttype, $contentlength, $c
return '';
}

if ($contenttype == self::DYNAMIC_CONTENT) {
if ($contenttype == self::DYNAMIC_CONTENT && in_array($cm->modname, ['book', 'page'])) {

if ($cm->modname == 'book') {
$chapter = $DB->get_record('book_chapters', ['id' => $chapterid, 'bookid' => $cm->instance]);
Expand All @@ -838,7 +838,7 @@ public static function generate_dynamic_content($contenttype, $contentlength, $c

$content = format_text($chaptertext, $chapter->contentformat, ['noclean' => true, 'overflowdiv' => true]);
$link = new moodle_url('/mod/book/view.php', ['id' => $cm->id, 'chapterid' => $chapterid]);
} else {
} else if ($cm->modname == 'page') {
$page = $DB->get_record('page', array('id' => $cm->instance), '*', MUST_EXIST);

$content = file_rewrite_pluginfile_urls(
Expand Down
Loading

0 comments on commit ebc06d0

Please sign in to comment.