From f4b571ab2bc6f316bbe6321ff83758d302b744fd Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Wed, 6 Mar 2013 16:40:07 +1100 Subject: [PATCH] MDL-37009 function print_course_search() is moved to course renderer --- course/category.php | 3 ++- course/index.php | 3 ++- course/lib.php | 44 ++++++-------------------------------------- course/manage.php | 5 +++-- course/renderer.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ course/search.php | 19 +++++-------------- index.php | 7 ++++--- 7 files changed, 67 insertions(+), 59 deletions(-) diff --git a/course/category.php b/course/category.php index 6ed18982b2273..e7f17f8e41069 100644 --- a/course/category.php +++ b/course/category.php @@ -63,10 +63,11 @@ // Begin output $PAGE->set_pagelayout('coursecategory'); +$courserenderer = $PAGE->get_renderer('core', 'course'); $site = get_site(); $PAGE->set_title("$site->shortname: $category->name"); $PAGE->set_heading($site->fullname); -$PAGE->set_button(print_course_search('', true, 'navbar')); +$PAGE->set_button($courserenderer->course_search_form('', 'navbar')); echo $OUTPUT->header(); /// Print the category selector diff --git a/course/index.php b/course/index.php index 5b3cbd21b0a1a..04c4a1af86677 100644 --- a/course/index.php +++ b/course/index.php @@ -33,6 +33,7 @@ $PAGE->set_url('/course/index.php'); $PAGE->set_context($systemcontext); $PAGE->set_pagelayout('admin'); +$courserenderer = $PAGE->get_renderer('core', 'course'); if ($CFG->forcelogin) { require_login(); @@ -59,7 +60,7 @@ echo $OUTPUT->box_start('categorybox'); print_whole_category_list(); echo $OUTPUT->box_end(); - print_course_search(); + echo $courserenderer->course_search_form(); } else { $strfulllistofcourses = get_string('fulllistofcourses'); diff --git a/course/lib.php b/course/lib.php index f906949033fe3..0e48f8973953b 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1769,46 +1769,14 @@ function print_my_moodle() { function print_course_search($value="", $return=false, $format="plain") { - global $CFG; - static $count = 0; - - $count++; - - $id = 'coursesearch'; - - if ($count > 1) { - $id .= $count; - } - - $strsearchcourses= get_string("searchcourses"); - - if ($format == 'plain') { - $output = '
'; - $output .= '
'; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= '
'; - } else if ($format == 'short') { - $output = '
'; - $output .= '
'; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= '
'; - } else if ($format == 'navbar') { - $output = '
'; - $output .= '
'; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= '
'; - } - + global $PAGE; + debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER); + $renderer = $PAGE->get_renderer('core', 'course'); if ($return) { - return $output; + return $renderer->course_search_form($value, $format); + } else { + echo $renderer->course_search_form($value, $format); } - echo $output; } function print_remote_course($course, $width="100%") { diff --git a/course/manage.php b/course/manage.php index 128e7a7a18a9a..8d54e9d29ed5e 100644 --- a/course/manage.php +++ b/course/manage.php @@ -277,6 +277,7 @@ } $PAGE->set_pagelayout('coursecategory'); +$courserenderer = $PAGE->get_renderer('core', 'course'); if (can_edit_in_category()) { // Integrate into the admin tree only if the user can edit categories at the top level, @@ -296,7 +297,7 @@ $site = get_site(); $PAGE->set_title("$site->shortname: $coursecat->name"); $PAGE->set_heading($site->fullname); - $PAGE->set_button(print_course_search('', true, 'navbar')); + $PAGE->set_button($courserenderer->course_search_form('', 'navbar')); } $displaylist[0] = get_string('top'); @@ -577,7 +578,7 @@ } echo html_writer::end_tag('div'); -print_course_search(); +echo $courserenderer->course_search_form(); echo $OUTPUT->footer(); diff --git a/course/renderer.php b/course/renderer.php index 54b3244349336..41ddb3f9a8b58 100644 --- a/course/renderer.php +++ b/course/renderer.php @@ -557,6 +557,51 @@ function course_section_add_cm_control($course, $section, $sectionreturn = null, return $output; } + /** + * 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 + */ + 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/search.php'); + + $output = html_writer::start_tag('form', array('id' => $formid, 'action' => $searchurl, 'method' => 'get')); + $output .= html_writer::start_tag('fieldset', array('class' => 'coursesearchbox invisiblefieldset')); + $output .= html_writer::tag('lavel', $strsearchcourses.': ', array('for' => $inputid)); + $output .= html_writer::empty_tag('input', array('type' => 'text', 'id' => $inputid, + 'size' => $inputsize, 'name' => 'search', 'value' => s($value))); + $output .= html_writer::empty_tag('input', array('type' => 'submit', + 'value' => get_string('go'))); + $output .= html_writer::end_tag('fieldset'); + $output .= html_writer::end_tag('form'); + + return $output; + } + /** * Renders html for completion box on course page * diff --git a/course/search.php b/course/search.php index 38bac692e8652..55e062dbc5892 100644 --- a/course/search.php +++ b/course/search.php @@ -67,6 +67,7 @@ $PAGE->set_url('/course/search.php', $urlparams); $PAGE->set_context(context_system::instance()); $PAGE->set_pagelayout('standard'); +$courserenderer = $PAGE->get_renderer('core', 'course'); if ($CFG->forcelogin) { require_login(); @@ -127,7 +128,7 @@ echo $OUTPUT->box_start(); echo "
"; echo "
"; - print_course_search("", false, "plain"); + echo $courserenderer->course_search_form('', 'plain'); echo "

"; print_string("searchhelp"); echo "

"; @@ -221,7 +222,7 @@ $aurl = new moodle_url("$CFG->wwwroot/course/search.php", $params); $searchform = $OUTPUT->single_button($aurl, $string, 'get'); } else { - $searchform = print_course_search($search, true, "navbar"); + $searchform = $courserenderer->course_search_form($search, 'navbar'); } $PAGE->navbar->add($strcourses, new moodle_url('/course/index.php')); @@ -252,17 +253,7 @@ // Show list of courses if (!$adminediting) { //Not editing mode - foreach ($courses as $course) { - // front page don't belong to any category and block can exist. - if ($course->category > 0) { - $course->summary .= "

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

"; - } - print_course($course, $search); - echo $OUTPUT->spacer(array('height'=>5, 'width'=>5, 'br'=>true)); // should be done with CSS instead - } + echo $courserenderer->courses_list($courses, $search, true); } else { // Editing mode echo "
\n"; @@ -391,7 +382,7 @@ echo "

"; -print_course_search($search); +echo $courserenderer->course_search_form($search); echo $OUTPUT->footer(); diff --git a/index.php b/index.php index 320d796179198..23423b311f447 100644 --- a/index.php +++ b/index.php @@ -95,6 +95,7 @@ $editing = $PAGE->user_is_editing(); $PAGE->set_title($SITE->fullname); $PAGE->set_heading($SITE->fullname); + $courserenderer = $PAGE->get_renderer('core', 'course'); echo $OUTPUT->header(); /// Print Section or custom info @@ -235,7 +236,7 @@ echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipavailablecourses')); } else { echo html_writer::tag('div', get_string('therearecourses', '', $ncourses), array('class' => 'notifyproblem')); - print_course_search('', false, 'short'); + echo $courserenderer->course_search_form('', 'short'); } break; @@ -249,7 +250,7 @@ echo $OUTPUT->box_start('generalbox categorybox'); print_whole_category_list(NULL, NULL, NULL, -1, false); echo $OUTPUT->box_end(); - print_course_search('', false, 'short'); + echo $courserenderer->course_search_form('', 'short'); //end frontpage category names div container echo html_writer::end_tag('div'); @@ -278,7 +279,7 @@ } else { echo $renderer->course_category_tree(get_course_category_tree()); } - print_course_search('', false, 'short'); + echo $courserenderer->course_search_form('', 'short'); //end frontpage category combo div container echo html_writer::end_tag('div');