List courses from students in groups for admin group - refs BT#9442

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent b3c096abd4
commit 825ca55e49
  1. 4
      main/gradebook/certificate_report.php
  2. 86
      main/inc/lib/course.lib.php

@ -55,6 +55,9 @@ if ($selectedSession > 0) {
}
}
} else {
if (api_is_student_boss()) {
$coursesList = CourseManager::getCoursesFollowedByGroupAdmin($userId);
} else {
$coursesList = CourseManager::get_courses_list_by_user_id($userId);
if (is_array($coursesList)) {
@ -64,6 +67,7 @@ if ($selectedSession > 0) {
$course = array_merge($course, $courseInfo);
}
}
}
}
foreach ($coursesList as $course) {

@ -5682,4 +5682,90 @@ class CourseManager
}
return $courses;
}
/**
* Get list of courses based on users of a group for a group admin
* @param int $userId The user id
* @return array
*/
public static function getCoursesFollowedByGroupAdmin($userId)
{
$coursesList = [];
$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);
if (empty($userIdList)) {
return [];
}
$sql = "SELECT DISTINCT(c.id), c.title "
. "FROM $courseTable c "
. "INNER JOIN $courseUserTable cru ON c.code = cru.course_code "
. "WHERE ( "
. "cru.user_id IN(" . implode(', ', $userIdList) . ") "
. "AND cru.relation_type = 0 "
. ")";
if (api_is_multiple_url_enabled()) {
$courseAccessUrlTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$accessUrlId = api_get_current_access_url_id();
if ($accessUrlId != -1) {
$sql = "SELECT DISTINCT(c.id), c.title "
. "FROM $courseTable c "
. "INNER JOIN $courseUserTable cru ON c.code = cru.course_code "
. "INNER JOIN $courseAccessUrlTable crau ON c.code = crau.course_code "
. "WHERE crau.access_url_id = $accessUrlId "
. "AND ( "
. "cru.id_user IN (" . implode(', ', $userIdList) . ") "
. "AND cru.relation_type = 0 "
. ")";
}
}
$result = Database::query($sql);
while ($row = Database::fetch_assoc($result)) {
$coursesList[] = $row;
}
return $coursesList;
}
}

Loading…
Cancel
Save