Permalink
Browse files

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

  • Loading branch information...
1 parent d8201d4 commit f4b571ab2bc6f316bbe6321ff83758d302b744fd @marinaglancy marinaglancy committed Mar 6, 2013
Showing with 67 additions and 59 deletions.
  1. +2 −1 course/category.php
  2. +2 −1 course/index.php
  3. +6 −38 course/lib.php
  4. +3 −2 course/manage.php
  5. +45 −0 course/renderer.php
  6. +5 −14 course/search.php
  7. +4 −3 index.php
View
3 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
View
3 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');
View
44 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 = '<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%") {
View
5 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();
View
45 course/renderer.php
@@ -558,6 +558,51 @@ function course_section_add_cm_control($course, $section, $sectionreturn = null,
}
/**
+ * 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
*
* If completion is disabled, returns empty string
View
19 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 "<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 @@
$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 .= "<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 @@
echo "<br /><br />";
-print_course_search($search);
+echo $courserenderer->course_search_form($search);
echo $OUTPUT->footer();
View
7 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');

0 comments on commit f4b571a

Please sign in to comment.