From 270dd87113da2ed6a3f1ac1e3e63b1b38cc446fc Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Fri, 5 Aug 2016 12:35:15 +0800 Subject: [PATCH] MDL-55474 block_search_forums: Convert search form to templates Part of MDL-55071 --- blocks/search_forums/block_search_forums.php | 18 +---- .../search_forums/classes/output/renderer.php | 50 +++++++++++++ .../classes/output/search_form.php | 74 +++++++++++++++++++ .../templates/search_form.mustache | 15 ++++ theme/noname/scss/moodle/blocks.scss | 5 ++ .../block_search_forums/search_form.mustache | 17 +++++ 6 files changed, 164 insertions(+), 15 deletions(-) create mode 100644 blocks/search_forums/classes/output/renderer.php create mode 100644 blocks/search_forums/classes/output/search_form.php create mode 100644 blocks/search_forums/templates/search_form.mustache create mode 100644 theme/noname/templates/block_search_forums/search_form.mustache diff --git a/blocks/search_forums/block_search_forums.php b/blocks/search_forums/block_search_forums.php index 2bf7d6c1bf0..669d5e8ca2b 100644 --- a/blocks/search_forums/block_search_forums.php +++ b/blocks/search_forums/block_search_forums.php @@ -42,21 +42,9 @@ class block_search_forums extends block_base { return $this->content; } - $advancedsearch = get_string('advancedsearch', 'block_search_forums'); - - $strsearch = get_string('search'); - $strgo = get_string('go'); - - $this->content->text = '
'; - $this->content->text .= '
'; - $this->content->text .= ''.$strsearch.''; - $this->content->text .= ''; // course - $this->content->text .= ''. - ''; - $this->content->text .= '
'; - $this->content->text .= ''.$advancedsearch.''; - $this->content->text .= $OUTPUT->help_icon('search'); - $this->content->text .= '
'; + $output = $this->page->get_renderer('block_search_forums'); + $searchform = new \block_search_forums\output\search_form($this->page->course->id); + $this->content->text = $output->render($searchform); return $this->content; } diff --git a/blocks/search_forums/classes/output/renderer.php b/blocks/search_forums/classes/output/renderer.php new file mode 100644 index 00000000000..292ce347392 --- /dev/null +++ b/blocks/search_forums/classes/output/renderer.php @@ -0,0 +1,50 @@ +. + +/** + * Block search forums renderer. + * + * @package block_search_forums + * @copyright 2016 Frédéric Massart - FMCorz.net + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_search_forums\output; +defined('MOODLE_INTERNAL') || die(); + +use plugin_renderer_base; +use renderable; + +/** + * Block search forums renderer. + * + * @package block_search_forums + * @copyright 2016 Frédéric Massart - FMCorz.net + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class renderer extends plugin_renderer_base { + + /** + * Render search form. + * + * @param renderable $searchform The search form. + * @return string + */ + public function render_search_form(renderable $searchform) { + return $this->render_from_template('block_search_forums/search_form', $searchform->export_for_template($this)); + } + +} diff --git a/blocks/search_forums/classes/output/search_form.php b/blocks/search_forums/classes/output/search_form.php new file mode 100644 index 00000000000..8213abe987f --- /dev/null +++ b/blocks/search_forums/classes/output/search_form.php @@ -0,0 +1,74 @@ +. + +/** + * Search form renderable. + * + * @package block_search_forums + * @copyright 2016 Frédéric Massart - FMCorz.net + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_search_forums\output; +defined('MOODLE_INTERNAL') || die(); + +use help_icon; +use moodle_url; +use renderable; +use renderer_base; +use templatable; + +/** + * Search form renderable class. + * + * @package block_search_forums + * @copyright 2016 Frédéric Massart - FMCorz.net + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class search_form implements renderable, templatable { + + /** @var int The course ID. */ + protected $courseid; + /** @var moodle_url The form action URL. */ + protected $actionurl; + /** @var moodle_url The advanced search URL. */ + protected $advancedsearchurl; + /** @var help_icon The help icon. */ + protected $helpicon; + + /** + * Constructor. + * + * @param int $courseid The course ID. + */ + public function __construct($courseid) { + $this->courseid = $courseid; + $this->actionurl = new moodle_url('/mod/forum/search.php'); + $this->advancedsearchurl = new moodle_url('/mod/forum/search.php', ['id' => $this->courseid]); + $this->helpicon = new help_icon('search', 'core'); + } + + public function export_for_template(renderer_base $output) { + $data = [ + 'actionurl' => $this->actionurl->out(false), + 'courseid' => $this->courseid, + 'advancedsearchurl' => $this->advancedsearchurl->out(false), + 'helpicon' => $this->helpicon->export_for_template($output), + ]; + return $data; + } + +} diff --git a/blocks/search_forums/templates/search_form.mustache b/blocks/search_forums/templates/search_form.mustache new file mode 100644 index 00000000000..9f0411f51b8 --- /dev/null +++ b/blocks/search_forums/templates/search_form.mustache @@ -0,0 +1,15 @@ +
+
+
+ {{#str}}search{{/str}} + + + +
+ {{#str}}advancedsearch, block_search_forums{{/str}} + {{#helpicon}} + {{>core/help_icon}} + {{/helpicon}} +
+
+
diff --git a/theme/noname/scss/moodle/blocks.scss b/theme/noname/scss/moodle/blocks.scss index 0a2e0b7ea19..81a3ca55a8b 100644 --- a/theme/noname/scss/moodle/blocks.scss +++ b/theme/noname/scss/moodle/blocks.scss @@ -2,3 +2,8 @@ position: relative; left: initial; } + +.block_search_forums .searchform { + /* Override plugin's default. */ + text-align: left; +} diff --git a/theme/noname/templates/block_search_forums/search_form.mustache b/theme/noname/templates/block_search_forums/search_form.mustache new file mode 100644 index 00000000000..f34e895ff62 --- /dev/null +++ b/theme/noname/templates/block_search_forums/search_form.mustache @@ -0,0 +1,17 @@ +
+
+ +
+ + +
+ + +
+
+ {{#str}}advancedsearch, block_search_forums{{/str}} + {{#helpicon}} + {{>core/help_icon}} + {{/helpicon}} +
+
-- 2.43.0