mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 01:46:45 +02:00
MDL-37009 Display course search results using new renderer methods
This commit is contained in:
parent
837d548eb2
commit
6004700329
2 changed files with 85 additions and 97 deletions
|
@ -72,109 +72,30 @@ $strsearch = new lang_string("search");
|
|||
$strsearchresults = new lang_string("searchresults");
|
||||
$strnovalidcourses = new lang_string('novalidcourses');
|
||||
|
||||
if (empty($searchcriteria)) {
|
||||
// no search criteria specified, print page with just search form
|
||||
$PAGE->navbar->add($strcourses, new moodle_url('/course/index.php'));
|
||||
$PAGE->navbar->add($strsearch);
|
||||
$PAGE->set_title("$site->fullname : $strsearch");
|
||||
$PAGE->set_heading($site->fullname);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->box_start();
|
||||
echo "<center>";
|
||||
echo "<br />";
|
||||
echo $courserenderer->course_search_form('', 'plain');
|
||||
echo "<br /><p>";
|
||||
print_string("searchhelp");
|
||||
echo "</p>";
|
||||
echo "</center>";
|
||||
echo $OUTPUT->box_end();
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// get list of courses
|
||||
$searchoptions = array('recursive' => true, 'sort' => array('fullname' => 1));
|
||||
if ($perpage !== 'all') {
|
||||
$searchoptions['offset'] = $page * $perpage;
|
||||
$searchoptions['limit'] = $perpage;
|
||||
}
|
||||
$courses = coursecat::get(0)->search_courses($searchcriteria, $searchoptions);
|
||||
$totalcount = coursecat::get(0)->search_courses_count($searchcriteria, $searchoptions);
|
||||
|
||||
$searchform = '';
|
||||
// Turn editing should be visible if user have system or category level capability
|
||||
if (!empty($courses) && (can_edit_in_category() || !empty($usercatlist))) {
|
||||
$aurl = new moodle_url('/course/manage.php', $searchcriteria);
|
||||
$searchform = $OUTPUT->single_button($aurl, get_string('managecourses'), 'get');
|
||||
} else {
|
||||
$searchform = $courserenderer->course_search_form($search, 'navbar');
|
||||
}
|
||||
|
||||
$PAGE->navbar->add($strcourses, new moodle_url('/course/index.php'));
|
||||
$PAGE->navbar->add($strsearch, new moodle_url('/course/search.php'));
|
||||
if (!empty($search)) {
|
||||
$PAGE->navbar->add(s($search));
|
||||
}
|
||||
$PAGE->set_title("$site->fullname : $strsearchresults");
|
||||
|
||||
if (empty($searchcriteria)) {
|
||||
// no search criteria specified, print page with just search form
|
||||
$PAGE->set_title("$site->fullname : $strsearch");
|
||||
} else {
|
||||
// this is search results page
|
||||
$PAGE->set_title("$site->fullname : $strsearchresults");
|
||||
// Link to manage search results should be visible if user have system or category level capability
|
||||
if ((can_edit_in_category() || !empty($usercatlist))) {
|
||||
$aurl = new moodle_url('/course/manage.php', $searchcriteria);
|
||||
$searchform = $OUTPUT->single_button($aurl, get_string('managecourses'), 'get');
|
||||
} else {
|
||||
$searchform = $courserenderer->course_search_form($search, 'navbar');
|
||||
}
|
||||
$PAGE->set_button($searchform);
|
||||
}
|
||||
|
||||
$PAGE->set_heading($site->fullname);
|
||||
$PAGE->set_button($searchform);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if ($courses) {
|
||||
echo $OUTPUT->heading("$strsearchresults: $totalcount");
|
||||
|
||||
// add the module/block parameter to the paging bar if they exists
|
||||
$modulelink = "";
|
||||
if (!empty($modulelist) and confirm_sesskey()) {
|
||||
$modulelink = "&modulelist=".$modulelist."&sesskey=".sesskey();
|
||||
} else if (!empty($blocklist) and confirm_sesskey()) {
|
||||
$modulelink = "&blocklist=".$blocklist."&sesskey=".sesskey();
|
||||
}
|
||||
|
||||
print_navigation_bar($totalcount, $page, $perpage, $searchcriteria);
|
||||
|
||||
// Show list of courses
|
||||
echo $courserenderer->courses_list($courses, $search, true);
|
||||
|
||||
print_navigation_bar($totalcount, $page, $perpage, $searchcriteria);
|
||||
|
||||
} else {
|
||||
if (!empty($search)) {
|
||||
echo $OUTPUT->heading(get_string("nocoursesfound",'', s($search)));
|
||||
}
|
||||
else {
|
||||
echo $OUTPUT->heading($strnovalidcourses);
|
||||
}
|
||||
}
|
||||
|
||||
echo "<br /><br />";
|
||||
|
||||
echo $courserenderer->course_search_form($search);
|
||||
|
||||
echo $courserenderer->search_courses($searchcriteria);
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
/**
|
||||
* Print a list navigation bar
|
||||
* Display page numbers, and a link for displaying all entries
|
||||
* @param int $totalcount number of entry to display
|
||||
* @param int $page page number
|
||||
* @param int $perpage number of entry per page
|
||||
* @param array $search
|
||||
*/
|
||||
function print_navigation_bar($totalcount, $page, $perpage, $search) {
|
||||
global $OUTPUT, $CFG;
|
||||
$url = new moodle_url('/course/search.php', $search);
|
||||
if ($perpage !== 'all' && $totalcount > $perpage) {
|
||||
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, $url->out(false, array('perpage' => $perpage)));
|
||||
echo "<center><p>";
|
||||
echo html_writer::link($url->out(false, array('perpage' => 'all')), get_string("showall", "", $totalcount));
|
||||
echo "</p></center>";
|
||||
} else if ($perpage === 'all') {
|
||||
echo "<center><p>";
|
||||
echo html_writer::link($url->out(false, array('perpage' => $CFG->coursesperpage)),
|
||||
get_string("showperpage", "", $CFG->coursesperpage));
|
||||
echo "</p></center>";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue