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,31 +639,19 @@ class course extends common
} }
} }
// Liste des inscrits dans le contenu sélectionné. // Liste des inscrits dans le contenu sélectionné.
$users = $this->getData(['enrolment', $courseId]); $users = $this->getData(['enrolment', $courseId]);
$reports = $this->getReport($courseId);
if (is_array($users)) { if (is_array($users)) {
// Tri du tableau par défaut par $userId // Tri du tableau par défaut par $userId
ksort($users); ksort($users);
foreach ($users as $userId => $userValue) { 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 // Compte les rôles valides
if (isset ($profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])])) { if (isset($profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])])) {
$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 // Progression
$viewPages = $this->getData(['enrolment', $courseId, $userId, 'history']) !== null ? $viewPages = array_key_exists($userId, $reports) ?
count(array_keys($this->getData(['enrolment', $courseId, $userId, 'history']))) : count($reports[$userId]) :
0; 0;
// Construction du tableau // Construction du tableau
self::$courseUsers[] = [ self::$courseUsers[] = [
//$userId, //$userId,
$this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']), $this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']),
isset ($pages[$this->getData(['enrolment', $courseId, $userId, 'lastPageView'])]['title']) isset($pages[$userValue['lastPageView']]['title'])
? $pages[$this->getData(['enrolment', $courseId, $userId, 'lastPageView'])]['title'] ? $pages[$userValue['lastPageView']]['title']
: '', : '',
$this->getData(['enrolment', $courseId, $userId, 'datePageView']) $userValue['datePageView']
? helper::dateUTF8('%d/%m/%Y', $this->getData(['enrolment', $courseId, $userId, 'datePageView'])) ? helper::dateUTF8('%d/%m/%Y', $userValue['datePageView'])
: '', : '',
$this->getData(['enrolment', $courseId, $userId, 'datePageView']) $userValue['datePageView']
? helper::dateUTF8('%H:%M', $this->getData(['enrolment', $courseId, $userId, 'datePageView'])) ? helper::dateUTF8('%H:%M', $userValue['datePageView'])
: '', : '',
$this->getData(['user', $userId, 'tags']), $this->getData(['user', $userId, 'tags']),
template::button('userReport' . $userId, [ template::button('userReport' . $userId, [
'href' => helper::baseUrl() . 'course/userReport/' . $courseId . '/' . $userId, 'href' => helper::baseUrl() . 'course/userReport/' . $courseId . '/' . $userId,
'value' => !empty ($userValue['history']) ? min(round(($viewPages * 100) / $sumPages, 1), 100) . ' %' : '0%', 'value' => $viewPages ? min(round(($viewPages * 100) / $sumPages, 1), 100) . ' %' : '0%',
'disable' => empty ($userValue['history']) 'disable' => empty($viewPages)
]), ]),
template::button('userDelete' . $userId, [ template::button('userDelete' . $userId, [
'class' => 'userDelete buttonRed', 'class' => 'userDelete buttonRed',
@ -765,7 +753,7 @@ class course extends common
// Inscription des utilisateurs cochés // Inscription des utilisateurs cochés
if ( if (
isset ($_POST['courseUsersAddSubmit']) isset($_POST['courseUsersAddSubmit'])
) { ) {
foreach ($_POST as $keyPost => $valuePost) { foreach ($_POST as $keyPost => $valuePost) {
// Exclure les variables post qui ne sont pas des userId et ne traiter que les non inscrits // Exclure les variables post qui ne sont pas des userId et ne traiter que les non inscrits
@ -821,15 +809,15 @@ class course extends common
foreach ($users as $userId => $userValue) { foreach ($users as $userId => $userValue) {
// Compte les rôles // Compte les rôles
if (isset ($profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])])) { if (isset($profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])])) {
$profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])]++; $profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])]++;
} }
// Filtres // Filtres
if ( if (
isset ($_POST['courseFilterGroup']) isset($_POST['courseFilterGroup'])
|| isset ($_POST['courseFilterFirstName']) || isset($_POST['courseFilterFirstName'])
|| isset ($_POST['courseFilterLastName']) || isset($_POST['courseFilterLastName'])
) { ) {
// Groupe et profils // Groupe et profils
@ -934,7 +922,7 @@ class course extends common
// Inscription des utilisateurs cochés // Inscription des utilisateurs cochés
if ( if (
isset ($_POST['courseUsersDeleteSubmit']) isset($_POST['courseUsersDeleteSubmit'])
) { ) {
foreach ($_POST as $keyPost => $valuePost) { foreach ($_POST as $keyPost => $valuePost) {
// Exclure les variables post qui ne sont pas des userId et ne traiter que les non inscrits // Exclure les variables post qui ne sont pas des userId et ne traiter que les non inscrits
@ -984,15 +972,15 @@ class course extends common
foreach ($users as $userId => $userValue) { foreach ($users as $userId => $userValue) {
// Compte les rôles // Compte les rôles
if (isset ($profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])])) { if (isset($profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])])) {
$profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])]++; $profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])]++;
} }
// Filtres // Filtres
if ( if (
isset ($_POST['courseFilterGroup']) isset($_POST['courseFilterGroup'])
|| isset ($_POST['courseFilterFirstName']) || isset($_POST['courseFilterFirstName'])
|| isset ($_POST['courseFilterLastName']) || isset($_POST['courseFilterLastName'])
) { ) {
// Groupe et profils // Groupe et profils
@ -1208,7 +1196,7 @@ class course extends common
$lastView = 0; $lastView = 0;
foreach ($history as $time => $pageId) { foreach ($history as $time => $pageId) {
if (isset ($pages[$pageId]['title'])) { if (isset($pages[$pageId]['title'])) {
$lastView = ($lastView === 0) ? $time : $lastView; $lastView = ($lastView === 0) ? $time : $lastView;
$diff = $time - $lastView; $diff = $time - $lastView;
self::$userReport[] = [ self::$userReport[] = [
@ -1224,8 +1212,8 @@ class course extends common
]; ];
} }
$lastView = $time; $lastView = $time;
$floorTime = isset ($floorTime) && $floorTime < $time ? $floorTime : $time; $floorTime = isset($floorTime) && $floorTime < $time ? $floorTime : $time;
$topTime = isset ($topTime) && $topTime > $time ? $topTime : $time; $topTime = isset($topTime) && $topTime > $time ? $topTime : $time;
} }
} }
@ -1319,7 +1307,7 @@ class course extends common
$this->getData(['enrolment', $courseId, $userId, 'lastPageView']) === null $this->getData(['enrolment', $courseId, $userId, 'lastPageView']) === null
or $this->getData(['enrolment', $courseId, $userId, 'datePageView']) === null or $this->getData(['enrolment', $courseId, $userId, 'datePageView']) === null
) { ) {
if (!empty ($userValue['history'])) { if (!empty($userValue['history'])) {
$maxTime = max($userValue['history']); $maxTime = max($userValue['history']);
$lastPageId = array_search($maxTime, $userValue['history']); $lastPageId = array_search($maxTime, $userValue['history']);
$this->setData(['enrolment', $courseId, $userId, 'lastPageView', $lastPageId]); $this->setData(['enrolment', $courseId, $userId, 'lastPageView', $lastPageId]);
@ -1337,7 +1325,7 @@ class course extends common
$userId, $userId,
$this->getData(['user', $userId, 'firstname']), $this->getData(['user', $userId, 'firstname']),
$this->getData(['user', $userId, 'lastname']), $this->getData(['user', $userId, 'lastname']),
isset ($pages[$this->getData(['enrolment', $courseId, $userId, 'lastPageView'])]) isset($pages[$this->getData(['enrolment', $courseId, $userId, 'lastPageView'])])
? $pages[$this->getData(['enrolment', $courseId, $userId, 'lastPageView'])] ? $pages[$this->getData(['enrolment', $courseId, $userId, 'lastPageView'])]
: $this->getData(['enrolment', $courseId, $userId, 'lastPageView']) . ' (supprimée)', : $this->getData(['enrolment', $courseId, $userId, 'lastPageView']) . ' (supprimée)',
helper::dateUTF8('%d/%d/%Y', $this->getData(['enrolment', $courseId, $userId, 'datePageView'])), helper::dateUTF8('%d/%d/%Y', $this->getData(['enrolment', $courseId, $userId, 'datePageView'])),
@ -1413,7 +1401,7 @@ class course extends common
$lastView = 0; $lastView = 0;
foreach ($history as $time => $pageId) { foreach ($history as $time => $pageId) {
if (isset ($pages[$pageId]['title'])) { if (isset($pages[$pageId]['title'])) {
$lastView = ($lastView === 0) ? $time : $lastView; $lastView = ($lastView === 0) ? $time : $lastView;
$diff = $time - $lastView; $diff = $time - $lastView;
self::$userReport[] = [ self::$userReport[] = [
@ -1423,8 +1411,8 @@ class course extends common
($diff < 1800) ? sprintf("%d' %d''", floor($diff / 60), $diff % 60) : "Non significatif", ($diff < 1800) ? sprintf("%d' %d''", floor($diff / 60), $diff % 60) : "Non significatif",
]; ];
$lastView = $time; $lastView = $time;
$floorTime = isset ($floorTime) && $floorTime < $time ? $floorTime : $time; $floorTime = isset($floorTime) && $floorTime < $time ? $floorTime : $time;
$topTime = isset ($topTime) && $topTime > $time ? $topTime : $time; $topTime = isset($topTime) && $topTime > $time ? $topTime : $time;
} }
} }
@ -1898,42 +1886,43 @@ class course extends common
/** /**
* Lit le contenu des fichiers de traces au format CS et renvoie un tableau associatif * 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 // Remplacez 'chemin/vers/votre/fichier.csv' par le chemin réel de votre fichier CSV
$file = fopen( self::DATA_DIR . $courseId . '/report.csv', "r"); $file = fopen(self::DATA_DIR . $courseId . '/report.csv', "r");
$data = array(); $data = array();
// Lire ligne par ligne // Lire ligne par ligne
while (($line = fgetcsv($file, 1000, ";")) !== false) { while (($line = fgetcsv($file, 1000, ";")) !== false) {
$name = $line[0]; $name = $line[0];
$pageId = $line[1]; $pageId = $line[1];
$timestamp = $line[2]; $timestamp = $line[2];
// Filtre userId
// Initialiser le tableau si nécessaire // if (!is_null($userId) && $name === $userId) {
if (!isset($data[$name][$pageId])) { // Initialiser le tableau si nécessaire
$data[$name][$pageId] = array(); if (!isset($data[$name][$pageId])) {
} $data[$name][$pageId] = array();
}
// Ajouter le timestamp // Ajouter le timestamp
$data[$name][$pageId][] = $timestamp; $data[$name][$pageId][] = $timestamp;
// }
} }
// Fermer le fichier // Fermer le fichier
fclose($file); fclose($file);
// Trier les timestamps // Trier les timestamps
foreach ($data as &$userData) { foreach ($data as &$userData) {
foreach ($userData as &$pageData) { foreach ($userData as &$pageData) {
sort($pageData); sort($pageData);
} }
} }
// Convertir en JSON
$json = json_encode($data, JSON_PRETTY_PRINT);
// Afficher le JSON; // Afficher le JSON;
return $json; return $data;
} }
} }