Ecriture dans report sauf dans course à venir

This commit is contained in:
Fred Tempez 2024-04-04 13:14:43 +02:00
parent e58ce9cda0
commit 65029fb191
5 changed files with 12 additions and 10 deletions

View File

@ -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()]);

View File

@ -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));
}

View File

@ -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);

View File

@ -963,6 +963,7 @@ class init extends common
]
]
],
'report' => []
];
public static $siteContent = [

View File

@ -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)) {