MDL-57660 mod_forum: Preserve forum ID selection after form submission
authorJun Pataleta <jun@moodle.com>
Mon, 16 Jan 2017 08:02:36 +0000 (16:02 +0800)
committerJun Pataleta <jun@moodle.com>
Fri, 27 Jan 2017 02:09:37 +0000 (10:09 +0800)
mod/forum/classes/output/big_search_form.php
mod/forum/search.php
mod/forum/templates/big_search_form.mustache
theme/boost/templates/mod_forum/big_search_form.mustache

index 6a77898..8145103 100644 (file)
@@ -148,6 +148,15 @@ class big_search_form implements renderable, templatable {
         $this->words = $value;
     }
 
         $this->words = $value;
     }
 
+    /**
+     * Forum ID setter search criteria.
+     *
+     * @param int $forumid The forum ID.
+     */
+    public function set_forumid($forumid) {
+        $this->forumid = $forumid;
+    }
+
     public function export_for_template(renderer_base $output) {
         $data = new stdClass();
 
     public function export_for_template(renderer_base $output) {
         $data = new stdClass();
 
@@ -185,6 +194,15 @@ class big_search_form implements renderable, templatable {
                             . html_writer::select_time('hours', 'tohour', $dateto)
                             . html_writer::select_time('minutes', 'tominute', $dateto);
 
                             . html_writer::select_time('hours', 'tohour', $dateto)
                             . html_writer::select_time('minutes', 'tominute', $dateto);
 
+        if ($this->forumid && !empty($this->forumoptions)) {
+            foreach ($this->forumoptions as $index => $option) {
+                if ($option['value'] == $this->forumid) {
+                    $this->forumoptions[$index]['selected'] = true;
+                } else {
+                    $this->forumoptions[$index]['selected'] = false;
+                }
+            }
+        }
         $data->forumoptions = $this->forumoptions;
 
         return $data;
         $data->forumoptions = $this->forumoptions;
 
         return $data;
index 931d045..ec399f9 100644 (file)
@@ -318,7 +318,7 @@ echo $OUTPUT->footer();
   * @return void The function prints the form.
   */
 function forum_print_big_search_form($course) {
   * @return void The function prints the form.
   */
 function forum_print_big_search_form($course) {
-    global $PAGE, $words, $subject, $phrase, $user, $userid, $fullwords, $notwords, $datefrom, $dateto, $OUTPUT;
+    global $PAGE, $words, $subject, $phrase, $user, $fullwords, $notwords, $datefrom, $dateto, $forumid;
 
     $renderable = new \mod_forum\output\big_search_form($course, $user);
     $renderable->set_words($words);
 
     $renderable = new \mod_forum\output\big_search_form($course, $user);
     $renderable->set_words($words);
@@ -329,6 +329,7 @@ function forum_print_big_search_form($course) {
     $renderable->set_dateto($dateto);
     $renderable->set_subject($subject);
     $renderable->set_user($user);
     $renderable->set_dateto($dateto);
     $renderable->set_subject($subject);
     $renderable->set_user($user);
+    $renderable->set_forumid($forumid);
 
     $output = $PAGE->get_renderer('mod_forum');
     echo $output->render($renderable);
 
     $output = $PAGE->get_renderer('mod_forum');
     echo $output->render($renderable);
index 6fc760c..f9371f2 100644 (file)
                 <td class="c1">
                     <select name="forumid" id="menuforumid">
                         {{#forumoptions}}
                 <td class="c1">
                     <select name="forumid" id="menuforumid">
                         {{#forumoptions}}
-                            <option value="{{value}}">{{name}}</option>
+                            <option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
                         {{/forumoptions}}
                     </select>
                 </td>
                         {{/forumoptions}}
                     </select>
                 </td>
index c376145..241d842 100644 (file)
                 <td class="c1">
                     <select name="forumid" id="menuforumid" class="form-control">
                         {{#forumoptions}}
                 <td class="c1">
                     <select name="forumid" id="menuforumid" class="form-control">
                         {{#forumoptions}}
-                            <option value="{{value}}">{{name}}</option>
+                            <option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
                         {{/forumoptions}}
                     </select>
                 </td>
                         {{/forumoptions}}
                     </select>
                 </td>