From 033528c50ba3dffd7fdd96d2893097c58a1adb13 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Fri, 22 Sep 2023 19:33:03 +0200 Subject: [PATCH] Changement de cours WIP --- core/core.php | 11 +-- core/module/course/course.php | 84 +++++++++++++++---- .../view/{change/change.css => swap/swap.css} | 32 +++---- .../view/{change/change.php => swap/swap.php} | 52 ++++++------ 4 files changed, 114 insertions(+), 65 deletions(-) rename core/module/course/view/{change/change.css => swap/swap.css} (96%) rename core/module/course/view/{change/change.php => swap/swap.php} (91%) diff --git a/core/core.php b/core/core.php index d69ce43..bfaf479 100644 --- a/core/core.php +++ b/core/core.php @@ -1466,15 +1466,13 @@ class common $r = in_array($userId, array_keys($this->getData(['enrolment', $courseId]))); break; case self::GROUP_MEMBER: - $r = $this->courseIsAvailable($courseId) && - (in_array($userId, array_keys($this->getData(['enrolment', $courseId]))) || - $this->getData(['course', $courseId, 'enrolment']) <= self::COURSE_ENROLMENT_SELF); + $r = in_array($userId, array_keys($this->getData(['enrolment', $courseId]))) && + $this->getData(['course', $courseId, 'enrolment']) <= self::COURSE_ENROLMENT_SELF; break; // Visiteur non connecté case self::GROUP_VISITOR: case false: - $r = $this->courseIsAvailable($courseId) && - $this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST; + $r = $this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST; break; default: $r = false; @@ -1489,6 +1487,9 @@ class common */ public function courseIsAvailable($courseId) { + if ($courseId === 'home') { + return true; + } $access = $this->getData(['course', $courseId, 'access']); switch ($access) { case self::COURSE_ACCESS_OPEN: diff --git a/core/module/course/course.php b/core/module/course/course.php index 6ecbca1..2217b39 100644 --- a/core/module/course/course.php +++ b/core/module/course/course.php @@ -22,7 +22,6 @@ class course extends common 'add' => self::GROUP_ADMIN, 'delete' => self::GROUP_ADMIN, 'swap' => self::GROUP_VISITOR, - 'change' => self::GROUP_VISITOR, ]; public static $courseAccess = [ @@ -42,7 +41,7 @@ class course extends common public static $courses = []; - public static $changeMessages = []; + public static $swapMessage = ''; public function index() @@ -243,10 +242,10 @@ class course extends common // Bouton de connexion ou d'inscription // C'est un prof ou un admin - self::$changeMessages = $this->getUser('group') >= self::GROUP_EDITOR - ? 'Se connecter' - // C'est un étudiant ou un visiteur - : ''; + self::$changeMessages = $this->getUser('group') >= self::GROUP_EDITOR + ? 'Se connecter' + // C'est un étudiant ou un visiteur + : ''; // Valeurs en sortie $this->addOutput([ @@ -266,21 +265,70 @@ class course extends common // Cours sélectionnée $courseId = $this->getUrl(2); - if ( - // home n'est pas présent dans la base de données des cours - $courseId === 'home' || - // Contrôle la validité du cours demandé - (is_dir(self::DATA_DIR . $courseId) && - $this->getData(['course', $courseId])) - ) { - // Stocker la sélection + // Le cours est disponible ? + if ($courseId === 'home') { $_SESSION['ZWII_SITE_CONTENT'] = $courseId; + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl(), + ]); + } elseif ($this->courseIsAvailable($courseId) === false) { + $message = 'Ce cours est fermé.'; + if ($this->getData(['course', $courseId, 'access']) === self::COURSE_ACCESS_DATE) { + $from = helper::dateUTF8('%m %B %Y', $this->getData(['course', $courseId, 'openingDate'])) . helper::translate(' à ') . helper::dateUTF8('%H:%M', $this->getData(['course', $courseId, 'openingDate'])); + $to = helper::dateUTF8('%m %B %Y', $this->getData(['course', $courseId, 'closingDate'])) . helper::translate(' à ') . helper::dateUTF8('%H:%M', $this->getData(['course', $courseId, 'closingDate'])); + $message = sprintf(helper::translate('Ce cours ouvre le
%s
et ferme le %s'), $from, $to); + } + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl(), + 'notification' => helper::translate($message), + 'state' => false, + ]); } - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() - ]); + // Soumission du formulaire + if ( + $this->isPost() + ) { + if ( + // Contrôle la validité du cours demandé + (is_dir(self::DATA_DIR . $courseId) && + $this->getData(['course', $courseId])) + ) { + // Stocker la sélection + $_SESSION['ZWII_SITE_CONTENT'] = $courseId; + } + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() + ]); + } else { + + // Génération du message d'inscription + $userId = $this->getUser('id'); + // L'étudiant est-il inscrit + self::$swapMessage = 'Se connecter'; + if ($this->courseUserEnrolment($courseId, $userId) === false) { + // Inscription libre + if ($this->getData(['course', $courseId, 'enrolment']) <= self::COURSE_ENROLMENT_SELF) { + self::$swapMessage = helper::translate('S\'inscrire'); + } + + } + + // Valeurs en sortie + $this->addOutput([ + 'title' => sprintf(helper::translate('Accéder au cours %s'), $this->getData(['course', $this->getUrl(2), 'shortTitle'])), + 'view' => 'swap', + 'display' => self::DISPLAY_LAYOUT_LIGHT, + ]); + } + + + + + } diff --git a/core/module/course/view/change/change.css b/core/module/course/view/swap/swap.css similarity index 96% rename from core/module/course/view/change/change.css rename to core/module/course/view/swap/swap.css index f28e78e..e879c55 100644 --- a/core/module/course/view/change/change.css +++ b/core/module/course/view/swap/swap.css @@ -1,16 +1,16 @@ -/** - * This file is part of Zwii. - * For full copyright and license information, please see the LICENSE - * file that was distributed with this source code. - * - * @author Frédéric Tempez - * @copyright Copyright (C) 2018-2023, Frédéric Tempez - * @license CC Attribution-NonCommercial-NoDerivatives 4.0 International - * @link http://zwiicms.fr/ - */ - - /** @import url("site/data/admin.css"); */ - -/** NE PAS EFFACER -* admin.css -*/ +/** + * This file is part of Zwii. + * For full copyright and license information, please see the LICENSE + * file that was distributed with this source code. + * + * @author Frédéric Tempez + * @copyright Copyright (C) 2018-2023, Frédéric Tempez + * @license CC Attribution-NonCommercial-NoDerivatives 4.0 International + * @link http://zwiicms.fr/ + */ + + /** @import url("site/data/admin.css"); */ + +/** NE PAS EFFACER +* admin.css +*/ diff --git a/core/module/course/view/change/change.php b/core/module/course/view/swap/swap.php similarity index 91% rename from core/module/course/view/change/change.php rename to core/module/course/view/swap/swap.php index 2c077b8..1326386 100644 --- a/core/module/course/view/change/change.php +++ b/core/module/course/view/swap/swap.php @@ -1,27 +1,27 @@ - -
-
- Auteur : " . $this->getData(['course', $this->getUrl(2), 'author' ]) . ""; ?> - Description : " . $this->getData(['course', $this->getUrl(2), 'description' ]) . "

