Split get-courses_page from get-courses so they can specialise
This commit is contained in:
+1
-3
@@ -213,14 +213,12 @@
|
||||
|
||||
/// Print out all the courses
|
||||
|
||||
if (!$courses = get_courses($category->id, "c.sortorder ASC", "c.*", $totalcount, $page*$perpage, $perpage)) {
|
||||
if (!$courses = get_course_pages($category->id, "c.sortorder ASC", "c.*", $totalcount, $page*$perpage, $perpage)) {
|
||||
print_heading(get_string("nocoursesyet"));
|
||||
|
||||
} else {
|
||||
|
||||
echo "<center>";
|
||||
print_paging_bar($totalcount, $page, $perpage, "category.php?id=$category->id&perpage=$perpage&");
|
||||
echo "</center>";
|
||||
|
||||
$strcourses = get_string("courses");
|
||||
$strselect = get_string("select");
|
||||
|
||||
@@ -66,9 +66,7 @@
|
||||
|
||||
print_heading("$strsearchresults: $totalcount");
|
||||
|
||||
echo "<center>";
|
||||
print_paging_bar($totalcount, $page, $perpage, "search.php?search=$search&perpage=$perpage&");
|
||||
echo "</center>";
|
||||
|
||||
foreach ($courses as $course) {
|
||||
$course->fullname = highlight("$search", $course->fullname);
|
||||
@@ -81,9 +79,7 @@
|
||||
print_spacer(5,5);
|
||||
}
|
||||
|
||||
echo "<center>";
|
||||
print_paging_bar($totalcount, $page, $perpage, "search.php?search=$search&perpage=$perpage&");
|
||||
echo "</center>";
|
||||
|
||||
} else {
|
||||
print_heading(get_string("nocoursesfound", "", $search));
|
||||
|
||||
+32
-2
@@ -1108,8 +1108,7 @@ function get_site () {
|
||||
}
|
||||
|
||||
|
||||
function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*",
|
||||
&$totalcount, $limitfrom="", $limitnum="") {
|
||||
function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*") {
|
||||
/// Returns list of courses, for whole site, or category
|
||||
|
||||
global $USER, $CFG;
|
||||
@@ -1132,6 +1131,37 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*",
|
||||
$visiblecourses = "AND c.visible > 0";
|
||||
}
|
||||
|
||||
$selectsql = "{$CFG->prefix}course c $teachertable WHERE $categoryselect $visiblecourses";
|
||||
|
||||
return get_records_sql("SELECT $fields FROM $selectsql $teachergroup ORDER BY $sort");
|
||||
}
|
||||
|
||||
|
||||
function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c.*",
|
||||
&$totalcount, $limitfrom="", $limitnum="") {
|
||||
/// Returns list of courses, for whole site, or category
|
||||
/// Similar to get_courses, but allows paging
|
||||
|
||||
global $USER, $CFG;
|
||||
|
||||
$categoryselect = "";
|
||||
if ($categoryid != "all") {
|
||||
$categoryselect = "c.category = '$categoryid'";
|
||||
}
|
||||
|
||||
$teachertable = "";
|
||||
$teachergroup = "";
|
||||
$visiblecourses = "";
|
||||
if (!empty($USER)) { // May need to check they are a teacher
|
||||
if (!isadmin()) {
|
||||
$visiblecourses = "AND ((c.visible > 0) OR (t.userid = '$USER->id' AND t.course = c.id))";
|
||||
$teachertable = ", {$CFG->prefix}user_teachers t";
|
||||
$teachergroup = "GROUP BY c.id";
|
||||
}
|
||||
} else {
|
||||
$visiblecourses = "AND c.visible > 0";
|
||||
}
|
||||
|
||||
if ($limitfrom !== "") {
|
||||
switch ($CFG->dbtype) {
|
||||
case "mysql":
|
||||
|
||||
Reference in New Issue
Block a user