Tracking: Course: Add finalization date for learnpath and exercises to reporting - refs BT#20362

Author: @christianbeeznest
pull/4524/head
christianbeeznest 3 years ago committed by GitHub
parent 12125bc37f
commit 45cf30d4bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      main/inc/lib/TrackingCourseLog.php
  2. 80
      main/inc/lib/tracking.lib.php
  3. 60
      main/lp/learnpath.class.php
  4. 61
      main/lp/learnpathItem.class.php
  5. 8
      main/tracking/courseLog.php

@ -814,6 +814,20 @@ class TrackingCourseLog
false === $GLOBALS['export_csv']
);
$user['lp_finalization_date'] = Tracking::getCourseLpFinalizationDate(
$user['user_id'],
$courseId,
$GLOBALS['session_id'],
false === $GLOBALS['export_csv']
);
$user['quiz_finalization_date'] = Tracking::getCourseQuizLastFinalizationDate(
$user['user_id'],
$courseId,
$GLOBALS['session_id'],
false === $GLOBALS['export_csv']
);
if ($GLOBALS['export_csv']) {
if (!empty($user['first_connection'])) {
$user['first_connection'] = api_get_local_time($user['first_connection']);
@ -825,6 +839,16 @@ class TrackingCourseLog
} else {
$user['last_connection'] = '-';
}
if (!empty($user['lp_finalization_date'])) {
$user['lp_finalization_date'] = api_get_local_time($user['lp_finalization_date']);
} else {
$user['lp_finalization_date'] = '-';
}
if (!empty($user['quiz_finalization_date'])) {
$user['quiz_finalization_date'] = api_get_local_time($user['quiz_finalization_date']);
} else {
$user['quiz_finalization_date'] = '-';
}
}
if (empty($GLOBALS['session_id'])) {
@ -889,6 +913,9 @@ class TrackingCourseLog
$userRow['first_connection'] = $user['first_connection'];
$userRow['last_connection'] = $user['last_connection'];
$userRow['lp_finalization_date'] = $user['lp_finalization_date'];
$userRow['quiz_finalization_date'] = $user['quiz_finalization_date'];
// we need to display an additional profile field
if (isset($_GET['additional_profile_field'])) {
$data = Session::read('additional_user_profile_info');

@ -3347,6 +3347,86 @@ class Tracking
return $count_attempts;
}
/**
* It gets the last finalization date of learnpaths in a course.
*
* @return string finalization date formatted or false if it is empty.
*/
public static function getCourseLpFinalizationDate(
int $userId,
int $courseId,
int $sessionId,
bool $convertDate = true
) {
$tblLpView = Database::get_course_table(TABLE_LP_VIEW);
$tblLpItem = Database::get_course_table(TABLE_LP_ITEM);
$tblLpItemView = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT FROM_UNIXTIME(liv.start_time) as start_date
FROM $tblLpItemView liv
INNER JOIN
$tblLpView lv ON lv.iid = liv.lp_view_id
INNER JOIN
$tblLpItem li ON li.iid = liv.lp_item_id
WHERE
lv.user_id = $userId AND
lv.c_id = $courseId AND
lv.session_id = $sessionId AND
li.item_type = '".TOOL_LP_FINAL_ITEM."' AND
liv.status = 'completed'
ORDER BY start_date DESC
LIMIT 1";
$rs = Database::query($sql);
$lpFinalDate = Database::result($rs, 0, 0);
if (empty($lpFinalDate)) {
return false;
}
if ($convertDate) {
return api_convert_and_format_date($lpFinalDate, DATE_FORMAT_SHORT);
}
return $lpFinalDate;
}
/**
* It gets the last finalization date of exercises in a course.
*
* @return string finalization date formatted or false if it is empty.
*/
public static function getCourseQuizLastFinalizationDate(
int $userId,
int $courseId,
int $sessionId,
bool $convertDate = true
) {
$tblTrackExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$sql = "SELECT ex.exe_date
FROM $tblTrackExercise AS ex
WHERE
ex.c_id = $courseId AND
ex.session_id = $sessionId AND
ex.exe_user_id = $userId AND
ex.status = ''
ORDER BY ex.exe_date DESC
LIMIT 1";
$rs = Database::query($sql);
$exeDate = Database::result($rs, 0, 0);
if (empty($exeDate)) {
return false;
}
if ($convertDate) {
return api_convert_and_format_date($exeDate, DATE_FORMAT_SHORT);
}
return $exeDate;
}
/**
* Get count student's exercise progress.
*

@ -1603,7 +1603,7 @@ class learnpath
*
* @return int The number of items currently completed
*/
public function get_complete_items_count($failedStatusException = false)
public function get_complete_items_count($failedStatusException = false, $typeListNotToCount = [])
{
$i = 0;
$completedStatusList = [
@ -1622,10 +1622,17 @@ class learnpath
error_log('Counting steps with status in: '.print_r($completedStatusList, 1));
}
$chapters = self::getChapterTypes();
if (!empty($typeListNotToCount)) {
$typeListNotToCount = array_merge($typeListNotToCount, $chapters);
} else {
$typeListNotToCount = $chapters;
}
foreach ($this->items as $id => $dummy) {
// Trying failed and browsed considered "progressed" as well.
if ($this->items[$id]->status_is($completedStatusList) &&
$this->items[$id]->get_type() !== 'dir'
!in_array($this->items[$id]->get_type(), $typeListNotToCount)
) {
$i++;
}
@ -1683,10 +1690,15 @@ class learnpath
*
* @return int The total no-chapters number of items
*/
public function getTotalItemsCountWithoutDirs()
public function getTotalItemsCountWithoutDirs($typeListNotToCount = [])
{
$total = 0;
$typeListNotToCount = self::getChapterTypes();
$chapters = self::getChapterTypes();
if (!empty($typeListNotToCount)) {
$typeListNotToCount = array_merge($typeListNotToCount, $chapters);
} else {
$typeListNotToCount = $chapters;
}
foreach ($this->items as $temp2) {
if (!in_array($temp2->get_type(), $typeListNotToCount)) {
$total++;
@ -14672,6 +14684,26 @@ EOD;
return empty($lpView) ? [] : $lpView;
}
/**
* Check and obtain the lp final item if exist.
*
* @return learnpathItem
*/
public function getFinalItem()
{
if (empty($this->items)) {
return null;
}
foreach ($this->items as $item) {
if ($item->type !== 'final_item') {
continue;
}
return $item;
}
}
/**
* Get the depth level of LP item.
*
@ -14728,26 +14760,6 @@ EOD;
return str_replace(' ', '_', $in_type);
}
/**
* Check and obtain the lp final item if exist.
*
* @return learnpathItem
*/
private function getFinalItem()
{
if (empty($this->items)) {
return null;
}
foreach ($this->items as $item) {
if ($item->type !== 'final_item') {
continue;
}
return $item;
}
}
/**
* Get the LP Final Item Template.
*

@ -3629,6 +3629,23 @@ class learnpathItem
}
}
public function isLpItemsCompleted()
{
$lp = new Learnpath(api_get_course_id(), $this->lp_id, api_get_user_id());
$count = $lp->getTotalItemsCountWithoutDirs([TOOL_LP_FINAL_ITEM]);
$completed = $lp->get_complete_items_count(true, [TOOL_LP_FINAL_ITEM]);
$isCompleted = ($count - $completed == 0);
return $isCompleted;
}
public function getLpFinalItem()
{
$lp = new Learnpath(api_get_course_id(), $this->lp_id, api_get_user_id());
return $lp->getFinalItem();
}
/**
* Writes the current data to the database.
*
@ -3659,6 +3676,15 @@ class learnpathItem
return true;
}
// Final item is checked when previous are completed.
if ($this->type == 'final_item') {
if ($debug) {
error_log('learnpathItem::write_to_db() , final item, so not updated.', 0);
}
return false;
}
$courseId = api_get_course_int_id();
$mode = $this->get_lesson_mode();
$credit = $this->get_credit();
@ -4124,6 +4150,41 @@ class learnpathItem
error_log('End of learnpathItem::write_to_db()', 0);
}
// Check if lp is completed to validate the final item
if ($this->isLpItemsCompleted()) {
$lpFinalItem = $this->getLpFinalItem();
if ($lpFinalItem) {
$sql = "SELECT iid
FROM $item_view_table
WHERE
c_id = $courseId AND
lp_item_id = {$lpFinalItem->get_id()} AND
lp_view_id = {$this->view_id} AND
status != 'completed'";
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
$params = [
'total_time' => $this->get_total_time(),
'start_time' => $this->get_current_start_time(),
'score' => $this->get_score(),
'status' => 'completed',
'max_score' => $this->get_max(),
'suspend_data' => $this->current_data,
'lesson_location' => $this->lesson_location,
];
$where = [
'c_id = ? AND lp_item_id = ? AND lp_view_id = ? AND view_count = ?' => [
$courseId,
$lpFinalItem->get_id(),
$this->view_id,
$this->get_attempt_id(),
],
];
Database::update($item_view_table, $params, $where);
}
}
}
return true;
}

@ -773,6 +773,12 @@ if ($nbStudents > 0 || isset($parameters['user_active'])) {
$table->set_header($headerCounter++, get_lang('LatestLoginInCourse'), false);
$headers['latest_login'] = get_lang('LatestLoginInCourse');
$table->set_header($headerCounter++, get_lang('LpFinalizationDate'), false);
$headers['lp_finalization_date'] = get_lang('LpFinalizationDate');
$table->set_header($headerCounter++, get_lang('QuizFinalizationDate'), false);
$headers['quiz_finalization_date'] = get_lang('QuizFinalizationDate');
$counter = $headerCounter;
if (api_get_setting('show_email_addresses') === 'true') {
$table->set_header($counter, get_lang('Email'), false);
@ -1021,6 +1027,8 @@ if ($export_csv) {
$csv_headers[] = get_lang('FirstLoginInCourse');
$csv_headers[] = get_lang('LatestLoginInCourse');
$csv_headers[] = get_lang('QuizFinalizationDate');
$csv_headers[] = get_lang('LpFinalizationDate');
if (isset($_GET['additional_profile_field'])) {
foreach ($_GET['additional_profile_field'] as $fieldId) {

Loading…
Cancel
Save