"; ?> - Disponibilité : " . $module::$courseAccess[$this->getData(['course', $this->getUrl(2), 'access' ])] . "

";?> - Inscription : " . $module::$courseEnrolment[$this->getData(['course', $this->getUrl(2), 'enrolment' ])]. "

";?> - -
-
-
-
- helper::baseUrl(), - 'value' => template::ico('left') - ]); ?> -
-
- 'Se connecter', - 'disabled' => !$this->courseIsAvailable($this->getUrl(2)), - 'ico' => '' - ]); ?> -
-
- + +
+
+ Auteur : " . $this->getData(['course', $this->getUrl(2), 'author' ]) . ""; ?> + Description : " . $this->getData(['course', $this->getUrl(2), 'description' ]) . "

"; ?> + Disponibilité : " . $module::$courseAccess[$this->getData(['course', $this->getUrl(2), 'access' ])] . "

";?> + Inscription : " . $module::$courseEnrolment[$this->getData(['course', $this->getUrl(2), 'enrolment' ])]. "

";?> + +
+
+
+
+ helper::baseUrl(), + 'value' => template::ico('left') + ]); ?> +
+
+ $module::$swapMessage, + 'disabled' => !$this->courseIsAvailable($this->getUrl(2)), + 'ico' => '' + ]); ?> +
+
+ \ No newline at end of file