From e58ce9cda0b36fc1d3a47bc41203ff012bb3521d Mon Sep 17 00:00:00 2001 From: F TEMPEZ Date: Thu, 4 Apr 2024 11:27:48 +0200 Subject: [PATCH] update : MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit creation des bases de données report dans les espaces avec les historiques des utilisateurs --- core/core.php | 12 +++--- core/include/update.inc.php | 36 +++++++++------- core/module/course/course.php | 42 ++++++++++--------- .../userReport.css} | 0 .../userReport.js.php} | 0 .../userReport.php} | 8 ++-- 6 files changed, 53 insertions(+), 45 deletions(-) rename core/module/course/view/{userHistory/userHistory.css => userReport/userReport.css} (100%) rename core/module/course/view/{userHistory/userHistory.js.php => userReport/userReport.js.php} (100%) rename core/module/course/view/{userHistory/userHistory.php => userReport/userReport.php} (85%) diff --git a/core/core.php b/core/core.php index f7a1dda..0e9b696 100644 --- a/core/core.php +++ b/core/core.php @@ -225,13 +225,13 @@ class common 'language' => '', 'profil' => '', 'category' => '', + 'enrolment' => '', ]; private $contentFiles = [ 'page' => '', 'module' => '', 'theme' => '', - 'enrolment' => '', ]; public static $fontsWebSafe = [ @@ -598,13 +598,13 @@ class common return file_put_contents(self::DATA_DIR . $path . '/content/' . $page . '.html', $value); } - /** + /* * Lire les données des historiques * @param string courseId * @param array $keys Clé(s) des données * @return array tableau demandé - */ - public function getEnrolment($courseId, $keys = []) + */ + public function getReport($courseId, $keys = []) { $data = json_decode(file_get_contents(self::DATA_DIR . $courseId . '/' . 'enrolment.json'), true); @@ -635,11 +635,11 @@ class common * @param string contenu de la page * @return int nombre d'octets écrits ou erreur */ - public function setEnrolement($courseId, $value) + public function setReport($courseId, $value) { return file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); } - + /** diff --git a/core/include/update.inc.php b/core/include/update.inc.php index 4b26f3f..1966614 100644 --- a/core/include/update.inc.php +++ b/core/include/update.inc.php @@ -26,23 +26,29 @@ if ( if ( $this->getData(['core', 'dataVersion']) < 1800 ) { - - // Déplace les incriptions dans les cours - if (file_exists(self::DATA_DIR . 'enrolment.json')) { - $old_enrolment = json_decode(file_get_contents(self::DATA_DIR . 'enrolment.json'), true); - $old_enrolment = $old_enrolment['enrolment']; - foreach ($this->getData(['course']) as $courseId => $courseValues) { - if (array_key_exists($courseId, $old_enrolment)) { - file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode(['enrolment' => [$courseId => $old_enrolment[$courseId]]], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), LOCK_EX); - } else { - // Création d'une structure vide - file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode(['enrolment' => [$courseId => []]], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), LOCK_EX); - } - } - } - unlink(self::DATA_DIR . 'enrolment.json'); + // Déplace les historiques dans les dossiers des esapaces + // Parcourir les espaces + foreach ($this->getData(['course']) as $courseId => $courseValues) { + $data = []; + //Parcourir les participants + foreach ($this->getData(['user']) as $userId => $userValues) { + // Un historique existe pour ce participant + $report = $this->getData(['enrolment', $courseId, $userId, 'history']); + if ( is_array($report) + ) { + // Ecriture dans un fichier report dans le dossier de l'espace + $data = array_merge($data, [$userId => $report]); + // Nettoyage du fichier des inscriptions + // Ce fichier ne contient que l'id du participant et de la date et de l'id de la dernière page vue + //$this->deleteData(['enrolment', $courseId, $userId, 'history']); + } + } + file_put_contents(self::DATA_DIR . $courseId . '/report.json', json_encode(['report' => $data], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), LOCK_EX); + } $this->setData(['core', 'dataVersion', 1800]); + } + /* $t = $this->getEnrolment('6571b5913e87e', ['pablorodriguez', 'history', 'les-titres-ou-headers']); echo"
";
diff --git a/core/module/course/course.php b/core/module/course/course.php
index cc4d2bd..04f12e8 100644
--- a/core/module/course/course.php
+++ b/core/module/course/course.php
@@ -28,8 +28,8 @@ class course extends common
         'usersDelete' => self::GROUP_EDITOR, //Fait
         'usersHistoryExport' => self::GROUP_EDITOR, //fait
         'userDelete' => self::GROUP_EDITOR, //Fait
