users avec stats okay

This commit is contained in:
Fred Tempez 2023-12-09 13:25:18 +01:00
parent 59d7a8e5c3
commit 30d96fb24c
3 changed files with 48 additions and 37 deletions

View File

@ -499,10 +499,14 @@ class core extends common
|| $this->getUser('id') !== $this->getData(['course', self::$siteContent, 'author']) || $this->getUser('id') !== $this->getData(['course', self::$siteContent, 'author'])
) )
) { ) {
// Stocke l'historique des pages vues
$data = is_array($this->getData(['enrolment', self::$siteContent, $this->getUser('id'), 'history', $this->getUrl(0)])) $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)])) ? array_merge([time()], $this->getData(['enrolment', self::$siteContent, $this->getUser('id'), 'history', $this->getUrl(0)]))
: [time()]; : [time()];
$this->setData(['enrolment', self::$siteContent, $this->getUser('id'), 'history', $this->getUrl(0), $data]); $this->setData(['enrolment', self::$siteContent, $this->getUser('id'), 'history', $this->getUrl(0), $data]);
// Stocke la dernière page vue et sa date de consultation
$this->setData(['enrolment', self::$siteContent, $this->getUser('id'), 'lastPageView', $this->getUrl(0)]);
$this->setData(['enrolment', self::$siteContent, $this->getUser('id'), 'datePageView', time()]);
} }
// Journalisation // Journalisation

View File

