Empty storage on submit

This commit is contained in:
Fred Tempez 2023-11-23 13:59:27 +01:00
parent 4d535369cc
commit 4ed8198321
2 changed files with 14 additions and 8 deletions

View File

@ -488,8 +488,10 @@ class course extends common
foreach ($users as $userId => $userValue) { foreach ($users as $userId => $userValue) {
$history = $userValue['history']; $history = $userValue['history'];
$maxTime = max($history); if (!empty($history)) {
$pageId = array_search($maxTime, $history); $maxTime = max($history);
$pageId = array_search($maxTime, $history);
}
// Compte les rôles // Compte les rôles
$profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])]++; $profils[$this->getData(['user', $userId, 'group']) . $this->getData(['user', $userId, 'profil'])]++;
@ -527,11 +529,12 @@ class course extends common
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']),
$pages[$pageId], !empty($history) ? $pages[$pageId] : '-',
helper::dateUTF8('%d %B %Y - %H:%M', $maxTime), !empty($history) ? helper::dateUTF8('%d %B %Y - %H:%M', $maxTime) : '-',
template::button('userHistory' . $userId, [ template::button('userHistory' . $userId, [
'href' => helper::baseUrl() . 'course/userHistory/' . $courseId . '/' . $userId, 'href' => helper::baseUrl() . 'course/userHistory/' . $courseId . '/' . $userId,
'value' => round(($viewPages * 100) / $sumPages, 1) . ' %' 'value' => !empty($history) ? round(($viewPages * 100) / $sumPages, 1) . ' %' : '0%',
'disable' => empty($history)
]), ]),
template::button('userDelete' . $userId, [ template::button('userDelete' . $userId, [
'class' => 'userDelete buttonRed', 'class' => 'userDelete buttonRed',
@ -571,7 +574,8 @@ class course extends common
) { ) {
foreach ($_POST as $keyPost => $valuePost) { foreach ($_POST as $keyPost => $valuePost) {
// Exclure les variables post qui ne sont pas des userId et ne traiter que les non inscrits // Exclure les variables post qui ne sont pas des userId et ne traiter que les non inscrits
if ($this->getData(['user', $keyPost]) !== null if (
$this->getData(['user', $keyPost]) !== null
&& $this->getData(['enrolment', $courseId, $keyPost]) === null && $this->getData(['enrolment', $courseId, $keyPost]) === null
) { ) {
$this->setData(['enrolment', $courseId, $keyPost, 'history', array()]); $this->setData(['enrolment', $courseId, $keyPost, 'history', array()]);

View File

@ -13,7 +13,6 @@
$(document).ready((function () { $(document).ready((function () {
$("#courseFilterGroup, #courseFilterFirstName, #courseFilterLastName").change(function () { $("#courseFilterGroup, #courseFilterFirstName, #courseFilterLastName").change(function () {
saveCheckboxState(); saveCheckboxState();
$("#courseUsersAddForm").submit(); $("#courseUsersAddForm").submit();
@ -45,6 +44,10 @@ $(document).ready((function () {
restoreCheckboxState(); restoreCheckboxState();
}); });
// Empty local storage after submit
$("#courseUsersAddSubmit").on("click", function () {
localStorage.setItem('checkboxState', JSON.stringify({}));
});
// Restore checkbox state on page load // Restore checkbox state on page load
restoreCheckboxState(); restoreCheckboxState();
@ -53,7 +56,6 @@ $(document).ready((function () {
// Récupérer d'abord les données existantes dans le localStorage // Récupérer d'abord les données existantes dans le localStorage
var existingData = JSON.parse(localStorage.getItem('checkboxState')) || {}; var existingData = JSON.parse(localStorage.getItem('checkboxState')) || {};
console.log(existingData);
// Ajouter ou mettre à jour les données actuelles // Ajouter ou mettre à jour les données actuelles
$('.checkboxSelect').each(function () { $('.checkboxSelect').each(function () {