-        'userHistory' => self::GROUP_EDITOR, //Fait
-        'userHistoryExport' => self::GROUP_EDITOR, //Fait
+        'userReport' => self::GROUP_EDITOR, //Fait
+        'userReportExport' => self::GROUP_EDITOR, //Fait
         'backup' => self::GROUP_EDITOR, // Fait
         'restore' => self::GROUP_EDITOR, //Fait
         'clone' => self::GROUP_ADMIN,
@@ -74,7 +74,7 @@ class course extends common
     public static $pagesList = ['accueil' => 'Accueil'];
 
 
-    public static $userHistory = [];
+    public static $userReport = [];
 
     public static $userGraph = [];
 
@@ -712,8 +712,8 @@ class course extends common
                     ? helper::dateUTF8('%H:%M', $this->getData(['enrolment', $courseId, $userId, 'datePageView']))
                     : '',
                     $this->getData(['user', $userId, 'tags']),
-                    template::button('userHistory' . $userId, [
-                        'href' => helper::baseUrl() . 'course/userHistory/' . $courseId . '/' . $userId,
+                    template::button('userReport' . $userId, [
+                        'href' => helper::baseUrl() . 'course/userReport/' . $courseId . '/' . $userId,
                         'value' => !empty ($userValue['history']) ? min(round(($viewPages * 100) / $sumPages, 1), 100) . ' %' : '0%',
                         'disable' => empty ($userValue['history'])
                     ]),
@@ -1164,7 +1164,7 @@ class course extends common
     /**
      * Liste les pages consultées par un utilisateur
      */
-    public function userHistory()
+    public function userReport()
     {
 
         // Espace sélectionné
@@ -1211,7 +1211,7 @@ class course extends common
             if (isset ($pages[$pageId]['title'])) {
                 $lastView = ($lastView === 0) ? $time : $lastView;
                 $diff = $time - $lastView;
-                self::$userHistory[] = [
+                self::$userReport[] = [
                     html_entity_decode($pages[$pageId]['title']),
                     $time,
                     ($diff < 1800) ? sprintf("%d' %d''", floor($diff / 60), $diff % 60) : "Non significatif",
@@ -1230,16 +1230,16 @@ class course extends common
         }
 
         // Décale les temps de consultation
-        for ($i = 0; $i < count(self::$userHistory) - 1; $i++) {
-            self::$userHistory[$i][2] = self::$userHistory[$i + 1][2];
+        for ($i = 0; $i < count(self::$userReport) - 1; $i++) {
+            self::$userReport[$i][2] = self::$userReport[$i + 1][2];
         }
         // Décale les temps de consultation
         for ($i = 0; $i < count(self::$userGraph) - 1; $i++) {
-            self::$userHistory[$i][1] = self::$userHistory[$i + 1][1];
+            self::$userReport[$i][1] = self::$userReport[$i + 1][1];
         }
 
         // Formate le timestamp
-        array_walk(self::$userHistory, function (&$item) {
+        array_walk(self::$userReport, function (&$item) {
             $item[1] = helper::dateUTF8('%d/%m/%Y %H:%M:%S', $item[1]);
         });
 
@@ -1257,7 +1257,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',
+            'view' => 'userReport',
             'vendor' => [
                 "plotly"
             ]
@@ -1371,7 +1371,7 @@ class course extends common
         }
     }
 
-    public function userHistoryExport()
+    public function userReportExport()
     {
 
         $courseId = $this->getUrl(2);
@@ -1416,7 +1416,7 @@ class course extends common
             if (isset ($pages[$pageId]['title'])) {
                 $lastView = ($lastView === 0) ? $time : $lastView;
                 $diff = $time - $lastView;
-                self::$userHistory[] = [
+                self::$userReport[] = [
                     $pageId,
                     html_entity_decode($pages[$pageId]['title']),
                     $time,
@@ -1429,16 +1429,16 @@ class course extends common
         }
 
         // Décale les temps de consultation
-        for ($i = 0; $i < count(self::$userHistory) - 1; $i++) {
-            self::$userHistory[$i][3] = self::$userHistory[$i + 1][3];
+        for ($i = 0; $i < count(self::$userReport) - 1; $i++) {
+            self::$userReport[$i][3] = self::$userReport[$i + 1][3];
         }
         // Formate le timestamp
-        array_walk(self::$userHistory, function (&$item) {
+        array_walk(self::$userReport, 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);
+        self::$userReport = array_merge([0 => ['PageId', 'Page Titre', 'Consultation Date', 'Temps Consultation']], self::$userReport);
 
         // Dossier d'export
         if (is_dir(self::FILE_DIR . 'source/' . $courseId) === false) {
@@ -1451,7 +1451,7 @@ class course extends common
 
         $file = fopen($filename, 'w');
 
-        foreach (self::$userHistory as $keys => $values) {
+        foreach (self::$userReport as $keys => $values) {
             $data = $values;
             // Écrire la ligne dans le fichier CSV
             fputcsv($file, $data, ';');
@@ -1461,7 +1461,7 @@ class course extends common
 
         // Valeurs en sortie
         $this->addOutput([
-            'redirect' => helper::baseUrl() . 'course/userHistory/' . $courseId . '/' . $userId,
+            'redirect' => helper::baseUrl() . 'course/userReport/' . $courseId . '/' . $userId,
             'notification' => 'Création ' . basename($filename) . ' dans le dossier "Export"',
             'state' => true,
         ]);
@@ -1895,4 +1895,6 @@ class course extends common
         return $r;
     }
 
+
+
 }
\ No newline at end of file
diff --git a/core/module/course/view/userHistory/userHistory.css b/core/module/course/view/userReport/userReport.css
similarity index 100%
rename from core/module/course/view/userHistory/userHistory.css
rename to core/module/course/view/userReport/userReport.css
diff --git a/core/module/course/view/userHistory/userHistory.js.php b/core/module/course/view/userReport/userReport.js.php
similarity index 100%
rename from core/module/course/view/userHistory/userHistory.js.php
rename to core/module/course/view/userReport/userReport.js.php
diff --git a/core/module/course/view/userHistory/userHistory.php b/core/module/course/view/userReport/userReport.php
similarity index 85%
rename from core/module/course/view/userHistory/userHistory.php
rename to core/module/course/view/userReport/userReport.php
index 4eed98d..7f8da46 100644
--- a/core/module/course/view/userHistory/userHistory.php
+++ b/core/module/course/view/userReport/userReport.php
@@ -1,6 +1,6 @@
 
- 'buttonGrey', 'href' => helper::baseUrl() . 'course/users/' . $this->getUrl(2), 'value' => template::ico('left') @@ -8,7 +8,7 @@
helper::baseUrl() . 'course/userHistoryExport/' . $this->getUrl(2) . '/' . $this->getUrl(3), + 'href' => helper::baseUrl() . 'course/userReportExport/' . $this->getUrl(2) . '/' . $this->getUrl(3), 'value' => template::ico('download'), 'help' => 'Exporter', ]) ?> @@ -20,7 +20,7 @@
- +
getData(['course', $this->getUrl(2), 'access']) === self::COURSE_ACCESS_DATE): ?> @@ -46,7 +46,7 @@
- +