From d59062cd4649447ec28791d102a673ae3abc04b1 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Sat, 9 Dec 2023 17:45:31 +0100 Subject: [PATCH] Export userHistory --- core/module/course/course.php | 65 +++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/core/module/course/course.php b/core/module/course/course.php index b636504..1b69eaa 100644 --- a/core/module/course/course.php +++ b/core/module/course/course.php @@ -1074,22 +1074,11 @@ class course extends common $courseId = $this->getUrl(2); $userId = $this->getUrl(3); - $history = $this->getData(['enrolment', $courseId, $userId]); + $history = $this->getData(['enrolment', $courseId, $userId, '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']; - - // Dossier temporaire - if (is_dir(self::FILE_DIR . 'source/export') === false) { - mkdir(self::FILE_DIR . 'source/export'); - } - if (is_dir(self::FILE_DIR . 'source/export/' . $courseId) === false) { - mkdir(self::FILE_DIR . 'source/export/' . $courseId); - } - $path = self::FILE_DIR . 'source/export/'; - - $filename = $path . $courseId . '/' . $userId . '.csv'; - - // Exclure les barres et les pages masquées $count = 0; foreach ($data as $pageId => $pageData) { if ($pageData['position'] > 0) { @@ -1100,18 +1089,44 @@ class course extends common ]; } } - $file = fopen($filename, 'w'); - foreach ($history['history'] as $pageId => $time) { - $data = array_map( - 'html_entity_decode', - array( - $pageId, - $pages[$pageId]['title'], - $pages[$pageId]['number'], - helper::dateUTF8('%d %B %Y - %H:%M:%S', $time), - ) - ); + 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 %B %Y %H:%M:%S', $time) + ]; + } + } else { + self::$userHistory[] = [ + $pages[$pageId]['number'], + $pageId, + html_entity_decode($pages[$pageId]['title']), + helper::dateUTF8('%d %B %Y %H:%M:%S', $times) + ]; + } + + + } + + // Dossier temporaire + if (is_dir(self::FILE_DIR . 'source/export') === false) { + mkdir(self::FILE_DIR . 'source/export'); + } + if (is_dir(self::FILE_DIR . 'source/export/' . $courseId) === false) { + mkdir(self::FILE_DIR . 'source/export/' . $courseId); + } + $path = self::FILE_DIR . 'source/export/'; + $filename = $path . $courseId . '/' . $userId . '.csv'; + $file = fopen($filename, 'w'); + + foreach (self::$userHistory as $keys => $values) { + $data = $values; // Écrire la ligne dans le fichier CSV fputcsv($file, $data, ';'); }