Browse Source

Merge branch 'fix-report-page' of https://github.com/hi-rafa/chamilo-lms into hi-rafa-fix-report-page

Yannick Warnier 8 years ago
parent
commit
5fe8abdafa
2 changed files with 106 additions and 13 deletions
  1. 98 10
      main/inc/ajax/model.ajax.php
  2. 8 3
      main/inc/lib/sessionmanager.lib.php

+ 98 - 10
main/inc/ajax/model.ajax.php

@@ -242,14 +242,78 @@ switch ($action) {
                 exit;
             }
         } elseif (api_is_student_boss()) {
+    
+            $supervisorStudents = UserManager::getUsersFollowedByUser(
+                api_get_user_id(),
+                api_is_student_boss() ? null : STUDENT,
+                false,
+                false,
+                false,
+                0,
+                null,
+                0,
+                'ASC',
+                1,
+                null,
+                api_is_student_boss() ? STUDENT_BOSS : COURSEMANAGER,
+                null
+            );
+            $supervisorStudents = array_column($supervisorStudents, 'user_id');
+            
+            //get students with course or session
+            $userIdList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
+                'admin',
+                null,
+                false,
+                null,
+                null,
+                1,
+                'asc',
+                null,
+                null,
+                null,
+                array(),
+                $supervisorStudents,
+                5
+            );
+            $userIdList = array_column($userIdList, 'user_id');
+    
+            //get students session courses
+            if ($sessionId == -1) {
+                $sessionList = SessionManager::get_sessions_list();
+                $sessionIdList = array_column($sessionList, 'id');
+        
+                $courseCodeList = array();
+                foreach ($sessionList as $session) {
+                    $courses = SessionManager::get_course_list_by_session_id($session['id']);
+                    $courseCodeList = array_merge($courseCodeList, array_column($courses, 'code'));
+                }
+            }
+            
             $searchByGroups = true;
         } elseif (api_is_platform_admin()) {
+            
+            
+            //get students with course or session
+            $userIdList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
+                'admin',
+                null,
+                false,
+                null,
+                null,
+                1,
+                'asc',
+                null,
+                null,
+                null,
+                array(),
+                array(),
+                5
+            );
+            $userIdList = array_column($userIdList, 'user_id');
+            
+            //get students session courses
             if ($sessionId == -1) {
-                $userIdList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
-                    'admin',
-                    null
-                );
-                $userIdList = array_column($userIdList, 'user_id');
                 $sessionList = SessionManager::get_sessions_list();
                 $sessionIdList = array_column($sessionList, 'id');
 
@@ -742,8 +806,29 @@ switch ($action) {
             $result = [];
             break;
         }
-
-        $result = CourseManager::get_user_list_from_course_code(
+    
+        //get sessions
+        $arrSessions = array();
+        if(count($sessionIdList) > 0) {
+            $arrSessions = CourseManager::get_user_list_from_course_code(
+                null,
+                null,
+                "LIMIT $start, $limit",
+                " $sidx $sord",
+                null,
+                null,
+                true,
+                false,
+                null,
+                $courseCodeList,
+                $userIdList,
+                null,
+                $sessionIdList
+            );
+        }
+    
+        //get courses
+        $arrCourses = CourseManager::get_user_list_from_course_code(
             null,
             null,
             "LIMIT $start, $limit",
@@ -753,11 +838,14 @@ switch ($action) {
             true,
             false,
             null,
-            $courseCodeList,
+            [],
             $userIdList,
-            null,
-            $sessionIdList
+            null
         );
+        
+        //merge courses and sessions
+        $result = array_merge($arrSessions, $arrCourses);
+
         if (api_is_student_boss()) {
             $userGroup = new UserGroup();
             foreach ($result as &$item) {

+ 8 - 3
main/inc/lib/sessionmanager.lib.php

@@ -5359,7 +5359,7 @@ class SessionManager
         }
 
         $courseList = CourseManager::get_courses_followed_by_drh($userId, DRH);
-        $courseConditions = ' AND 1 <> 1';
+//        $courseConditions = ' AND 1 <> 1'; //Why?
         if (!empty($courseList)) {
             $courseIdList = array_column($courseList, 'id');
             $courseConditions = ' AND c.id IN ("'.implode('","', $courseIdList).'")';
@@ -5375,8 +5375,11 @@ class SessionManager
                 true,
                 false
             );
-            $studentIdList = array_keys($studentListSql);
-            $studentListSql = "'".implode("','", $studentIdList)."'";
+            if(!empty($studentListSql)){
+                $studentIdList = array_keys($studentListSql);
+                $studentListSql = "'".implode("','", $studentIdList)."'";
+            }
+            
         } else {
             $studentIdList = array_map('intval', $studentIdList);
             $studentListSql = "'".implode("','", $studentIdList)."'";
@@ -5472,6 +5475,7 @@ class SessionManager
                     INNER JOIN $tbl_session_rel_access_url url ON (url.session_id = s.id)
                     $where
                     $sessionConditions
+                    $userConditionsFromDrh
                 ) UNION (
                     $select
                     FROM $tbl_course c
@@ -5480,6 +5484,7 @@ class SessionManager
                     INNER JOIN $tbl_course_rel_access_url url ON (url.c_id = c.id)
                     $where
                     $courseConditions
+                    $userConditionsFromDrh
                 ) $userUnion
                 ) as t1
                 ";