From 220539616a91c957df649b5f2396bc6b3443644b Mon Sep 17 00:00:00 2001 From: Daniel Barreto Date: Fri, 17 Oct 2014 11:04:41 -0500 Subject: [PATCH] Update Improve documentation, Delete unused function - refs #7273 --- main/auth/courses_controller.php | 33 +++++-------------- main/inc/lib/auth.lib.php | 3 +- main/inc/lib/course_category.lib.php | 33 +++++++++++++++---- .../default/auth/courses_categories.php | 4 ++- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/main/auth/courses_controller.php b/main/auth/courses_controller.php index 4eea3b01d9..716752daa7 100755 --- a/main/auth/courses_controller.php +++ b/main/auth/courses_controller.php @@ -76,10 +76,10 @@ class CoursesController * It's used for listing courses with categories, * render to courses_categories view * @param $action - * @param null $category_code + * @param string $category_code * @param string $message * @param string $error - * @param null $content + * @param string $content * @param array $limit will be used if $random_value is not set. * This array should contains 'start' and 'length' keys * @internal param \action $string @@ -100,6 +100,7 @@ class CoursesController if (!isset($category_code)) { $category_code = $browse_course_categories[0][1]['code']; // by default first category } + $limit = isset($limit) ? $limit : getLimitArray(); $data['browse_courses_in_category'] = $this->model->browse_courses_in_category($category_code, null, $limit); } @@ -515,16 +516,6 @@ class CoursesController return Display::return_icon('window_list.png', $sessionName, null, ICON_SIZE_LARGE); } - /** - * @param string $courseCategory - * @param string $searchTerm - * @return int - */ - public function getCountCourses($courseCategory = '', $searchTerm = '') - { - return countCoursesInCategory($courseCategory, $searchTerm); - } - /** * Return Session Catalogue rendered view * @param string $action @@ -535,28 +526,22 @@ class CoursesController { $date = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d'); $hiddenLinks = isset($_GET['hidden_links']) ? intval($_GET['hidden_links']) == 1 : false; - if ( - !empty($limit) && - is_array($limit) && - isset($limit['start']) && - isset($limit['current']) && - isset($limit['length']) - ) { - // Nothing to do - } else { - $limit = getLimitArray(); - } + + $limit = isset($limit) ? $limit : getLimitArray(); $countSessions = $this->model->countSessions($date); $sessions = $this->model->browseSessions($date, $limit); $pageTotal = intval(ceil(intval($countSessions) / $limit['length'])); + // Do NOT show pagination if only one page or less $cataloguePagination = $pageTotal > 1 ? getCataloguePagination($limit['current'], $limit['length'], $pageTotal) : - '' . print_r($limit, 1) . ' ' . $pageTotal; + ''; $sessionsBlocks = array(); + // Get session list catalogue URL $sessionUrl = getCourseCategoryUrl(1, $limit['length'], null, 0, 'display_sessions'); + // Get session search catalogue URL $courseUrl = getCourseCategoryUrl(1, $limit['length'], null, 0, 'subscribe'); foreach ($sessions as $session) { diff --git a/main/inc/lib/auth.lib.php b/main/inc/lib/auth.lib.php index b7eb0f54e3..d6b2d1abe2 100755 --- a/main/inc/lib/auth.lib.php +++ b/main/inc/lib/auth.lib.php @@ -412,7 +412,7 @@ class Auth /** * Display all the courses in the given course category. I could have used a parameter here * @param string $categoryCode Category code - * @param null $randomValue + * @param int $randomValue * @param array $limit will be used if $random_value is not set. * This array should contains 'start' and 'length' keys * @return array Courses data @@ -626,6 +626,7 @@ class Auth if ($res !== false && Database::num_rows($res) > 0) { $count = current(Database::fetch_row($res)); } + return $count; } } diff --git a/main/inc/lib/course_category.lib.php b/main/inc/lib/course_category.lib.php index f169ce6a06..db31e021eb 100755 --- a/main/inc/lib/course_category.lib.php +++ b/main/inc/lib/course_category.lib.php @@ -560,7 +560,7 @@ function countCoursesInCategory($category_code="", $searchTerm = '') /** * @param string $category_code - * @param string $random_value + * @param int $random_value * @param array $limit will be used if $random_value is not set. * This array should contains 'start' and 'length' keys * @return array @@ -859,8 +859,11 @@ function getLimitFilterFromArray($limit) */ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) { + // Start empty html $pageDiv = ''; + // Check if current page is the first page if (1 === $pageCurrent) { + // Add anchor without href $pageAnchor = Display::tag( 'a', '<' @@ -869,10 +872,13 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) 'a', '<<' ); + // Page buttons disabled $pageItemAttributes = array( 'class' => 'disabled' ); } else { + // Add Anchor with href + // To previous page $pageAnchor = Display::tag( 'a', '<', @@ -883,6 +889,7 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) ), ) ); + // To First page $pageAnchorFirst = Display::tag( 'a', '<<', @@ -895,6 +902,7 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) ); $pageItemAttributes = array(); } + // Add items to html $pageDiv .= Display::tag( 'li', $pageAnchorFirst, @@ -905,6 +913,7 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) $pageAnchor, $pageItemAttributes ); + // For each page add its page button to html for ( $i = max(1, $pageCurrent - 3); $i <= min($pageTotal, $pageCurrent + 3); @@ -938,7 +947,9 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) $pageItemAttributes ); } + // Check if current page is the last page if ($pageTotal == $pageCurrent) { + // Add anchor without href $pageAnchor = Display::tag( 'a', '>' @@ -951,6 +962,8 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) 'class' => 'disabled' ); } else { + // Add anchor with href + // To next Page $pageAnchor = Display::tag( 'a', '>', @@ -961,6 +974,7 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) ), ) ); + // To last page $pageAnchorLast = Display::tag( 'a', '>>', @@ -974,6 +988,7 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) ); $pageItemAttributes = array(); } + // Add items to html $pageDiv .= Display::tag( 'li', $pageAnchor, @@ -984,6 +999,7 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) $pageAnchorLast, $pageItemAttributes ); + // Complete pagination html $pageDiv = Display::div( Display::tag( 'ul', @@ -1000,12 +1016,12 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) /** * Return URL to course catalog - * @param $pageCurrent - * @param $pageLength - * @param null $categoryCode - * @param null $hiddenLinks - * @param null $action - * @return null|string + * @param int $pageCurrent + * @param int $pageLength + * @param string $categoryCode + * @param int $hiddenLinks + * @param string $action + * @return string */ function getCourseCategoryUrl( $pageCurrent, @@ -1017,6 +1033,7 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) { $action = isset($action) ? Security::remove_XSS($action) : Security::remove_XSS($_REQUEST['action']); + // Start URL with params $pageUrl = api_get_self() . '?action=' . $action . '&category_code=' . ( @@ -1032,6 +1049,7 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) ; switch ($action) { case 'subscribe' : + // for search $pageUrl .= '&search_term=' . $_REQUEST['search_term'] . '&search_course=1' . @@ -1043,6 +1061,7 @@ function getCataloguePagination($pageCurrent, $pageLength, $pageTotal) break; } + return $pageUrl; } /** diff --git a/main/template/default/auth/courses_categories.php b/main/template/default/auth/courses_categories.php index 5f94598024..294985cdbc 100755 --- a/main/template/default/auth/courses_categories.php +++ b/main/template/default/auth/courses_categories.php @@ -22,7 +22,9 @@ $pageLength = isset($pageLength) ? $pageLength : isset($_GET['pageLength']) ? intval($_GET['pageLength']) : 10; $pageTotal = intval(ceil(intval($countCoursesInCategory) / $pageLength)); -$cataloguePagination = getCataloguePagination($pageCurrent, $pageLength, $pageTotal); +$cataloguePagination = $pageTotal > 1 ? + getCataloguePagination($pageCurrent, $pageLength, $pageTotal) : + ''; if ($showSessions && isset($_POST['date'])) { $date = $_POST['date'];