11<?php
22/* For licensing terms, see /license.txt */
33
4+ use Chamilo \CoreBundle \Entity \Repository \SequenceRepository ;
45use Chamilo \CoreBundle \Entity \SequenceResource ;
6+ use Chamilo \CoreBundle \Entity \SessionRelCourse ;
7+ use Chamilo \CoreBundle \Entity \Tag ;
8+
59
610/**
711 * Class CoursesController.
@@ -41,7 +45,7 @@ public function courseList($action, $message = '')
4145 {
4246 $ data = [];
4347 $ data ['user_courses ' ] = $ this ->model ->get_courses_of_user (api_get_user_id ());
44- $ data ['user_course_categories ' ] = $ this -> model -> get_user_course_categories ();
48+ $ data ['user_course_categories ' ] = CourseManager:: get_user_course_categories (api_get_user_id () );
4549 $ data ['courses_in_category ' ] = $ this ->model ->get_courses_in_category ();
4650 $ data ['action ' ] = $ action ;
4751 $ data ['message ' ] = $ message ;
@@ -66,7 +70,7 @@ public function categoryList($action, $message = '', $error = '')
6670 api_block_anonymous_users ();
6771
6872 $ data = [];
69- $ data ['user_course_categories ' ] = $ this -> model -> get_user_course_categories ();
73+ $ data ['user_course_categories ' ] = CourseManager:: get_user_course_categories (api_get_user_id () );
7074
7175 $ stok = Security::get_token ();
7276 $ actions = Display::url (
@@ -114,11 +118,11 @@ public function courses_categories(
114118 $ limit = []
115119 ) {
116120 $ data = [];
117- $ browse_course_categories = $ this -> model -> browse_course_categories ();
118- $ data ['countCoursesInCategory ' ] = $ this -> model -> count_courses_in_category ($ category_code );
121+ $ browse_course_categories = CoursesAndSessionsCatalog:: getCourseCategories ();
122+ $ data ['countCoursesInCategory ' ] = CourseCategory:: countCoursesInCategory ($ category_code );
119123 if ($ action === 'display_random_courses ' ) {
120124 // Random value is used instead limit filter
121- $ data ['browse_courses_in_category ' ] = $ this -> model -> browse_courses_in_category (
125+ $ data ['browse_courses_in_category ' ] = CoursesAndSessionsCatalog:: getCoursesInCategory (
122126 null ,
123127 12
124128 );
@@ -127,8 +131,8 @@ public function courses_categories(
127131 if (!isset ($ category_code )) {
128132 $ category_code = $ browse_course_categories [0 ][1 ]['code ' ]; // by default first category
129133 }
130- $ limit = isset ($ limit ) ? $ limit : CourseCategory ::getLimitArray ();
131- $ data ['browse_courses_in_category ' ] = $ this -> model -> browse_courses_in_category (
134+ $ limit = isset ($ limit ) ? $ limit : self ::getLimitArray ();
135+ $ data ['browse_courses_in_category ' ] = CoursesAndSessionsCatalog:: getCoursesInCategory (
132136 $ category_code ,
133137 null ,
134138 $ limit
@@ -192,13 +196,13 @@ public function search_courses(
192196 $ justVisible = false
193197 ) {
194198 $ data = [];
195- $ limit = !empty ($ limit ) ? $ limit : CourseCategory ::getLimitArray ();
196- $ browse_course_categories = $ this -> model -> browse_course_categories ();
197- $ data ['countCoursesInCategory ' ] = $ this -> model -> count_courses_in_category (
199+ $ limit = !empty ($ limit ) ? $ limit : self ::getLimitArray ();
200+ $ browse_course_categories = CoursesAndSessionsCatalog:: getCourseCategories ();
201+ $ data ['countCoursesInCategory ' ] = CourseCategory:: countCoursesInCategory (
198202 'ALL ' ,
199203 $ search_term
200204 );
201- $ data ['browse_courses_in_category ' ] = $ this -> model -> search_courses (
205+ $ data ['browse_courses_in_category ' ] = CoursesAndSessionsCatalog:: search_courses (
202206 $ search_term ,
203207 $ limit ,
204208 $ justVisible
@@ -430,7 +434,7 @@ public function unsubscribe_user_from_course(
430434 }
431435
432436 if (!empty ($ search_term )) {
433- $ this -> search_courses ($ search_term , $ message , $ error );
437+ CoursesAndSessionsCatalog:: search_courses ($ search_term , $ message , $ error );
434438 } else {
435439 $ this ->courses_categories (
436440 'subcribe ' ,
@@ -455,7 +459,7 @@ public function getCoursesCategoriesBlock(
455459 $ hiddenLinks = false ,
456460 $ limit = null
457461 ) {
458- $ categories = $ this -> model -> browse_course_categories ();
462+ $ categories = CoursesAndSessionsCatalog:: getCourseCategories ();
459463 $ html = '' ;
460464 if (!empty ($ categories )) {
461465 $ action = 'display_courses ' ;
@@ -711,9 +715,9 @@ public function sessionsList($action, $nameTools, $limit = [])
711715 {
712716 $ date = isset ($ _POST ['date ' ]) ? $ _POST ['date ' ] : date ('Y-m-d ' );
713717 $ hiddenLinks = isset ($ _GET ['hidden_links ' ]) ? intval ($ _GET ['hidden_links ' ]) == 1 : false ;
714- $ limit = isset ($ limit ) ? $ limit : CourseCategory ::getLimitArray ();
715- $ countSessions = $ this -> model -> countSessions ($ date );
716- $ sessions = $ this -> model -> browseSessions ($ date , $ limit );
718+ $ limit = isset ($ limit ) ? $ limit : self ::getLimitArray ();
719+ $ countSessions = SessionManager:: countSessionsByEndDate ($ date );
720+ $ sessions = CoursesAndSessionsCatalog:: browseSessions ($ date , $ limit );
717721
718722 $ pageTotal = intval (intval ($ countSessions ) / $ limit ['length ' ]);
719723 // Do NOT show pagination if only one page or less
@@ -765,7 +769,7 @@ public function sessionsListByCoursesTag(array $limit)
765769 'subscribe '
766770 );
767771
768- $ sessions = $ this -> model -> browseSessionsByTags ($ searchTag , $ limit );
772+ $ sessions = CoursesAndSessionsCatalog:: browseSessionsByTags ($ searchTag , $ limit );
769773 $ sessionsBlocks = $ this ->getFormattedSessionsBlock ($ sessions );
770774
771775 $ tpl = new Template ();
@@ -803,7 +807,7 @@ public function sessionListBySearch(array $limit)
803807 );
804808 $ searchDate = isset ($ _POST ['date ' ]) ? $ _POST ['date ' ] : date ('Y-m-d ' );
805809
806- $ sessions = $ this -> model -> browseSessionsBySearch ($ q , $ limit );
810+ $ sessions = CoursesAndSessionsCatalog:: browseSessionsBySearch ($ q , $ limit );
807811 $ sessionsBlocks = $ this ->getFormattedSessionsBlock ($ sessions );
808812
809813 $ tpl = new Template ();
@@ -865,13 +869,13 @@ private function getFormattedSessionsBlock(array $sessions)
865869 $ sessionRelCourses = $ sessionRelCourseRepo ->findBy ([
866870 'session ' => $ session ,
867871 ]);
868-
872+ /** @var SessionRelCourse $sessionRelCourse */
869873 foreach ($ sessionRelCourses as $ sessionRelCourse ) {
870874 $ courseTags = $ extraFieldRelTagRepo ->getTags (
871875 $ tagsField ,
872876 $ sessionRelCourse ->getCourse ()->getId ()
873877 );
874-
878+ /** @var Tag $tag */
875879 foreach ($ courseTags as $ tag ) {
876880 $ sessionCourseTags [] = $ tag ->getTag ();
877881 }
@@ -882,6 +886,7 @@ private function getFormattedSessionsBlock(array $sessions)
882886 $ sessionCourseTags = array_unique ($ sessionCourseTags );
883887 }
884888
889+ /** @var SequenceRepository $repo */
885890 $ repo = $ entityManager ->getRepository ('ChamiloCoreBundle:SequenceResource ' );
886891 $ sequences = $ repo ->getRequirementsAndDependenciesWithinSequences (
887892 $ session ->getId (),
@@ -955,4 +960,19 @@ private function getFormattedSessionsBlock(array $sessions)
955960
956961 return $ sessionsBlocks ;
957962 }
963+
964+ /**
965+ * @return array
966+ */
967+ public static function getLimitArray ()
968+ {
969+ $ pageCurrent = isset ($ _REQUEST ['pageCurrent ' ]) ? intval ($ _GET ['pageCurrent ' ]) : 1 ;
970+ $ pageLength = isset ($ _REQUEST ['pageLength ' ]) ? intval ($ _GET ['pageLength ' ]) : CoursesAndSessionsCatalog::PAGE_LENGTH ;
971+
972+ return [
973+ 'start ' => ($ pageCurrent - 1 ) * $ pageLength ,
974+ 'current ' => $ pageCurrent ,
975+ 'length ' => $ pageLength ,
976+ ];
977+ }
958978}
0 commit comments