@ -469,11 +469,11 @@ class course extends common
// Statistiques du contenu sélectionné calcul du nombre de pages // Statistiques du contenu sélectionné calcul du nombre de pages
$sumPages = 0; $sumPages = 0;
$data = json_decode(file_get_contents(self::DATA_DIR . $courseId . '/page.json'), true); $data = json_decode(file_get_contents(self::DATA_DIR . $courseId . '/page.json'), true);
// Exclure les barres et les pages masquées
// Compter les pages et exclure les barres et les pages masquées
foreach ($data['page'] as $pageId => $pageData) { foreach ($data['page'] as $pageId => $pageData) {
if ($pageData['position'] > 0) { if ($pageData['position'] > 0) {
$sumPages++; $sumPages++;
$pages[$pageId] = $pageData['title'];
} }
} }
@ -486,25 +486,20 @@ class course extends common
foreach ($users as $userId => $userValue) { foreach ($users as $userId => $userValue) {
// Date et heure de la dernière page vue // Date et heure de la dernière page vue
$history = $userValue['history']; // Compatibilité anciennes versions
$maxTime = 0; if (
foreach ($userValue['history'] as $pageId => $times) { $this->getData(['enrolment', $courseId, $userId, 'lastPageView']) === null
if (is_array($times)) { or $this->getData(['enrolment', $courseId, $userId, 'datePageView']) === null
foreach ($times as $time) { ) {
if ($time > $maxTime) { if (!empty($userValue['history'])) {
$maxTime = $time; $maxTime = max($userValue['history']);
$lastPageId = $pageId; $lastPageId = array_search($maxTime, $userValue['history']);
} $this->setData(['enrolment', $courseId, $userId, 'lastPageView', $lastPageId]);
} $this->setData(['enrolment', $courseId, $userId, 'datePageView', $maxTime]);
} else {
// Compatibilité anciennes versions
if ($times > $maxTime) {
$maxTime = $times;
$lastPageId = $pageId;
}
} }
} }
// 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'])]++;
@ -537,19 +532,20 @@ class course extends common
} }
// Taux de parcours // Taux de parcours
$viewPages = count($this->getData(['enrolment', $courseId, $userId, 'history'])); $viewPages = $this->getData(['enrolment', $courseId, $userId, 'history']) !== null ?
count(array_keys($this->getData(['enrolment', $courseId, $userId, 'history']))) :
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']),
!empty($history) ? $pages[$lastPageId] : '-', $this->getData(['enrolment', $courseId, $userId, 'lastPageView']),
!empty($history) ? helper::dateUTF8('%d %B %Y - %H:%M', $maxTime) : '-', helper::dateUTF8('%d %B %Y - %H:%M', $this->getData(['enrolment', $courseId, $userId, 'datePageView'])),
$this->getData(['user', $userId, 'tags']), $this->getData(['user', $userId, 'tags']),
template::button('userHistory' . $userId, [ template::button('userHistory' . $userId, [
'href' => helper::baseUrl() . 'course/userHistory/' . $courseId . '/' . $userId, 'href' => helper::baseUrl() . 'course/userHistory/' . $courseId . '/' . $userId,
'value' => !empty($history) ? round(($viewPages * 100) / $sumPages, 1) . ' %' : '0%', 'value' => !empty($userValue['history']) ? round(($viewPages * 100) / $sumPages, 1) . ' %' : '0%',
'disable' => empty($history) 'disable' => empty($userValue['history'])
]), ]),
template::button('userDelete' . $userId, [ template::button('userDelete' . $userId, [
'class' => 'userDelete buttonRed', 'class' => 'userDelete buttonRed',
@ -871,18 +867,19 @@ class course extends common
&& $this->courseIsAvailable($courseId) && $this->courseIsAvailable($courseId)
) { ) {
// Récupérer la dernière page visitée par cet utilisateur si elle existe // Récupérer la dernière page visitée par cet utilisateur si elle existe
$maxTime = $this->getData(['enrolment', $courseId, $userId, 'history']) ? max($this->getData(['enrolment', $courseId, $userId, 'history'])) : null; $redirect = $this->getData(['enrolment', $courseId, $userId, 'lastPageView'])
if (is_int($maxTime)) { ? helper::baseUrl() . $this->getData(['enrolment', $courseId, $userId, 'lastPageView'])
$redirect = helper::baseUrl() . array_search($maxTime, $this->getData(['enrolment', $courseId, $userId, 'history'])); : helper::baseUrl() . $this->getData(['course', $courseId, 'homePageId']);
} else { /*
// Sinon la page d'accueil par défaut du module $essage = $this->getData(['enrolment', $courseId, $userId, 'datePageView'])
$redirect = helper::baseUrl() . $this->getData(['course', $courseId, 'homePageId']); ? $this->getData(['enrolment', $courseId, $userId, 'datePageView'])
} : '';
*/
if ($this->getData(['course', $courseId, 'access']) === self::COURSE_ACCESS_DATE) { if ($this->getData(['course', $courseId, 'access']) === self::COURSE_ACCESS_DATE) {
$to = helper::dateUTF8('%d %B %Y', $this->getData(['course', $courseId, 'closingDate']), self::$i18nUI) . helper::translate(' à ') . helper::dateUTF8('%H:%M', $this->getData(['course', $courseId, 'closingDate']), self::$i18nUI); $to = helper::dateUTF8('%d %B %Y', $this->getData(['course', $courseId, 'closingDate']), self::$i18nUI) . helper::translate(' à ') . helper::dateUTF8('%H:%M', $this->getData(['course', $courseId, 'closingDate']), self::$i18nUI);
$message = sprintf(helper::translate('Ce contenu ferme le %s'), $to); $message .= sprintf(helper::translate('Ce contenu ferme le %s'), $to);
} else { } else {
$message = sprintf(helper::translate('Bienvenue dans l\'espace %s'), $this->getData(['course', $courseId, 'title'])); $message .= sprintf(helper::translate('Bienvenue dans l\'espace %s'), $this->getData(['course', $courseId, 'title']));
} }
$_SESSION['ZWII_SITE_CONTENT'] = $courseId; $_SESSION['ZWII_SITE_CONTENT'] = $courseId;
} }
@ -968,11 +965,21 @@ class course extends common
} }
} }
foreach ($history['history'] as $pageId => $time) { foreach ($history as $pageId => $times) {
if (is_array($times)) {
$d = array();
foreach ($times as $time) {
$d[] = helper::dateUTF8('%d %B %Y - %H:%M:%S', $time);
}
$dates = implode('<br />', $d);
} else {
$dates = helper::dateUTF8('%d %B %Y - %H:%M:%S', $history);
}
self::$userHistory[$pageId] = [ self::$userHistory[$pageId] = [
$pages[$pageId]['number'], $pages[$pageId]['number'],
helper::dateUTF8('%d %B %Y - %H:%M:%S', $time),
$pages[$pageId]['title'], $pages[$pageId]['title'],
$dates,
]; ];
} }

View File

@ -2,7 +2,7 @@
<div class="col1"> <div class="col1">
<?php echo template::button('courseUserHistoryBack', [ <?php echo template::button('courseUserHistoryBack', [
'class' => 'buttonGrey', 'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'course/user/' . $this->getUrl(2), 'href' => helper::baseUrl() . 'course/users/' . $this->getUrl(2),
'value' => template::ico('left') 'value' => template::ico('left')
]); ?> ]); ?>
</div> </div>
@ -17,7 +17,7 @@
<?php if ($module::$userHistory): ?> <?php if ($module::$userHistory): ?>
<div class="row textAlignCenter"> <div class="row textAlignCenter">
<div class="col8"> <div class="col8">
<?php echo template::table([1, 6, 5], $module::$userHistory, ['Ordre', 'Dernière consultation de cette page', 'Titre de la page'], ['id' => 'dataTables']); ?> <?php echo template::table([1, 6, 5], $module::$userHistory, ['Ordre', 'Titre de la page', 'Dernière consultation de cette page'], ['id' => 'dataTables']); ?>
</div> </div>
</div> </div>
<?php else: ?> <?php else: ?>