MDL-37009 function print_course_search() is moved to course renderer

This commit is contained in:
Marina Glancy
2013-04-02 10:54:48 +11:00
parent d8201d49d8
commit f4b571ab2b
7 changed files with 67 additions and 59 deletions
+2 -1
View File
@@ -63,10 +63,11 @@ if ($perpage) {
// 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
+2 -1
View File
@@ -33,6 +33,7 @@ $systemcontext = context_system::instance();
$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 @@ if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course
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');
+6 -38
View File
@@ -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 = '<form id="'.$id.'" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
$output .= '<fieldset class="coursesearchbox invisiblefieldset">';
$output .= '<label for="coursesearchbox">'.$strsearchcourses.': </label>';
$output .= '<input type="text" id="coursesearchbox" size="30" name="search" value="'.s($value).'" />';
$output .= '<input type="submit" value="'.get_string('go').'" />';
$output .= '</fieldset></form>';
} else if ($format == 'short') {
$output = '<form id="'.$id.'" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
$output .= '<fieldset class="coursesearchbox invisiblefieldset">';
$output .= '<label for="shortsearchbox">'.$strsearchcourses.': </label>';
$output .= '<input type="text" id="shortsearchbox" size="12" name="search" value="'.s($value).'" />';
$output .= '<input type="submit" value="'.get_string('go').'" />';
$output .= '</fieldset></form>';
} else if ($format == 'navbar') {
$output = '<form id="coursesearchnavbar" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
$output .= '<fieldset class="coursesearchbox invisiblefieldset">';
$output .= '<label for="navsearchbox">'.$strsearchcourses.': </label>';
$output .= '<input type="text" id="navsearchbox" size="20" name="search" value="'.s($value).'" />';
$output .= '<input type="submit" value="'.get_string('go').'" />';
$output .= '</fieldset></form>';
}
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%") {
+3 -2
View File
@@ -277,6 +277,7 @@ if ($perpage) {
}
$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 @@ if (can_edit_in_category()) {
$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 @@ if (!empty($CFG->enablecourserequests) && $id == $CFG->defaultrequestcategory) {
}
echo html_writer::end_tag('div');
print_course_search();
echo $courserenderer->course_search_form();
echo $OUTPUT->footer();
+45
View File
@@ -557,6 +557,51 @@ class core_course_renderer extends plugin_renderer_base {
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
*
+5 -14
View File
@@ -67,6 +67,7 @@ if ($perpage != 10) {
$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 @@ if (empty($search) and empty($blocklist) and empty($modulelist) and empty($movet
echo $OUTPUT->box_start();
echo "<center>";
echo "<br />";
print_course_search("", false, "plain");
echo $courserenderer->course_search_form('', 'plain');
echo "<br /><p>";
print_string("searchhelp");
echo "</p>";
@@ -221,7 +222,7 @@ if (!empty($courses) && (can_edit_in_category() || !empty($usercatlist))) {
$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 @@ if ($courses) {
// 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 .= "<br /><p class=\"category\">";
$course->summary .= "$strcategory: <a href=\"category.php?id=$course->category\">";
$course->summary .= $displaylist[$course->category];
$course->summary .= "</a></p>";
}
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 "<form id=\"movecourses\" action=\"search.php\" method=\"post\">\n";
@@ -391,7 +382,7 @@ if ($courses) {
echo "<br /><br />";
print_course_search($search);
echo $courserenderer->course_search_form($search);
echo $OUTPUT->footer();
+4 -3
View File
@@ -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');