From 04c53106744d0623ec25513f895d3cd861e4835c Mon Sep 17 00:00:00 2001 From: tjhunt Date: Thu, 11 Dec 2008 10:47:48 +0000 Subject: [PATCH] course search: MDL-10801 Search terms were not being highlighted consistently in the results. --- course/index.php | 5 ++--- course/lib.php | 15 ++++++++++----- course/search.php | 42 +++++++++++++++--------------------------- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/course/index.php b/course/index.php index f711fa85eb..cd58288092 100644 --- a/course/index.php +++ b/course/index.php @@ -116,7 +116,7 @@ print_category_edit_header(); print_heading($heading); - if ($data->fulldelete) { + if ($datadelete) { category_delete_full($deletecat, true); } else { category_delete_move($deletecat, $data->newparent, true); @@ -232,11 +232,9 @@ echo ''; print_category_edit(NULL, $displaylist, $parentlist); - echo ''; echo '
'; - if (has_capability('moodle/course:create', $systemcontext)) { // print create course link to first category $options = array(); @@ -252,6 +250,7 @@ } print_course_request_buttons($systemcontext); + echo '
'; admin_externalpage_print_footer(); diff --git a/course/lib.php b/course/lib.php index a3b1bc4b33..22b4036411 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2077,8 +2077,13 @@ function print_courses($category) { } } - -function print_course($course) { +/** + * Print a description of a course, suitable for browsing in a list. + * + * @param object $course the course object. + * @param string $highlightterms (optional) some search terms that should be highlighted in the display. + */ +function print_course($course, $highlightterms = '') { global $CFG, $USER, $DB; if (isset($course->context)) { @@ -2093,7 +2098,7 @@ function print_course($course) { echo '
'; echo ''; + highlight($highlightterms, format_string($course->fullname)).'
'; /// first find all roles that are supposed to be displayed @@ -2180,7 +2185,7 @@ function print_course($course) { $options = NULL; $options->noclean = true; $options->para = false; - echo format_text($course->summary, FORMAT_MOODLE, $options, $course->id); + echo highlight($highlightterms, format_text($course->summary, FORMAT_MOODLE, $options, $course->id)); echo ''; echo ''; } @@ -2213,7 +2218,7 @@ function print_my_moodle() { continue; } echo '
  • '; - print_course($course, "100%"); + print_course($course); echo "
  • \n"; } echo "\n"; diff --git a/course/search.php b/course/search.php index 0abf631fd7..299bb1400f 100644 --- a/course/search.php +++ b/course/search.php @@ -33,22 +33,18 @@ require_login(); } - if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM))) { + if (update_category_button()) { if ($edit !== -1) { $USER->categoryediting = $edit; - // If the edit mode we are leaving has higher per page than the one we are entering, - // with pages, chances are you will get a no courses found error. So when we are switching - // modes, set page to 0. - $page = 0; } + $adminediting = !empty($USER->categoryediting); + } else { + $adminediting = false; } /// Editing functions - if (has_capability('moodle/course:visibility', get_context_instance(CONTEXT_SYSTEM))) { - /// Hide or show a course - if ($hide or $show and confirm_sesskey()) { if ($hide) { $course = $DB->get_record("course", array("id"=>$hide)); @@ -63,7 +59,6 @@ } } } - } if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM)) && $perpage != 99999) { @@ -106,7 +101,6 @@ } if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) { // Some courses are being moved - if (! $destcategory = $DB->get_record("course_categories", array("id"=>$data->moveto))) { print_error('cannotfindcategory', '', '', $data->moveto); } @@ -168,7 +162,7 @@ } } else { - $courses = get_courses_search($searchterms, "fullname ASC", + $courses = get_courses_search($searchterms, "fullname ASC", $page, $perpage, $totalcount); } @@ -186,35 +180,30 @@ print_header("$site->fullname : $strsearchresults", $site->fullname, $navigation, "", "", "", $searchform); - $lastcategory = -1; if ($courses) { - print_heading("$strsearchresults: $totalcount"); - $encodedsearch = urlencode($search); - + ///add the module parameter to the paging bar if they exists $modulelink = ""; if (!empty($modulelist) and confirm_sesskey()) { $modulelink = "&modulelist=".$modulelist."&sesskey=".$USER->sesskey; } - - print_navigation_bar($totalcount,$page,$perpage,$encodedsearch,$modulelink); - if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { + print_navigation_bar($totalcount, $page, $perpage, $encodedsearch, $modulelink); + + if (!$adminediting) { foreach ($courses as $course) { - $course->fullname = highlight(trim($search, '+'), $course->fullname); - $course->summary = highlight(trim($search, '+'), $course->summary); $course->summary .= "

    "; $course->summary .= "$strcategory: category\">"; $course->summary .= $displaylist[$course->category]; $course->summary .= "

    "; - print_course($course); + print_course($course, $search); print_spacer(5,5); } - } else { // slightly more sophisticated - + } else { + /// Show editing UI. echo "
    \n"; echo "
    sesskey\" />\n"; echo "\n"; @@ -226,15 +215,14 @@ echo "$strselect\n"; echo "$stredit\n"; - foreach ($courses as $course) { - + foreach ($courses as $course) { + if (isset($course->context)) { $coursecontext = $course->context; } else { $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); } - $course->fullname = highlight(trim($search, '+'), $course->fullname); $linkcss = $course->visible ? "" : " class=\"dimmed\" "; // are we displaying the front page (courseid=1)? @@ -252,7 +240,7 @@ echo "\n"; echo "id\">" - . format_string($course->fullname) . "\n"; + . highlight($search, format_string($course->fullname)) . "\n"; echo "".$displaylist[$course->category]."\n"; echo "\n"; -- 2.39.5