From d5593b18c2a3622493b9bfe2c5b3142ae0b0e2af Mon Sep 17 00:00:00 2001 From: Bas Brands Date: Mon, 31 Aug 2020 12:11:14 +0200 Subject: [PATCH] MDL-69454 core_search: consistent course management search --- course/classes/management_renderer.php | 59 +++++------------------- course/management.php | 4 +- course/tests/behat/course_search.feature | 8 ++-- 3 files changed, 18 insertions(+), 53 deletions(-) diff --git a/course/classes/management_renderer.php b/course/classes/management_renderer.php index 25340f849f6..3de3c7a5bbf 100644 --- a/course/classes/management_renderer.php +++ b/course/classes/management_renderer.php @@ -1291,56 +1291,19 @@ class core_course_management_renderer extends plugin_renderer_base { * Renders html to display a course search form * * @param string $value default value to populate the search field - * @param string $format display format - 'plain' (default), 'short' or 'navbar' * @return string */ - public function course_search_form($value = '', $format = 'plain') { - static $count = 0; - $formid = 'coursesearch'; - if ((++$count) > 1) { - $formid .= $count; - } - - switch ($format) { - case 'navbar' : - $formid = 'coursesearchnavbar'; - $inputid = 'navsearchbox'; - $inputsize = 20; - break; - case 'short' : - $inputid = 'shortsearchbox'; - $inputsize = 12; - break; - default : - $inputid = 'coursesearchbox'; - $inputsize = 30; - } - - $strsearchcourses = get_string("searchcourses"); - $searchurl = new moodle_url('/course/management.php'); - - $output = html_writer::start_div('row'); - $output .= html_writer::start_div('col-md-12'); - $output .= html_writer::start_tag('form', array('class' => 'card', 'id' => $formid, - 'action' => $searchurl, 'method' => 'get')); - $output .= html_writer::start_tag('fieldset', array('class' => 'coursesearchbox invisiblefieldset')); - $output .= html_writer::tag('legend', $this->output->heading($strsearchcourses.': ', 2, 'm-0'), - array('class' => 'card-header')); - $output .= html_writer::start_div('card-body'); - $output .= html_writer::start_div('input-group col-sm-6 col-lg-4 m-auto'); - $output .= html_writer::empty_tag('input', array('class' => 'form-control', 'type' => 'text', 'id' => $inputid, - 'size' => $inputsize, 'name' => 'search', 'value' => s($value), 'aria-label' => get_string('searchcourses'))); - $output .= html_writer::start_tag('span', array('class' => 'input-group-btn')); - $output .= html_writer::tag('button', get_string('go'), array('class' => 'btn btn-primary', 'type' => 'submit')); - $output .= html_writer::end_tag('span'); - $output .= html_writer::end_div(); - $output .= html_writer::end_div(); - $output .= html_writer::end_tag('fieldset'); - $output .= html_writer::end_tag('form'); - $output .= html_writer::end_div(); - $output .= html_writer::end_div(); - - return $output; + public function course_search_form($value = '') { + + $data = [ + 'action' => new moodle_url('/course/management.php'), + 'btnclass' => 'btn-primary', + 'extraclasses' => 'my-3 d-flex justify-content-center', + 'inputname' => 'search', + 'searchstring' => get_string('searchcourses'), + 'value' => $value + ]; + return $this->render_from_template('core/search_input', $data); } /** diff --git a/course/management.php b/course/management.php index 39ad5a77b7b..5afc685bb5b 100644 --- a/course/management.php +++ b/course/management.php @@ -487,6 +487,9 @@ if (count($notificationsfail) > 0) { } // Start the management form. + +echo $renderer->course_search_form($search); + echo $renderer->management_form_start(); echo $renderer->accessible_skipto_links($displaycategorylisting, $displaycourselisting, $displaycoursedetail); @@ -518,6 +521,5 @@ echo $renderer->grid_end(); // End of the management form. echo $renderer->management_form_end(); -echo $renderer->course_search_form($search); echo $renderer->footer(); diff --git a/course/tests/behat/course_search.feature b/course/tests/behat/course_search.feature index 635bc2d1d91..bd5c99c5f67 100644 --- a/course/tests/behat/course_search.feature +++ b/course/tests/behat/course_search.feature @@ -20,8 +20,8 @@ Feature: Courses can be searched for and moved in bulk. Scenario: Search courses finds correct results Given I log in as "admin" And I go to the courses management page - When I set the field "coursesearchbox" to "Biology" - And I press "Go" + When I set the field "Search" to "Biology" + And I press "Search" Then I should see "Biology Y1" And I should see "Biology Y2" And I should not see "English Y1" @@ -31,8 +31,8 @@ Feature: Courses can be searched for and moved in bulk. Scenario: Search courses and move results in bulk Given I log in as "admin" And I go to the courses management page - And I set the field "coursesearchbox" to "Biology" - And I press "Go" + And I set the field "Search" to "Biology" + And I press "Search" When I select course "Biology Y1" in the management interface And I select course "Biology Y2" in the management interface And I set the field "menumovecoursesto" to "Science" -- 2.17.1