From 6af831a87c213bdf02ebe4cd8ea7cf536f5a74ed Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Tue, 12 Sep 2023 22:16:25 +0200 Subject: [PATCH] Edit and Delete course --- core/module/course/course.php | 111 +++++++++++++++++++-- core/module/course/view/add/add.php | 4 +- core/module/course/view/edit/edit.css | 18 ++++ core/module/course/view/edit/edit.js.php | 20 ++++ core/module/course/view/edit/edit.php | 88 ++++++++++++++++ core/module/course/view/index/index.js.php | 25 +++++ core/module/course/view/index/index.php | 3 +- 7 files changed, 260 insertions(+), 9 deletions(-) create mode 100644 core/module/course/view/edit/edit.css create mode 100644 core/module/course/view/edit/edit.js.php create mode 100644 core/module/course/view/edit/edit.php create mode 100644 core/module/course/view/index/index.js.php diff --git a/core/module/course/course.php b/core/module/course/course.php index 6b6eabf..a221402 100644 --- a/core/module/course/course.php +++ b/core/module/course/course.php @@ -17,9 +17,10 @@ class course extends common { public static $actions = [ - 'index' => self::GROUP_TEACHER, + 'index' => self::GROUP_ADMIN, + 'edit' => self::GROUP_ADMIN, 'add' => self::GROUP_ADMIN, - // + 'delete' => self::GROUP_ADMIN, 'swap' => self::GROUP_VISITOR, ]; @@ -31,15 +32,38 @@ class course extends common public static $courseEnrolment = [ 0 => 'Anonyme', - 1 => 'Auto-inscrition', + 1 => 'Auto-inscrition libre', 2 => 'Auto-inscription avec clé', 3 => 'Manuelle' ]; public static $courseTeachers = []; + public static $courses = []; + public function index() { + $courseIdShortTitle = helper::arrayColumn($this->getData(['course']), 'shortTitle'); + ksort( $courseIdShortTitle); + foreach ($courseIdShortTitle as $courseId => $courseTitle) { + self::$courses[] = [ + $courseTitle, + $this->getData(['course', $courseId, 'author']), + $this->getData(['course', $courseId, 'description']), + template::button('courseEdit' . $courseId, [ + 'href' => helper::baseUrl() . 'course/edit/' . $courseId, + 'value' => template::ico('pencil'), + 'help' => 'Éditer' + ]), + template::button('courseDelete' . $courseId, [ + 'class' => 'courseDelete buttonRed', + 'href' => helper::baseUrl() . 'course/delete/' . $courseId, + 'value' => template::ico('trash'), + 'help' => 'Supprimer' + ]) + + ]; + } // Valeurs en sortie $this->addOutput([ 'title' => helper::translate('Cours'), @@ -80,8 +104,6 @@ class course extends common // BDD des inscrits file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode(array())); - - // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . 'course', @@ -105,6 +127,83 @@ class course extends common ]); } + public function delete() { + + if ( + $this->getUser('permission', __CLASS__, __FUNCTION__) !== true || + // Le cours n'existe pas + $this->getData(['course', $this->getUrl(2)]) === null + // Groupe insuffisant + and ($this->getUrl('group') < self::GROUP_TEACHER) + ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + // Suppression + } else { + $this->deleteData(['course', $this->getUrl(2)]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . 'course', + 'notification' => helper::translate('Cours supprimé'), + 'state' => true + ]); + } + + } + + /** + * Edite un cours + */ + public function edit() + { + + // Soumission du formulaire + if ( + $this->getUser('permission', __CLASS__, __FUNCTION__) === true && + $this->isPost() + ) { + $courseId = $this->getUrl(2); + $this->setData([ + 'course', + $courseId, + [ + 'title' => $this->getInput('courseEditTitle', helper::FILTER_STRING_SHORT, true), + 'shortTitle' => $this->getInput('courseEditShortTitle', helper::FILTER_STRING_SHORT, true), + 'author' => $this->getInput('courseEditAuthor'), + 'description' => $this->getInput('courseEditDescription', helper::FILTER_STRING_SHORT, true), + 'access' => $this->getInput('courseEditAccess'), + 'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME), + 'closingDate' => $this->getInput('courseClosingDate', helper::FILTER_DATETIME), + 'enrolment' => $this->getInput('courseEditEnrolment'), + 'enrolmentKey' => $this->getInput('courseEditEnrolmentKey'), + ] + ]); + + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . 'course', + 'notification' => helper::translate('Cours édité'), + 'state' => true + ]); + } + + // Liste des enseignants pour le sélecteur d'auteurs + $teachers = $this->getData(['user']); + foreach ($teachers as $teacherId => $teacherInfo) { + if ($teacherInfo["group"] >= 2) { + self::$courseTeachers[$teacherId] = $teacherInfo["firstname"] . ' ' . $teacherInfo["lastname"]; + } + } + + // Valeurs en sortie + $this->addOutput([ + 'title' => helper::translate('Editer un cours'), + 'view' => 'edit' + ]); + } + /* * Traitement du changement de langue * Fonction utilisée par le noyau @@ -116,7 +215,7 @@ class course extends common if ( // home n'est pas présent dans la base de donénes des cours $courseId === 'home' || - ( is_dir(self::DATA_DIR . $courseId) && + (is_dir(self::DATA_DIR . $courseId) && $this->getData(['course', $courseId])) ) { // Stocker la sélection diff --git a/core/module/course/view/add/add.php b/core/module/course/view/add/add.php index f373109..dcc42c5 100644 --- a/core/module/course/view/add/add.php +++ b/core/module/course/view/add/add.php @@ -51,13 +51,13 @@
'date', + 'type' => 'datetime-local', 'label' => 'Ouverture', ]); ?>
'date', + 'type' => 'datetime-local', 'label' => 'Fermeture', ]); ?>
diff --git a/core/module/course/view/edit/edit.css b/core/module/course/view/edit/edit.css new file mode 100644 index 0000000..ec84629 --- /dev/null +++ b/core/module/course/view/edit/edit.css @@ -0,0 +1,18 @@ +/** + * 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 Rémi Jean + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @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/ + */ + + +/** NE PAS EFFACER +* admin.css +*/ \ No newline at end of file diff --git a/core/module/course/view/edit/edit.js.php b/core/module/course/view/edit/edit.js.php new file mode 100644 index 0000000..bdba684 --- /dev/null +++ b/core/module/course/view/edit/edit.js.php @@ -0,0 +1,20 @@ +/** + * 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 Rémi Jean + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @authorFrédéric Tempez + * @copyright Copyright (C) 2018-2023, Frédéric Tempez + * @license CC Attribution-NonCommercial-NoDerivatives 4.0 International + * @link http://zwiicms.fr/ + */ + +/** + * Duplication du champ Title dans Short title + */ +$("#courseAddTitle").on("input", function() { + $("#courseAddShortTitle").val($(this).val()); +}); \ No newline at end of file diff --git a/core/module/course/view/edit/edit.php b/core/module/course/view/edit/edit.php new file mode 100644 index 0000000..4088c72 --- /dev/null +++ b/core/module/course/view/edit/edit.php @@ -0,0 +1,88 @@ + +
+
+ 'buttonGrey', + 'href' => helper::baseUrl() . 'course', + 'value' => template::ico('left') + ]); ?> +
+
+ +
+
+
+
+
+

