Merge branch 'wip-mdl-30388-m22' of git://github.com/rajeshtaneja/moodle into MOODLE_22_STABLE

This commit is contained in:
Sam Hemelryk 2012-02-15 16:23:33 +13:00
commit 646704c8d0

View file

@ -42,6 +42,7 @@
} }
$PAGE->set_url('/course/search.php', $urlparams); $PAGE->set_url('/course/search.php', $urlparams);
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_pagelayout('standard');
if ($CFG->forcelogin) { if ($CFG->forcelogin) {
require_login(); require_login();
@ -73,7 +74,8 @@
} }
} }
if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM)) && $perpage != 99999) { $capabilities = array('moodle/course:create', 'moodle/category:manage');
if (has_any_capability($capabilities, get_context_instance(CONTEXT_SYSTEM)) && ($perpage != 99999)) {
$perpage = 30; $perpage = 30;
} }
@ -137,10 +139,15 @@
JOIN {block_instances} bi ON bi.parentcontextid = ctx.id JOIN {block_instances} bi ON bi.parentcontextid = ctx.id
WHERE ctx.contextlevel = " . CONTEXT_COURSE . " AND bi.blockname = ?)", WHERE ctx.contextlevel = " . CONTEXT_COURSE . " AND bi.blockname = ?)",
array($blockname)); array($blockname));
$totalcount = count($courses);
//Keep only chunk of array which you want to display
if ($totalcount > $perpage) {
$courses = array_chunk($courses, $perpage, true);
$courses = $courses[$page];
}
foreach ($courses as $course) { foreach ($courses as $course) {
$courses[$course->id] = $course; $courses[$course->id] = $course;
} }
$totalcount = count($courses);
} }
// get list of courses containing modules if required // get list of courses containing modules if required
elseif (!empty($modulelist) and confirm_sesskey()) { elseif (!empty($modulelist) and confirm_sesskey()) {
@ -180,7 +187,6 @@
if ($PAGE->user_is_editing()) { if ($PAGE->user_is_editing()) {
$string = get_string("turneditingoff"); $string = get_string("turneditingoff");
$edit = "off"; $edit = "off";
$perpage = 30;
} else { } else {
$string = get_string("turneditingon"); $string = get_string("turneditingon");
$edit = "on"; $edit = "on";
@ -212,10 +218,12 @@
echo $OUTPUT->heading("$strsearchresults: $totalcount"); echo $OUTPUT->heading("$strsearchresults: $totalcount");
$encodedsearch = urlencode($search); $encodedsearch = urlencode($search);
///add the module parameter to the paging bar if they exists // add the module/block parameter to the paging bar if they exists
$modulelink = ""; $modulelink = "";
if (!empty($modulelist) and confirm_sesskey()) { if (!empty($modulelist) and confirm_sesskey()) {
$modulelink = "&modulelist=".$modulelist."&sesskey=".sesskey(); $modulelink = "&modulelist=".$modulelist."&sesskey=".sesskey();
} else if (!empty($blocklist) and confirm_sesskey()) {
$modulelink = "&blocklist=".$blocklist."&sesskey=".sesskey();
} }
print_navigation_bar($totalcount, $page, $perpage, $encodedsearch, $modulelink); print_navigation_bar($totalcount, $page, $perpage, $encodedsearch, $modulelink);
@ -370,6 +378,17 @@
echo "<center><p>"; echo "<center><p>";
echo "<a href=\"search.php?search=$encodedsearch".$modulelink."&amp;perpage=99999\">".get_string("showall", "", $totalcount)."</a>"; echo "<a href=\"search.php?search=$encodedsearch".$modulelink."&amp;perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
echo "</p></center>"; echo "</p></center>";
} else if ($perpage === 99999) {
$defultprepage = 10;
//If user has course:create or category:manage capability the show 30 records.
$capabilities = array('moodle/course:create', 'moodle/category:manage');
if (has_any_capability($capabilities, get_context_instance(CONTEXT_SYSTEM))) {
$defultprepage = 30;
}
echo "<center><p>";
echo "<a href=\"search.php?search=$encodedsearch".$modulelink."&amp;perpage=".$defultprepage."\">".get_string("showperpage", "", $defultprepage)."</a>";
echo "</p></center>";
} }
} }