Browse Source

Filter report result for student boss - BT#9442

Angel Fernando Quiroz Campos 10 years ago
parent
commit
69b9175faa

+ 5 - 0
main/gradebook/certificate_report.php

@@ -30,6 +30,7 @@ $userId = api_get_user_id();
 $sessions = $courses = $months = [0 => get_lang('Select')];
 
 if (api_is_student_boss()) {
+    $userList = GroupPortalManager::getGroupUsersByUser($userId);
     $sessionsList = SessionManager::getSessionsFollowedForGroupAdmin($userId);
 } else {
 $sessionsList = SessionManager::getSessionsCoachedByUser($userId);
@@ -118,6 +119,10 @@ if ($searchSessionAndCourse || $searchCourseOnly) {
 
         if (is_array($studentList) && !empty($studentList)) {
             foreach ($studentList as $student) {
+                if (api_is_student_boss() && !in_array($student['user_id'], $userList)) {
+                    continue;
+                }
+
                 $certificateStudent = array(
                     'fullName' => api_get_person_name($student['firstname'], $student['lastname']),
                     'certificates' => array()

+ 4 - 33
main/inc/ajax/model.ajax.php

@@ -211,39 +211,10 @@ switch ($action) {
         }
 
         if ($searchByGroups) {
-            $groups = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_ADMIN);
-            $groupsId = array_keys($groups);
-            $subgroupsId = [];
-
-            if (is_array($groupsId)) {
-                foreach ($groupsId as $groupId) {
-                    $subgroupsId = array_merge(
-                        $subgroupsId,
-                        GroupPortalManager::getGroupsByDepthLevel($groupId)
-                    );
-                }
-
-                $groupsId = array_merge(
-                    $groupsId,
-                    $subgroupsId
-                );
-
-                foreach ($groupsId as $groupId) {
-                    $groupUsers = GroupPortalManager::get_users_by_group($groupId);
-
-                    if (!is_array($groupUsers)) {
-                        continue;
-                    }
-
-                    foreach ($groupUsers as $memberId => $member) {
-                        if ($member['user_id'] == $userId ) {
-                            continue;
-                        }
-
-                        $userIdList[] = intval($member['user_id']);
-                    }
-                }
-            }
+            $userIdList = array_merge(
+                $userIdList,
+                GroupPortalManager::getGroupUsersByUser(api_get_user_id())
+            );
         }
 
         if (is_array($userIdList)) {

+ 1 - 35
main/inc/lib/course.lib.php

@@ -5695,41 +5695,7 @@ class CourseManager
         $courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
         $courseUserTable = Database::get_main_table(TABLE_MAIN_COURSE_USER);
 
-        $groups = GroupPortalManager::get_groups_by_user($userId, GROUP_USER_PERMISSION_ADMIN);
-
-        $groupsId = array_keys($groups);
-        $subgroupsId = [];
-        $userIdList = [];
-
-        foreach ($groupsId as $groupId) {
-            $subgroupsId = array_merge($subgroupsId, GroupPortalManager::getGroupsByDepthLevel($groupId));
-        }
-
-        $groupsId = array_merge($groupsId, $subgroupsId);
-
-        $groupsId = array_unique($groupsId);
-
-        if (empty($groupsId)) {
-            return [];
-        }
-
-        foreach ($groupsId as $groupId) {
-            $groupUsers = GroupPortalManager::get_users_by_group($groupId);
-
-            if (empty($groupUsers)) {
-                continue;
-            }
-
-            foreach ($groupUsers as $member) {
-                if ($member['user_id'] == $userId ) {
-                    continue;
-                }
-
-                $userIdList[] = intval($member['user_id']);
-            }
-        }
-
-        $userIdList = array_unique($userIdList);
+        $userIdList = GroupPortalManager::getGroupUsersByUser($userId);
 
         if (empty($userIdList)) {
             return [];

+ 55 - 0
main/inc/lib/group_portal_manager.lib.php

@@ -1359,4 +1359,59 @@ class GroupPortalManager
         }
         return true;
     }
+
+    /**
+     * Get the group member list by a user and his group role
+     * @param int $userId The user ID
+     * @param int $relationType Optional. The relation type. GROUP_USER_PERMISSION_ADMIN by default
+     * @param boolean $includeSubgroupsUsers Optional. Whether include the users from subgroups
+     * @return array
+     */
+    public static function getGroupUsersByUser(
+        $userId,
+        $relationType = GROUP_USER_PERMISSION_ADMIN,
+        $includeSubgroupsUsers = true
+    )
+    {
+        $userId = intval($userId);
+
+        $groups = GroupPortalManager::get_groups_by_user($userId, $relationType);
+
+        $groupsId = array_keys($groups);
+        $subgroupsId = [];
+        $userIdList = [];
+
+        if ($includeSubgroupsUsers) {
+            foreach ($groupsId as $groupId) {
+                $subgroupsId = array_merge($subgroupsId, GroupPortalManager::getGroupsByDepthLevel($groupId));
+            }
+
+            $groupsId = array_merge($groupsId, $subgroupsId);
+        }
+
+        $groupsId = array_unique($groupsId);
+
+        if (empty($groupsId)) {
+            return [];
+        }
+
+        foreach ($groupsId as $groupId) {
+            $groupUsers = GroupPortalManager::get_users_by_group($groupId);
+
+            if (empty($groupUsers)) {
+                continue;
+            }
+
+            foreach ($groupUsers as $member) {
+                if ($member['user_id'] == $userId) {
+                    continue;
+                }
+
+                $userIdList[] = intval($member['user_id']);
+            }
+        }
+
+        return array_unique($userIdList);
+    }
+
 }

+ 1 - 35
main/inc/lib/sessionmanager.lib.php

@@ -5965,41 +5965,7 @@ class SessionManager
         $sessionTable = Database::get_main_table(TABLE_MAIN_SESSION);
         $sessionUserTable = Database::get_main_table(TABLE_MAIN_SESSION_USER);
 
-        $groups = GroupPortalManager::get_groups_by_user($userId, GROUP_USER_PERMISSION_ADMIN);
-
-        $groupsId = array_keys($groups);
-        $subgroupsId = [];
-        $userIdList = [];
-
-        foreach ($groupsId as $groupId) {
-            $subgroupsId = array_merge($subgroupsId, GroupPortalManager::getGroupsByDepthLevel($groupId));
-        }
-
-        $groupsId = array_merge($groupsId, $subgroupsId);
-
-        $groupsId = array_unique($groupsId);
-
-        if (empty($groupsId)) {
-            return [];
-        }
-
-        foreach ($groupsId as $groupId) {
-            $groupUsers = GroupPortalManager::get_users_by_group($groupId);
-
-            if (empty($groupUsers)) {
-                continue;
-            }
-
-            foreach ($groupUsers as $member) {
-                if ($member['user_id'] == $userId ) {
-                    continue;
-                }
-
-                $userIdList[] = intval($member['user_id']);
-            }
-        }
-
-        $userIdList = array_unique($userIdList);
+        $userIdList = GroupPortalManager::getGroupUsersByUser($userId);
 
         if (empty($userIdList)) {
             return [];