Reporting - Add new reporting of lp and certificate in session - refs BT#19971

pull/4298/head
Christian 4 years ago
parent c37d1698b8
commit 19b4e31c45
  1. 13
      main/inc/lib/course.lib.php
  2. 2
      main/inc/lib/sessionmanager.lib.php
  3. 43
      main/inc/lib/tracking.lib.php
  4. 23
      main/inc/lib/usermanager.lib.php
  5. 151
      main/mySpace/progress_in_session_report.php
  6. 6
      main/mySpace/session.php
  7. 31
      main/template/default/my_space/progress_in_session_report.tpl

@ -7145,13 +7145,15 @@ class CourseManager
* @param int $userId
* @param string|int|null $startDate
* @param string|int|null $endDate
* @param int $sessionId
*/
public static function getAccessCourse(
$courseId = 0,
$withSession = 0,
$userId = 0,
$startDate = null,
$endDate = null
$endDate = null,
$sessionId = null
) {
$where = null;
$courseId = (int) $courseId;
@ -7166,11 +7168,11 @@ class CourseManager
}
if (!empty($startDate)) {
$startDate = api_get_utc_datetime($startDate, false, true);
$wheres[] = " course_access.login_course_date >= '".$startDate->format('Y-m-d')."' ";
$wheres[] = " course_access.login_course_date >= '".$startDate->format('Y-m-d 00:00:00')."' ";
}
if (!empty($endDate)) {
$endDate = api_get_utc_datetime($endDate, false, true);
$wheres[] = " course_access.login_course_date <= '".$endDate->format('Y-m-d')."' ";
$wheres[] = " course_access.login_course_date <= '".$endDate->format('Y-m-d 23:59:59')."' ";
}
if (0 == $withSession) {
$wheres[] = " course_access.session_id = 0 ";
@ -7178,6 +7180,11 @@ class CourseManager
$wheres[] = " course_access.session_id != 0 ";
}
if (isset($sessionId)) {
$sessionId = (int) $sessionId;
$wheres[] = " course_access.session_id = $sessionId ";
}
$totalWhere = count($wheres);
for ($i = 0; $i <= $totalWhere; $i++) {
if (isset($wheres[$i])) {

@ -1387,7 +1387,7 @@ class SessionManager
*/
public static function get_user_data_access_tracking_overview(
$sessionId,
$courseId,
$courseId = 0,
$studentId = 0,
$profile = '',
$date_from = '',

@ -2622,13 +2622,17 @@ class Tracking
* @param int $user_id
* @param int $courseId
* @param int $session_id
* @param string $startDate date string
* @param string $endDate date string
*
* @return int Time in seconds
*/
public static function get_time_spent_on_the_course(
$user_id,
$courseId,
$session_id = 0
$session_id = 0,
$startDate = null,
$endDate = null
) {
$courseId = (int) $courseId;
@ -2666,6 +2670,15 @@ class Tracking
$sql .= "AND session_id = '$session_id' ";
}
if (!empty($startDate)) {
$startDate = api_get_utc_datetime($startDate, false, true);
$sql .= " AND login_course_date >= '".$startDate->format('Y-m-d 00:00:00')."' ";
}
if (!empty($endDate)) {
$endDate = api_get_utc_datetime($endDate, false, true);
$sql .= " AND login_course_date <= '".$endDate->format('Y-m-d 23:59:59')."' ";
}
$sql .= $conditionUser;
$rs = Database::query($sql);
@ -3403,7 +3416,9 @@ class Tracking
$sessionId = null,
$returnArray = false,
$onlySeriousGame = false,
$maxInsteadAvg = false
$maxInsteadAvg = false,
$startDate = null,
$endDate = null
) {
// If there is at least one learning path and one student.
if (empty($studentId)) {
@ -3452,11 +3467,11 @@ class Tracking
}
$conditions = [
" c_id = {$courseInfo['real_id']} ",
" lp_view.c_id = {$courseInfo['real_id']} ",
" lp_view.lp_id IN (".implode(', ', $filteredLP).") ",
];
$groupBy = 'GROUP BY lp_id';
$groupBy = 'GROUP BY lp_view.lp_id';
if (is_array($studentId)) {
$studentId = array_map('intval', $studentId);
@ -3491,14 +3506,30 @@ class Tracking
$conditions[] = ' (session_id = 0 OR session_id IS NULL) ';
}
$innerJoin = "";
if (!empty($startDate) || !empty($endDate)) {
$lpItemViewTable = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$innerJoin = " INNER JOIN $lpItemViewTable liv ON liv.lp_view_id = lp_view.iid";
if (!empty($startDate)) {
$startDate = api_get_utc_datetime($startDate, false, true);
$startTime = strtotime($startDate->format('Y-m-d 00:00:00'));
$conditions[] = " liv.start_time >= '".$startTime."' ";
}
if (!empty($endDate)) {
$endDate = api_get_utc_datetime($endDate, false, true);
$endTime = strtotime($endDate->format('Y-m-d 23:59:59'));
$conditions[] = " liv.start_time <= '".$endTime."' ";
}
}
$conditionToString = implode('AND', $conditions);
$sql = "SELECT lp_id, view_count, progress
$sql = "SELECT lp_view.lp_id, lp_view.view_count, lp_view.progress
FROM $lpViewTable lp_view
$innerJoin
WHERE
$conditionToString
$groupBy
ORDER BY view_count DESC";
$result = Database::query($sql);
$progress = [];

@ -5953,11 +5953,18 @@ class UserManager
* @param string $course_code The course code
* @param int $session_id
* @param int $user_id The user id
* @param string $startDate date string
* @param string $endDate date string
*
* @return array if there is not information return false
*/
public static function get_info_gradebook_certificate($course_code, $session_id, $user_id)
{
public static function get_info_gradebook_certificate(
$course_code,
$session_id,
$user_id,
$startDate = null,
$endDate = null
) {
$tbl_grade_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$tbl_grade_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$session_id = (int) $session_id;
@ -5969,11 +5976,21 @@ class UserManager
$session_condition = " AND session_id = $session_id";
}
$dateConditions = "";
if (!empty($startDate)) {
$startDate = api_get_utc_datetime($startDate, false, true);
$dateConditions .= " AND created_at >= '".$startDate->format('Y-m-d 00:00:00')."' ";
}
if (!empty($endDate)) {
$endDate = api_get_utc_datetime($endDate, false, true);
$dateConditions .= " AND created_at <= '".$endDate->format('Y-m-d 23:59:59')."' ";
}
$sql = 'SELECT * FROM '.$tbl_grade_certificate.'
WHERE cat_id = (
SELECT id FROM '.$tbl_grade_category.'
WHERE
course_code = "'.Database::escape_string($course_code).'" '.$session_condition.'
course_code = "'.Database::escape_string($course_code).'" '.$session_condition.' '.$dateConditions.'
LIMIT 1
) AND user_id='.$user_id;

@ -0,0 +1,151 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Generate a session report during a period.
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
$this_section = SECTION_TRACKING;
$toolName = get_lang('ProgressInSessionReport');
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'mySpace/index.php',
'name' => get_lang('Reporting')
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'mySpace/session.php',
'name' => get_lang('FollowedSessions'),
];
$actions = null;
$actions .= Display::url(
Display::return_icon('back.png', get_lang('Back'),
null,
ICON_SIZE_MEDIUM
),
'../mySpace/session.php'
);
$actions .= Display::url(
Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), [], 32),
api_get_self().'?export=csv'
);
$actions .= Display::url(
Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), [], ICON_SIZE_MEDIUM),
api_get_self().'?export=xls'
);
if (api_is_platform_admin()) {
$sessionList = SessionManager::get_sessions_list();
} elseif (api_is_drh()) {
$sessionList = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
} elseif (api_is_session_admin()) {
$sessionList = SessionManager::getSessionsFollowedByUser(api_get_user_id(), SESSIONADMIN);
} else {
$sessionList = Tracking::get_sessions_coached_by_user(api_get_user_id());
}
$form = new FormValidator('session_progress_report');
$selectSession = $form->addSelect('session_id', get_lang('Session'), [0 => get_lang('None')]);
foreach ($sessionList as $sessionInfo) {
$selectSession->addOption($sessionInfo['name'], $sessionInfo['id']);
}
$form->addDateRangePicker(
'date_range',
get_lang('DateRange'),
false,
['id' => 'date_range']
);
$form->addButtonFilter(get_lang('Filter'));
$sid = isset($_GET['sid']) ? (int) $_GET['sid'] : 0;
if (!empty($sessionId)) {
$form->setDefaults(['session_id' => $sid]);
}
$users = [];
$courses = [];
$sessionName = '';
if ($form->validate()) {
$formValues = $form->getSubmitValues();
$sessionId = $formValues['session_id'];
$startDate = $formValues['date_range_start'];
$endDate = $formValues['date_range_end'];
$accessSessionCourse = CourseManager::getAccessCourse(
0,
1,
0,
$startDate,
$endDate,
$sessionId
);
if (!empty($accessSessionCourse)) {
$session = api_get_session_entity($sessionId);
$sessionName = $session->getName();
foreach ($accessSessionCourse as $access) {
$user = api_get_user_entity($access['user_id']);
$users[$user->getId()] = [
'complete_name' => UserManager::formatUserFullName($user),
'time_in_platform' => api_time_to_hms(
Tracking::get_time_spent_on_the_course($user->getId(), $access['c_id'], $sessionId, $startDate, $endDate)
),
];
$course = api_get_course_entity($access['c_id']);
$courses[$course->getCode()] = $course->getCode();
}
if (!empty($courses)) {
foreach ($courses as $courseCode => $name) {
foreach ($users as $userId => $user) {
$progress = Tracking::get_avg_student_progress(
$userId,
$courseCode,
[],
$sessionId,
false,
false,
false,
$startDate,
$endDate
);
$infoGradeCertificate = UserManager::get_info_gradebook_certificate(
$courseCode,
$sessionId,
$userId,
$startDate,
$endDate
);
$users[$userId][$courseCode.'_progress'] = is_numeric($progress) ? "$progress %" : '0 %';
$users[$userId][$courseCode.'_certificate'] = $infoGradeCertificate ? get_lang('Yes') : get_lang('No');;
}
}
}
}
}
$view = new Template($toolName);
$view->assign('form', $form->returnForm());
if (!empty($users)) {
$view->assign('sessionName', $sessionName);
$view->assign('courses', $courses);
$view->assign('users', $users);
}
$template = $view->get_template('my_space/progress_in_session_report.tpl');
$content = $view->fetch($template);
$view->assign(
'actions',
Display::toolbarAction('toolbar', [$actions])
);
$view->assign('header', $toolName);
$view->assign('content', $content);
$view->display_one_col_template();

@ -345,6 +345,12 @@ if (api_is_platform_admin(true, true)) {
Display::return_icon('works.png', get_lang('WorksReport'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'mySpace/works_in_session_report.php'
);
$menu_items[] = Display::url(
Display::return_icon('clock.png', get_lang('ProgressInSessionReport'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'mySpace/progress_in_session_report.php'
);
$menu_items[] = Display::url(
Display::return_icon('clock.png', get_lang('TeacherTimeReportBySession'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'admin/teachers_time_by_session_report.php'

@ -0,0 +1,31 @@
{{toolbar}}
{{ form }}
{% if users %}
<h3 class="page-header">{{ sessionName }}</h3>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>{{ 'StudentName'|get_lang }}</th>
<th>{{ 'TimeSpentOnThePlatform'|get_lang }}</th>
{% for course_code in courses %}
<th>{{ 'Progress'|get_lang }}<br />{{ course_code }}</th>
<th>{{ 'Certificate'|get_lang }}<br />{{ course_code }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
{% for data in user %}
<td>{{ data }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
Loading…
Cancel
Save