MDL-31640 course search: Coding style clean up

This commit is contained in:
Sam Hemelryk 2012-03-21 09:49:38 +13:00
parent 1a381535e6
commit f520dcd9ba

View file

@ -1,9 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/// Displays external information about a course
/**
* Displays external information about a course
* @package core
* @category course
* @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../config.php");
require_once("lib.php");
require_once($CFG->dirroot.'/course/lib.php');
$search = optional_param('search', '', PARAM_RAW); // search words
$page = optional_param('page', 0, PARAM_INT); // which page to show
@ -57,7 +77,7 @@
require_login();
}
//Editing is possible if user have system or category level create and manage capability
// Editing is possible if user has system or category level create and manage capability
if (can_edit_in_category() || !empty($usercatlist)) {
if ($edit !== -1) {
$USER->editing = $edit;
@ -72,10 +92,10 @@
$adminediting = false;
}
/// Editing functions
// Editing functions
if (has_capability('moodle/course:visibility', context_system::instance())) {
/// Hide or show a course
if ($hide or $show and confirm_sesskey()) {
// Hide or show a course
if (($hide || $show) && confirm_sesskey()) {
if ($hide) {
$course = $DB->get_record("course", array("id" => $hide));
$visible = 0;
@ -93,16 +113,16 @@
$parentlist = array();
make_categories_list($displaylist, $parentlist);
$strcourses = get_string("courses");
$strsearch = get_string("search");
$strsearchresults = get_string("searchresults");
$strcategory = get_string("category");
$strselect = get_string("select");
$strselectall = get_string("selectall");
$strdeselectall = get_string("deselectall");
$stredit = get_string("edit");
$strfrontpage = get_string('frontpage', 'admin');
$strnovalidcourses = get_string('novalidcourses');
$strcourses = new lang_string("courses");
$strsearch = new lang_string("search");
$strsearchresults = new lang_string("searchresults");
$strcategory = new lang_string("category");
$strselect = new lang_string("select");
$strselectall = new lang_string("selectall");
$strdeselectall = new lang_string("deselectall");
$stredit = new lang_string("edit");
$strfrontpage = new lang_string('frontpage', 'admin');
$strnovalidcourses = new lang_string('novalidcourses');
if (empty($search) and empty($blocklist) and empty($modulelist) and empty($moveto) and ($edit != -1)) {
$PAGE->navbar->add($strcourses, new moodle_url('/course/index.php'));
@ -140,6 +160,9 @@
// user must have category:manage and course:create capability for the course to be moved.
$coursecontext = context_course::instance($courseid);
foreach ($capabilities as $capability) {
// Require capability here will result in a fatal error should the user not
// have the requried category ensuring that no moves occur if they are
// trying to move multiple courses.
require_capability($capability, $coursecontext);
array_push($courses, $courseid);
}
@ -190,19 +213,19 @@
else {
$totalcount = 0;
}
} else if (!empty($searchterm)) { //Donot do search for empty search request.
$courses = get_courses_search($searchterms, "fullname ASC",
$page, $perpage, $totalcount);
} else if (!empty($searchterm)) {
// Donot do search for empty search request.
$courses = get_courses_search($searchterms, "fullname ASC", $page, $perpage, $totalcount);
}
$searchform = '';
// Turn editing should be visible if user have system or category level capability
if (!empty($courses) && (can_edit_in_category() || !empty($usercatlist))) {
if ($PAGE->user_is_editing()) {
$string = get_string("turneditingoff");
$string = new lang_string("turneditingoff");
$edit = "off";
} else {
$string = get_string("turneditingon");
$string = new lang_string("turneditingon");
$edit = "on";
}
$params = array_merge($urlparams, array('sesskey' => sesskey(), 'edit' => $edit));
@ -251,7 +274,8 @@
print_course($course, $search);
echo $OUTPUT->spacer(array('height'=>5, 'width'=>5, 'br'=>true)); // should be done with CSS instead
}
} else { //editing mode
} else {
// Editing mode
echo "<form id=\"movecourses\" action=\"search.php\" method=\"post\">\n";
echo "<div><input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n";
echo "<input type=\"hidden\" name=\"search\" value=\"".s($search)."\" />\n";
@ -380,11 +404,11 @@
/**
* Print a list navigation bar
* Display page numbers, and a link for displaying all entries
* @param integer $totalcount - number of entry to display
* @param integer $page - page number
* @param integer $perpage - number of entry per page
* @param int $totalcount number of entry to display
* @param int $page page number
* @param int $perpage number of entry per page
* @param string $encodedsearch
* @param string $modulelink - module name
* @param string $modulelink module name
*/
function print_navigation_bar($totalcount, $page, $perpage, $encodedsearch, $modulelink) {
global $OUTPUT;
@ -408,5 +432,3 @@
echo "</p></center>";
}
}