From 81c9ff76ff7177b653616c07953a05e4f208f547 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 24 Jun 2016 10:14:20 +0200 Subject: [PATCH] Fix pagination --- main/auth/courses.php | 4 ++-- main/auth/courses_controller.php | 13 ++++++++++--- main/inc/lib/course_category.lib.php | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/main/auth/courses.php b/main/auth/courses.php index c8938f241d..ceff75e2e1 100755 --- a/main/auth/courses.php +++ b/main/auth/courses.php @@ -62,7 +62,7 @@ if (isset($_GET['action']) && in_array($_GET['action'], $actions)) { $action = Security::remove_XSS($_GET['action']); } -$categoryCode = isset($_GET['category_code']) ? $_GET['category_code'] : 'ALL'; +$categoryCode = isset($_GET['category_code']) && !empty($_GET['category_code']) ? $_GET['category_code'] : 'ALL'; $nameTools = getCourseCatalogNameTools($action); if (empty($nameTools)) { @@ -216,7 +216,7 @@ switch ($action) { if (!$user_can_view_page) { api_not_allowed(true); } - + $courses_controller->courses_categories( $action, $categoryCode, diff --git a/main/auth/courses_controller.php b/main/auth/courses_controller.php index 54d3e9bccb..50a76d2630 100755 --- a/main/auth/courses_controller.php +++ b/main/auth/courses_controller.php @@ -90,14 +90,20 @@ class CoursesController * @internal param \action $string * @internal param \Category $string code (optional) */ - public function courses_categories($action, $category_code = null, $message = '', $error = '', $content = null, $limit = array()) - { + public function courses_categories( + $action, + $category_code = null, + $message = '', + $error = '', + $content = null, + $limit = array() + ) { $data = array(); $browse_course_categories = $this->model->browse_course_categories(); $data['countCoursesInCategory'] = $this->model->count_courses_in_category($category_code); if ($action == 'display_random_courses') { // Random value is used instead limit filter - $data['browse_courses_in_category'] = $this->model->browse_courses_in_category(null, 10); + $data['browse_courses_in_category'] = $this->model->browse_courses_in_category(null, 12); $data['countCoursesInCategory'] = count($data['browse_courses_in_category']); } else { if (!isset($category_code)) { @@ -110,6 +116,7 @@ class CoursesController $data['browse_course_categories'] = $browse_course_categories; $data['code'] = Security::remove_XSS($category_code); + // getting all the courses to which the user is subscribed to $curr_user_id = api_get_user_id(); $user_courses = $this->model->get_courses_of_user($curr_user_id); diff --git a/main/inc/lib/course_category.lib.php b/main/inc/lib/course_category.lib.php index 66c62c965b..efd6d6c8ba 100755 --- a/main/inc/lib/course_category.lib.php +++ b/main/inc/lib/course_category.lib.php @@ -582,7 +582,7 @@ function browseCourseCategories() * @param string $searchTerm * @return int */ -function countCoursesInCategory($category_code="", $searchTerm = '') +function countCoursesInCategory($category_code = '', $searchTerm = '') { $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $categoryCode = Database::escape_string($category_code); @@ -628,6 +628,7 @@ function countCoursesInCategory($category_code="", $searchTerm = '') $without_special_courses $visibilityCondition "; + // Showing only the courses of the current portal access_url_id. if (api_is_multiple_url_enabled()) {