+ +

+
+
+ 'Titre', + 'value' => $this->getdata(['course', $this->getUrl(2), 'title']) + ]); ?> +
+
+
+
+ 'Titre court', + 'value' => $this->getdata(['course', $this->getUrl(2), 'shortTitle']) + ]); ?> +
+
+ 'Auteur', + 'value' => $this->getdata(['course', $this->getUrl(2), 'author']) + ]); ?> +
+
+
+
+ 'Description', + 'value' => $this->getdata(['course', $this->getUrl(2), 'description']) + ]); ?> +
+
+
+
+ 'Accès', + 'selected' => $this->getdata(['course', $this->getUrl(2), 'access']) + ]); ?> +
+
+ 'datetime-local', + 'label' => 'Ouverture', + 'value' => is_null($this->getdata(['course', $this->getUrl(2), 'openingDate'])) ? '' :floor($this->getdata(['course', $this->getUrl(2), 'openingDate']) / 60) * 60 + ]); ?> +
+
+ 'datetime-local', + 'label' => 'Fermeture', + 'value' => is_null($this->getdata(['course', $this->getUrl(2), 'closingDate'])) ? '' : floor($this->getdata(['course', $this->getUrl(2), 'closingDate']) / 60) * 60 + ]); ?> +
+
+
+
+ 'Inscription', + 'selected' => $this->getdata(['course', $this->getUrl(2), 'enrolment']) + ]); ?> +
+
+ 'Clé', + 'value' => $this->getdata(['course', $this->getUrl(2), 'enrolmentKey']) + ]); ?> +
+
+
+
+ \ No newline at end of file diff --git a/core/module/course/view/index/index.js.php b/core/module/course/view/index/index.js.php new file mode 100644 index 0000000..bbd1649 --- /dev/null +++ b/core/module/course/view/index/index.js.php @@ -0,0 +1,25 @@ +/** + * 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 Rémi Jean + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @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/ + */ + +$(document).ready(function () { + /** + * Confirmation de suppression + */ + $(".courseDelete").on("click", function () { + var _this = $(this); + var message = ""; + return core.confirm(message, function () { + $(location).attr("href", _this.attr("href")); + }); + }); +}); \ No newline at end of file diff --git a/core/module/course/view/index/index.php b/core/module/course/view/index/index.php index 77ef37f..6cc940d 100644 --- a/core/module/course/view/index/index.php +++ b/core/module/course/view/index/index.php @@ -13,4 +13,5 @@ 'value' => template::ico('plus') ]); ?>
- \ No newline at end of file + + \ No newline at end of file