getReport utilisé dans la liste des users d'un courseId

This commit is contained in:
Fred Tempez 2024-04-12 22:04:24 +02:00
parent 03c7e0a7fa
commit 71418548e7

View File

@ -639,29 +639,17 @@ class course extends common
}
}
// Liste des inscrits dans le contenu sélectionné.
$users = $this->getData(['enrolment', $courseId]);
$reports = $this->getReport($courseId);
if (is_array($users)) {
// Tri du tableau par défaut par $userId
ksort($users);
foreach ($users as $userId => $userValue) {
// Date et heure de la dernière page vue
// Compatibilité anciennes versions
if (
$this->getData(['enrolment', $courseId, $userId, 'lastPageView']) === null
or $this->getData(['enrolment', $courseId, $userId, 'datePageView']) === null
) {
if (!empty ($userValue['history'])) {
$maxTime = max($userValue['history']);
$lastPageId = array_search($maxTime, $userValue['history']);
$this->setData(['enrolment', $courseId, $userId, 'lastPageView', $lastPageId]);
$this->setData(['enrolment', $courseId, $userId, 'datePageView', $maxTime]);
}
}
// Compte les rôles valides
if (isset($profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])])) {
$profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])]++;
@ -694,28 +682,28 @@ class course extends common
}
// Progression
$viewPages = $this->getData(['enrolment', $courseId, $userId, 'history']) !== null ?
count(array_keys($this->getData(['enrolment', $courseId, $userId, 'history']))) :
$viewPages = array_key_exists($userId, $reports) ?
count($reports[$userId]) :
0;
// Construction du tableau
self::$courseUsers[] = [
//$userId,
$this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']),
isset ($pages[$this->getData(['enrolment', $courseId, $userId, 'lastPageView'])]['title'])
? $pages[$this->getData(['enrolment', $courseId, $userId, 'lastPageView'])]['title']
isset($pages[$userValue['lastPageView']]['title'])
? $pages[$userValue['lastPageView']]['title']
: '',
$this->getData(['enrolment', $courseId, $userId, 'datePageView'])
? helper::dateUTF8('%d/%m/%Y', $this->getData(['enrolment', $courseId, $userId, 'datePageView']))
$userValue['datePageView']
? helper::dateUTF8('%d/%m/%Y', $userValue['datePageView'])
: '',
$this->getData(['enrolment', $courseId, $userId, 'datePageView'])
? helper::dateUTF8('%H:%M', $this->getData(['enrolment', $courseId, $userId, 'datePageView']))
$userValue['datePageView']
? helper::dateUTF8('%H:%M', $userValue['datePageView'])
: '',
$this->getData(['user', $userId, 'tags']),
template::button('userReport' . $userId, [
'href' => helper::baseUrl() . 'course/userReport/' . $courseId . '/' . $userId,
'value' => !empty ($userValue['history']) ? min(round(($viewPages * 100) / $sumPages, 1), 100) . ' %' : '0%',
'disable' => empty ($userValue['history'])
'value' => $viewPages ? min(round(($viewPages * 100) / $sumPages, 1), 100) . ' %' : '0%',
'disable' => empty($viewPages)
]),
template::button('userDelete' . $userId, [
'class' => 'userDelete buttonRed',
@ -1898,7 +1886,8 @@ class course extends common
/**
* Lit le contenu des fichiers de traces au format CS et renvoie un tableau associatif
*/
private function getReport($courseId, $userId = null) {
private function getReport($courseId, $userId = null)
{
// Remplacez 'chemin/vers/votre/fichier.csv' par le chemin réel de votre fichier CSV
$file = fopen(self::DATA_DIR . $courseId . '/report.csv', "r");
@ -1909,14 +1898,15 @@ class course extends common
$name = $line[0];
$pageId = $line[1];
$timestamp = $line[2];
// Filtre userId
// if (!is_null($userId) && $name === $userId) {
// Initialiser le tableau si nécessaire
if (!isset($data[$name][$pageId])) {
$data[$name][$pageId] = array();
}
// Ajouter le timestamp
$data[$name][$pageId][] = $timestamp;
// }
}
// Fermer le fichier
@ -1929,11 +1919,10 @@ class course extends common
}
}
// Convertir en JSON
$json = json_encode($data, JSON_PRETTY_PRINT);
// Afficher le JSON;
return $json;
return $data;
}
}