Stocke la totalité des historiques et affiche la dernière page vue

This commit is contained in:
Fred Tempez 2023-12-08 23:04:14 +01:00
parent 4db14b5da6
commit 59d7a8e5c3
2 changed files with 26 additions and 9 deletions

View File

@ -499,7 +499,10 @@ class core extends common
|| $this->getUser('id') !== $this->getData(['course', self::$siteContent, 'author'])
)
) {
$this->setData(['enrolment', self::$siteContent, $this->getUser('id'), 'history', $this->getUrl(0), time()]);
$data = is_array($this->getData(['enrolment', self::$siteContent, $this->getUser('id'), 'history', $this->getUrl(0)]))
? array_merge([time()], $this->getData(['enrolment', self::$siteContent, $this->getUser('id'), 'history', $this->getUrl(0)]))
: [time()];
$this->setData(['enrolment', self::$siteContent, $this->getUser('id'), 'history', $this->getUrl(0), $data]);
}
// Journalisation

View File

@ -281,9 +281,9 @@ class course extends common
{
$courseId = $this->getUrl(2);
if (
($this->getUser('permission', __CLASS__, __FUNCTION__) !== true
// Le contenu n'existe pas
|| $this->getData(['course', $courseId]) === null)
($this->getUser('permission', __CLASS__, __FUNCTION__) !== true
// Le contenu n'existe pas
|| $this->getData(['course', $courseId]) === null)
) {
// Valeurs en sortie
$this->addOutput([
@ -484,11 +484,25 @@ class course extends common
ksort($users);
foreach ($users as $userId => $userValue) {
$history = $userValue['history'];
if (!empty($history)) {
$maxTime = max($history);
$pageId = array_search($maxTime, $history);
// Date et heure de la dernière page vue
$history = $userValue['history'];
$maxTime = 0;
foreach ($userValue['history'] as $pageId => $times) {
if (is_array($times)) {
foreach ($times as $time) {
if ($time > $maxTime) {
$maxTime = $time;
$lastPageId = $pageId;
}
}
} else {
// Compatibilité anciennes versions
if ($times > $maxTime) {
$maxTime = $times;
$lastPageId = $pageId;
}
}
}
// Compte les rôles valides
@ -529,7 +543,7 @@ class course extends common
self::$courseUsers[] = [
$userId,
$this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']),
!empty($history) ? $pages[$pageId] : '-',
!empty($history) ? $pages[$lastPageId] : '-',
!empty($history) ? helper::dateUTF8('%d %B %Y - %H:%M', $maxTime) : '-',
$this->getData(['user', $userId, 'tags']),
template::button('userHistory' . $userId, [