1.4.23 User History modifié

This commit is contained in:
Fred Tempez 2024-02-09 15:38:32 +01:00
parent b8123b0534
commit 023ba99c0b
4 changed files with 82 additions and 79 deletions

View File

@ -1121,17 +1121,23 @@ class course extends common
$courseId = $this->getUrl(2);
$userId = $this->getUrl(3);
$history = $this->getData(['enrolment', $courseId, $userId, 'history']);
$h = $this->getData(['enrolment', $courseId, $userId, 'history']);
// Inversion des clés et des valeurs
$history = array();
foreach ($h as $key => $values) {
foreach ($values as $value) {
$history[$value] = $key;
}
}
ksort($history);
// Liste des pages contenues dans cet espace et exclure les barres et les pages masquées
$data = json_decode(file_get_contents(self::DATA_DIR . $courseId . '/page.json'), true);
$data = $data['page'];
$count = 0;
foreach ($data as $pageId => $pageData) {
$p = json_decode(file_get_contents(self::DATA_DIR . $courseId . '/page.json'), true);
foreach ($p['page'] as $pageId => $pageData) {
if ($pageData['position'] > 0) {
$count++;
$pages[$pageId] = [
'number' => $count,
'title' => $pageData['title'],
];
}
@ -1139,37 +1145,33 @@ class course extends common
$floorTime = 99999999999;
$topTime = 0;
$lastView = 0;
foreach ($history as $pageId => $times) {
// Dates de consultation de la page
if (is_array($times)) {
$d = array();
foreach ($times as $time) {
if (isset($pages[$pageId]['number'])) {
self::$userHistory[] = [
$pages[$pageId]['number'],
html_entity_decode($pages[$pageId]['title']),
helper::dateUTF8('%d/%m/%Y', $time),
helper::dateUTF8('%H:%M', $time)
];
$floorTime = isset($floorTime) && $floorTime < $time ? $floorTime : $time;
$topTime = isset($topTime) && $topTime > $time ? $topTime : $time;
}
}
} else {
if (isset($pages[$pageId]['number'])) {
self::$userHistory[] = [
$pages[$pageId]['number'],
html_entity_decode($pages[$pageId]['title']),
helper::dateUTF8('%d/%m/%Y', $times),
helper::dateUTF8('%H:%M', $times)
];
$floorTime = isset($floorTime) && $floorTime < $times ? $floorTime : $times;
$topTime = isset($topTime) && $topTime > $times ? $topTime : $times;
}
foreach ($history as $time => $pageId) {
if (isset($pages[$pageId]['title'])) {
$lastView = ($lastView === 0) ? $time : $lastView;
$diff = $time - $lastView;
self::$userHistory[] = [
html_entity_decode($pages[$pageId]['title']),
$time,
($diff < 1800) ? sprintf("%d' %d''", floor($diff / 60), $diff % 60) : "Non significatif",
];
$lastView = $time;
$floorTime = isset($floorTime) && $floorTime < $time ? $floorTime : $time;
$topTime = isset($topTime) && $topTime > $time ? $topTime : $time;
}
}
// Décale les temps de consultation
for ($i = 0; $i < count(self::$userHistory) - 1; $i++) {
self::$userHistory[$i][2] = self::$userHistory[$i + 1][2];
}
// Formate le timestamp
array_walk(self::$userHistory, function (&$item) {
$item[1] = helper::dateUTF8('%d/%m/%Y %H:%M:%S', $item[1]);
});
self::$userStat['floor'] = helper::dateUTF8('%d %B %Y %H:%M', $floorTime);
self::$userStat['top'] = helper::dateUTF8('%d %B %Y %H:%M', $topTime);
$d = $topTime - $floorTime;
@ -1184,10 +1186,7 @@ class course extends common
// Valeurs en sortie
$this->addOutput([
'title' => helper::translate('Historique ') . $this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']),
'view' => 'userHistory',
'vendor' => [
'datatables'
]
'view' => 'userHistory'
]);
}
@ -1293,50 +1292,60 @@ class course extends common
$courseId = $this->getUrl(2);
$userId = $this->getUrl(3);
$history = $this->getData(['enrolment', $courseId, $userId, 'history']);
self::$userHistory = [
0 => ['Ordre', 'PageId', 'Page Titre', 'Consultation Date', 'Consultation Heure']
];
// Traitement de l'historique
$h = $this->getData(['enrolment', $courseId, $userId, 'history']);
// Inversion des clés et des valeurs
$history = array();
foreach ($h as $key => $values) {
foreach ($values as $value) {
$history[$value] = $key;
}
}
ksort($history);
// Liste des pages contenues dans cet espace et exclure les barres et les pages masquées
$data = json_decode(file_get_contents(self::DATA_DIR . $courseId . '/page.json'), true);
$data = $data['page'];
$count = 0;
foreach ($data as $pageId => $pageData) {
$p = json_decode(file_get_contents(self::DATA_DIR . $courseId . '/page.json'), true);
foreach ($p['page'] as $pageId => $pageData) {
if ($pageData['position'] > 0) {
$count++;
$pages[$pageId] = [
'number' => $count,
'title' => $pageData['title'],
];
}
}
foreach ($history as $pageId => $times) {
// Dates de consultation de la page
if (is_array($times)) {
$d = array();
foreach ($times as $time) {
self::$userHistory[] = [
$pages[$pageId]['number'],
$pageId,
html_entity_decode($pages[$pageId]['title']),
helper::dateUTF8('%d/%d/%Y', $time),
helper::dateUTF8('%H:%M:%S', $time),
];
}
} else {
$lastView = 0;
foreach ($history as $time => $pageId) {
if (isset($pages[$pageId]['title'])) {
$lastView = ($lastView === 0) ? $time : $lastView;
$diff = $time - $lastView;
self::$userHistory[] = [
$pages[$pageId]['number'],
$pageId,
html_entity_decode($pages[$pageId]['title']),
helper::dateUTF8('%d/%d/%Y', $times),
helper::dateUTF8('%H:%M:%S', $time),
$time,
($diff < 1800) ? sprintf("%d' %d''", floor($diff / 60), $diff % 60) : "Non significatif",
];
$lastView = $time;
$floorTime = isset($floorTime) && $floorTime < $time ? $floorTime : $time;
$topTime = isset($topTime) && $topTime > $time ? $topTime : $time;
}
}
// Décale les temps de consultation
for ($i = 0; $i < count(self::$userHistory) - 1; $i++) {
self::$userHistory[$i][3] = self::$userHistory[$i + 1][3];
}
// Formate le timestamp
array_walk(self::$userHistory, function (&$item) {
$item[2] = helper::dateUTF8('%d/%m/%Y %H:%M:%S', $item[2]);
});
// Ajoute les entêtes
self::$userHistory = array_merge([0 => ['PageId', 'Page Titre', 'Consultation Date', 'Temps Consultation']], self::$userHistory);
// Dossier d'export
if (is_dir(self::FILE_DIR . 'source/' . $courseId) === false) {
mkdir(self::FILE_DIR . 'source/' . $courseId);

View File

@ -16,3 +16,7 @@
/** NE PAS EFFACER
* admin.css
*/
table td {
text-align: left;
}

View File

@ -12,15 +12,5 @@
*/
$(document).ready((function () {
$.fn.dataTable.moment( 'DD/MM/YYYY' );
$('#dataTables').DataTable({
language: {
url: "core/vendor/datatables/french.json"
},
locale: 'fr',
searching: false,
pageLength: 100,
lengthChange: false,
paging: false
});
}));

View File

@ -19,7 +19,7 @@
<div class="col4 offset2">
<?php if ($this->getData(['course', $this->getUrl(2), 'access']) === self::COURSE_ACCESS_DATE): ?>
<p>Espace ouvert le :
<?php echo helper::dateUTF8('%d %B %Y %H:%M', $this->getData(['course', $this->getUrl(2), 'openingDate'])); ?></p
<?php echo helper::dateUTF8('%d %B %Y %H:%M', $this->getData(['course', $this->getUrl(2), 'openingDate'])); ?></p>
<p>Espace fermé le :
<?php echo helper::dateUTF8('%d %B %Y %H:%M', $this->getData(['course', $this->getUrl(2), 'closingDate'])); ?></p>
<?php endif;?>
@ -32,7 +32,7 @@
</div>
<div class="row textAlignCenter">
<div class="col8">
<?php echo template::table([1, 5, 3, 3], $module::$userHistory, ['#', 'Page', 'Date Consultation', 'Heure'], ['id' => 'dataTables']);?>
<?php echo template::table([6, 3, 3], $module::$userHistory, ['Page', 'Début de Consultation', 'Temps consultation']);?>
</div>
</div>
<?php else: ?>