Edit and Delete course

This commit is contained in:
Fred Tempez 2023-09-12 22:16:25 +02:00
parent c21214fe44
commit 6af831a87c
7 changed files with 260 additions and 9 deletions

View File

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

View File

@ -51,13 +51,13 @@
</div>
<div class="col4">
<?php echo template::date('courseOpeningDate', [
'type' => 'date',
'type' => 'datetime-local',
'label' => 'Ouverture',
]); ?>
</div>
<div class="col4">
<?php echo template::date('courseClosingDate', [
'type' => 'date',
'type' => 'datetime-local',
'label' => 'Fermeture',
]); ?>
</div>

View File

@ -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 <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @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
*/

View File

@ -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 <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @authorFrédéric Tempez <frederic.tempez@outlook.com>
* @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());
});

View File

@ -0,0 +1,88 @@
<?php echo template::formOpen('courseEditForm'); ?>
<div class="row">
<div class="col1">
<?php echo template::button('courseEditBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'course',
'value' => template::ico('left')
]); ?>
</div>
<div class="col2 offset9">
<?php echo template::submit('courseEditSubmit'); ?>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>
<?php echo helper::translate('Paramètres'); ?>
</h4>
<div class="row">
<div class="col12">
<?php echo template::text('courseEditTitle', [
'label' => 'Titre',
'value' => $this->getdata(['course', $this->getUrl(2), 'title'])
]); ?>
</div>
</div>
<div class="row">
<div class="col7">
<?php echo template::text('courseEditShortTitle', [
'label' => 'Titre court',
'value' => $this->getdata(['course', $this->getUrl(2), 'shortTitle'])
]); ?>
</div>
<div class="col5">
<?php echo template::select('courseEditAuthor', $module::$courseTeachers, [
'label' => 'Auteur',
'value' => $this->getdata(['course', $this->getUrl(2), 'author'])
]); ?>
</div>
</div>
<div class="row">
<div class="col12">
<?php echo template::textarea('courseEditDescription', [
'label' => 'Description',
'value' => $this->getdata(['course', $this->getUrl(2), 'description'])
]); ?>
</div>
</div>
<div class="row">
<div class="col4">
<?php echo template::select('courseEditAccess', $module::$courseAccess, [
'label' => 'Accès',
'selected' => $this->getdata(['course', $this->getUrl(2), 'access'])
]); ?>
</div>
<div class="col4">
<?php echo template::date('courseOpeningDate', [
'type' => 'datetime-local',
'label' => 'Ouverture',
'value' => is_null($this->getdata(['course', $this->getUrl(2), 'openingDate'])) ? '' :floor($this->getdata(['course', $this->getUrl(2), 'openingDate']) / 60) * 60
]); ?>
</div>
<div class="col4">
<?php echo template::date('courseClosingDate', [
'type' => 'datetime-local',
'label' => 'Fermeture',
'value' => is_null($this->getdata(['course', $this->getUrl(2), 'closingDate'])) ? '' : floor($this->getdata(['course', $this->getUrl(2), 'closingDate']) / 60) * 60
]); ?>
</div>
</div>
<div class="row">
<div class="col6">
<?php echo template::select('courseEditEnrolment', $module::$courseEnrolment, [
'label' => 'Inscription',
'selected' => $this->getdata(['course', $this->getUrl(2), 'enrolment'])
]); ?>
</div>
<div class="col6">
<?php echo template::text('courseEditEnrolmentKey', [
'label' => 'Clé',
'value' => $this->getdata(['course', $this->getUrl(2), 'enrolmentKey'])
]); ?>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>

View File

@ -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 <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @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 = "<?php echo helper::translate('Supprimer ce cours ?'); ?>";
return core.confirm(message, function () {
$(location).attr("href", _this.attr("href"));
});
});
});

View File

@ -14,3 +14,4 @@
]); ?>
</div>
</div>
<?php echo template::table([3 , 3, 4, 1, 1], $module::$courses, ['Titre court', 'Auteur', 'Description', '', '']); ?>