Skip to content

Commit

Permalink
MDL-69454 core_search: consistent course management search
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas Brands committed Sep 21, 2020
1 parent 968cd48 commit d5593b1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 53 deletions.
59 changes: 11 additions & 48 deletions course/classes/management_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1291,56 +1291,19 @@ public function search_listitem_actions(core_course_list_element $course) {
* 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);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion course/management.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@
}

// Start the management form.

echo $renderer->course_search_form($search);

echo $renderer->management_form_start();

echo $renderer->accessible_skipto_links($displaycategorylisting, $displaycourselisting, $displaycoursedetail);
Expand Down Expand Up @@ -518,6 +521,5 @@

// End of the management form.
echo $renderer->management_form_end();
echo $renderer->course_search_form($search);

echo $renderer->footer();
8 changes: 4 additions & 4 deletions course/tests/behat/course_search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit d5593b1

Please sign in to comment.