From c42c23557e00f47141ce09d1e0661df500df19b6 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 29 Mar 2016 15:26:29 +0800 Subject: [PATCH] MDL-53634 forum: Switch digest selection to inplace_editable --- mod/forum/index.php | 21 +++++++-------------- mod/forum/lang/en/deprecated.txt | 5 +++++ mod/forum/lang/en/forum.php | 10 +++++----- mod/forum/lib.php | 27 +++++++++++++++++++++++++++ mod/forum/renderer.php | 23 +++++++++++++++++++++++ 5 files changed, 67 insertions(+), 19 deletions(-) diff --git a/mod/forum/index.php b/mod/forum/index.php index d3405eb5986..38bb8ccaccb 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -48,7 +48,6 @@ require_course_login($course); $PAGE->set_pagelayout('incourse'); $coursecontext = context_course::instance($course->id); - unset($SESSION->fromdiscussion); $params = array( @@ -77,8 +76,7 @@ $stremaildigest = get_string('emaildigest'); $searchform = forum_search_form($course); -// Start of the table for General Forums - +// Start of the table for General Forums. $generaltable = new html_table(); $generaltable->head = array ($strforum, $strdescription, $strdiscussions); $generaltable->align = array ('left', 'left', 'center'); @@ -501,20 +499,15 @@ echo $OUTPUT->footer(); * @return string */ function forum_index_get_forum_subscription_selector($forum) { - global $OUTPUT; + global $OUTPUT, $PAGE; if ($forum->cansubscribe || $forum->issubscribed) { - $digestoptionsselector = new single_select(new moodle_url('/mod/forum/maildigest.php', [ - 'id' => $forum->id, - 'backtoindex' => 1, - ]), - 'maildigest', - forum_get_user_digest_options(), - $forum->maildigest !== null ? $forum->maildigest : -1, - ''); - $digestoptionsselector->method = 'post'; + if ($forum->maildigest === null) { + $forum->maildigest = -1; + } - return $OUTPUT->render($digestoptionsselector); + $renderer = $PAGE->get_renderer('mod_forum'); + return $OUTPUT->render($renderer->render_digest_options($forum, $forum->maildigest)); } else { // This user can subscribe to some forums. Add the empty fields. return ''; diff --git a/mod/forum/lang/en/deprecated.txt b/mod/forum/lang/en/deprecated.txt index 90cbb6cb7b0..619038ebe38 100644 --- a/mod/forum/lang/en/deprecated.txt +++ b/mod/forum/lang/en/deprecated.txt @@ -1,2 +1,7 @@ subscribersto,mod_forum postmailinfo,mod_forum +emaildigestupdated,mod_forum +emaildigestupdated_default,mod_forum +emaildigest_0,mod_forum +emaildigest_1,mod_forum +emaildigest_2,mod_forum diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 4804d4ed05c..e5c74595683 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -195,11 +195,6 @@ $string['emaildigesttype_help'] = 'The type of notification that you will receiv * Digest - complete posts - you will receive one digest e-mail per day containing the complete contents of each forum post; * Digest - subjects only - you will receive one digest e-mail per day containing just the subject of each forum post. '; -$string['emaildigestupdated'] = 'The e-mail digest option was changed to \'{$a->maildigesttitle}\' for the forum \'{$a->forum}\'. {$a->maildigestdescription}'; -$string['emaildigestupdated_default'] = 'Your default profile setting of \'{$a->maildigesttitle}\' was used for the forum \'{$a->forum}\'. {$a->maildigestdescription}.'; -$string['emaildigest_0'] = 'You will receive one e-mail per forum post.'; -$string['emaildigest_1'] = 'You will receive one digest e-mail per day containing the complete contents of each forum post.'; -$string['emaildigest_2'] = 'You will receive one digest e-mail per day containing the subject of each forum post.'; $string['emptymessage'] = 'Something was wrong with your post. Perhaps you left it blank, or the attachment was too big. Your changes have NOT been saved.'; $string['erroremptymessage'] = 'Post message cannot be empty'; $string['erroremptysubject'] = 'Post subject cannot be empty.'; @@ -542,3 +537,8 @@ $string['subscribersto'] = 'Subscribers to "{$a->name}"'; $string['postmailinfo'] = 'This is a copy of a message posted on the {$a} website. To reply click on this link:'; +$string['emaildigestupdated'] = 'The e-mail digest option was changed to \'{$a->maildigesttitle}\' for the forum \'{$a->forum}\'. {$a->maildigestdescription}'; +$string['emaildigestupdated_default'] = 'Your default profile setting of \'{$a->maildigesttitle}\' was used for the forum \'{$a->forum}\'. {$a->maildigestdescription}.'; +$string['emaildigest_0'] = 'You will receive one e-mail per forum post.'; +$string['emaildigest_1'] = 'You will receive one digest e-mail per day containing the complete contents of each forum post.'; +$string['emaildigest_2'] = 'You will receive one digest e-mail per day containing the subject of each forum post.'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index cb0bbbbcef9..1f6160deae2 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -7992,3 +7992,30 @@ function forum_is_author_hidden($post, $forum) { } return false; } + +/** + * Manage inplace editable saves. + * + * @param string $itemtype The type of item. + * @param int $itemid The ID of the item. + * @param mixed $newvalue The new value + * @return string + */ +function mod_forum_inplace_editable($itemtype, $itemid, $newvalue) { + global $DB, $PAGE; + + if ($itemtype === 'digestoptions') { + // The itemid is the forumid. + $forum = $DB->get_record('forum', array('id' => $itemid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST); + $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST); + $context = context_module::instance($cm->id); + + $PAGE->set_context($context); + require_login($course, false, $cm); + forum_set_user_maildigest($forum, $newvalue); + + $renderer = $PAGE->get_renderer('mod_forum'); + return $renderer->render_digest_options($forum, $newvalue); + } +} diff --git a/mod/forum/renderer.php b/mod/forum/renderer.php index 77e6b502a3c..67589f930a9 100644 --- a/mod/forum/renderer.php +++ b/mod/forum/renderer.php @@ -203,4 +203,27 @@ class mod_forum_renderer extends plugin_renderer_base { public function forum_post_template() { return 'forum_post'; } + + /** + * Create the inplace_editable used to select forum digest options. + * + * @param stdClass $forum The forum to create the editable for. + * @param int $value The current value for this user + * @return inplace_editable + */ + public function render_digest_options($forum, $value) { + $options = forum_get_user_digest_options(); + $editable = new \core\output\inplace_editable( + 'mod_forum', + 'digestoptions', + $forum->id, + true, + $options[$value], + $value + ); + + $editable->set_type_select($options); + + return $editable; + } }