From 65029fb191d4cc4875210ba9a1fcaffa58817974 Mon Sep 17 00:00:00 2001 From: F TEMPEZ Date: Thu, 4 Apr 2024 13:14:43 +0200 Subject: [PATCH] =?UTF-8?q?Ecriture=20dans=20report=20sauf=20dans=20course?= =?UTF-8?q?=20=C3=A0=20venir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/class/router.class.php | 6 +++--- core/core.php | 5 +++-- core/include/update.inc.php | 2 +- core/module/install/ressource/defaultdata.php | 1 + core/module/page/page.php | 8 ++++---- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/class/router.class.php b/core/class/router.class.php index 17922c2..e5e5aaa 100644 --- a/core/class/router.class.php +++ b/core/class/router.class.php @@ -423,10 +423,10 @@ class core extends common ) ) { // Stocke l'historique des pages vues - $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)])) + $data = is_array($this->getData(['report', $this->getUser('id'), $this->getUrl(0)])) + ? array_merge([time()], $this->getData(['report', $this->getUser('id'),$this->getUrl(0)])) : [time()]; - $this->setData(['enrolment', self::$siteContent, $this->getUser('id'), 'history', $this->getUrl(0), $data]); + $this->setData(['report', $this->getUser('id'), $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()]); diff --git a/core/core.php b/core/core.php index 0e9b696..592b419 100644 --- a/core/core.php +++ b/core/core.php @@ -232,6 +232,7 @@ class common 'page' => '', 'module' => '', 'theme' => '', + 'report' => '', ]; public static $fontsWebSafe = [ @@ -635,9 +636,9 @@ class common * @param string contenu de la page * @return int nombre d'octets écrits ou erreur */ - public function setReport($courseId, $value) + public function setReport($courseId, $keys = []) { - return file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); + return file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode($keys, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); } diff --git a/core/include/update.inc.php b/core/include/update.inc.php index 1966614..abad670 100644 --- a/core/include/update.inc.php +++ b/core/include/update.inc.php @@ -40,7 +40,7 @@ if ( $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']); + $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); diff --git a/core/module/install/ressource/defaultdata.php b/core/module/install/ressource/defaultdata.php index 2b5c268..54a3280 100644 --- a/core/module/install/ressource/defaultdata.php +++ b/core/module/install/ressource/defaultdata.php @@ -963,6 +963,7 @@ class init extends common ] ] ], + 'report' => [] ]; public static $siteContent = [ diff --git a/core/module/page/page.php b/core/module/page/page.php index b0f18ae..9f548df 100644 --- a/core/module/page/page.php +++ b/core/module/page/page.php @@ -360,16 +360,16 @@ class page extends common } } // Met à jour les historiques des utilisateurs - foreach ($this->getData(['enrolment', self::$siteContent]) as $userId => $userData) { + foreach ($this->getReport(self::$siteContent) as $userId => $userData) { // Vérifier si l'utilisateur a un historique if ( isset($userData["history"]) && isset($userData['history'][$this->getUrl(2)]) ) { // Remplacer l'ancienne ID par la nouvelle - $datas = $this->getData(['enrolment', self::$siteContent, $userId, 'history', $this->getUrl(2)]); - $this->setData(['enrolment', self::$siteContent, $userId, 'history', $pageId, $datas]); - $this->deleteData(['enrolment', self::$siteContent, $userId, 'history', $this->getUrl(2)]); + $datas = $this->getReport([self::$siteContent, [ $userId, $this->getUrl(2)]]); + $this->setReport(self::$siteContent, [$userId, $pageId, $datas]); + $this->deleteData(['report', $userId,$this->getUrl(2)]); } // Mettre à jour la dernière page vue si nécessaire if ($this->getData(['enrolment', self::$siteContent, $userId, 'lastPageView']) === $this->getUrl(2)) {