Skip to content

Commit

Permalink
Fix company report pagination pb and incoherent calculation -refs BT#…
Browse files Browse the repository at this point in the history
…20446
  • Loading branch information
NicoDucou committed Jan 4, 2023
1 parent 8236bd4 commit ba8d1ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
24 changes: 14 additions & 10 deletions main/inc/ajax/model.ajax.php
Expand Up @@ -452,19 +452,14 @@ function getWhereClause($col, $oper, $val)
5
);
$userIdList = array_column($userIdList, 'user_id');

$courseCodeList = array_merge(
$courseCodeList,
CourseManager::getAllCoursesCode()
);
//get students session courses
if ($sessionId == -1) {
$sessionList = SessionManager::get_sessions_list();
$sessionIdList = array_column($sessionList, 'id');
$courseCodeList = [];
foreach ($sessionList as $session) {
$courses = SessionManager::get_course_list_by_session_id($session['id']);
$courseCodeList = array_merge(
$courseCodeList,
array_column($courses, 'code')
);
}
}
$searchByGroups = true;
}
Expand Down Expand Up @@ -513,14 +508,23 @@ function getWhereClause($col, $oper, $val)
}

if ($action === 'get_user_course_report') {
$count = CourseManager::get_count_user_list_from_course_code(
$countCourse = CourseManager::get_count_user_list_from_course_code(
false,
null,
$courseCodeList,
$userIdList,
null,
['where' => $whereCondition, 'extra' => $extra_fields]
);
$countCourseSession = CourseManager::get_count_user_list_from_course_code(
false,
null,
$courseCodeList,
$userIdList,
$sessionIdList,
['where' => $whereCondition, 'extra' => $extra_fields]
);
$count = $countCourse + $countCourseSession;
} else {
$count = CourseManager::get_count_user_list_from_course_code(
true,
Expand Down
20 changes: 20 additions & 0 deletions main/inc/lib/course.lib.php
Expand Up @@ -7300,6 +7300,26 @@ public static function getAccessCourse(
return $data;
}

/**
* returns an array with all the courses codes of the plateform
* @return array
*/
public static function getAllCoursesCode()
{
$sql = "select id, code from course";
$result = Database::query($sql);
$num_rows = Database::num_rows($result);
$coursesCode = [];
$coursesList = [];
if ($num_rows > 0) {
while ($row = Database::fetch_array($result, 'ASSOC')) {
$coursesList[$row['id']] = $row;
}
$coursesCode = array_column($coursesList, 'code');
}
return $coursesCode;
}

/**
* Check if a specific access-url-related setting is a problem or not.
*
Expand Down

0 comments on commit ba8d1ce

Please sign in to comment.