Skip to content

Commit

Permalink
MDL-37009 function print_course_search() is moved to course renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Apr 1, 2013
1 parent d8201d4 commit f4b571a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 59 deletions.
3 changes: 2 additions & 1 deletion course/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion course/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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');

Expand Down
44 changes: 6 additions & 38 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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%") {
Expand Down
5 changes: 3 additions & 2 deletions course/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
Expand Down Expand Up @@ -577,7 +578,7 @@
}
echo html_writer::end_tag('div');

print_course_search();
echo $courserenderer->course_search_form();

echo $OUTPUT->footer();

Expand Down
45 changes: 45 additions & 0 deletions course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
19 changes: 5 additions & 14 deletions course/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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>";
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -391,7 +382,7 @@

echo "<br /><br />";

print_course_search($search);
echo $courserenderer->course_search_form($search);

echo $OUTPUT->footer();

Expand Down
7 changes: 4 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit f4b571a

Please sign in to comment.