New suppression de catégorie

This commit is contained in:
Fred Tempez 2023-10-04 21:05:39 +02:00
parent b4fafd6891
commit e7129e3c66
8 changed files with 158 additions and 8 deletions

View File

@ -25,6 +25,8 @@ class course extends common
'delete' => self::GROUP_ADMIN,
'category' => self::GROUP_ADMIN,
'categoryAdd' => self::GROUP_ADMIN,
'categoryDelete' => self::GROUP_ADMIN,
'user' => self::GROUP_ADMIN,
];
public static $courseAccess = [
@ -249,7 +251,7 @@ class course extends common
} else {
// Active l'accueil
$_SESSION['ZWII_SITE_CONTENT'] = 'home';
// ET efface la structure
if (is_dir(self::DATA_DIR . $courseId)) {
$success = $this->deleteDir(self::DATA_DIR . $courseId);
@ -278,13 +280,13 @@ class course extends common
self::$courseCategories[] = [
$categoryId,
$categoryTitle,
template::button('courseEdit' . $categoryId, [
template::button('categoryEdit' . $categoryId, [
'href' => helper::baseUrl() . 'course/categoryEdit/' . $categoryId,
'value' => template::ico('pencil'),
'help' => 'Éditer'
]),
template::button('courseDelete' . $categoryId, [
'class' => 'courseDelete buttonRed',
'class' => 'categoryDelete buttonRed',
'href' => helper::baseUrl() . 'course/categoryDelete/' . $categoryId,
'value' => template::ico('trash'),
'help' => 'Supprimer'
@ -298,6 +300,57 @@ class course extends common
]);
}
public function categoryAdd()
{
// Soumission du formulaire
if (
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
$categoryId = $this->getInput('categoryAddTitle', helper::FILTER_ID, true);
$this->setData([
'category',
$categoryId,
$this->getInput('categoryAddTitle', helper::FILTER_STRING_SHORT, true)
]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'course/category',
'notification' => helper::translate('Catégorie créée'),
'state' => true
]);
}
// Valeurs en sortie
$this->addOutput([
'title' => helper::translate('Ajouter une catégorie'),
'view' => 'categoryAdd'
]);
}
public function categoryDelete()
{
$categories = helper::arrayColumn($this->getData(['course']), 'category', 'SORT_ASC');
$courseId = $this->getUrl(2);
$message = helper::translate('Une catégorie affectée ne peut pas être effacée');
$state = false;
if (in_array($courseId, $categories) === false) {
$this->deleteData(['category', $this->getUrl(2)]);
// Valeurs en sortie
$message = helper::translate('Catégorie effacée');
$state = true;
}
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'course/category',
'notification' => $message,
'state' => $state
]);
}
/*
* Traitement du changement de langue
*/

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
*/
$(".categoryDelete").on("click", function () {
var _this = $(this);
var message = "<?php echo helper::translate('Supprimer cette catégorie ?'); ?>";
return core.confirm(message, function () {
$(location).attr("href", _this.attr("href"));
});
});
});

View File

@ -9,7 +9,7 @@
<div class="col1 offset10">
<?php echo template::button('courseCategoryModulesAdd', [
'class' => 'buttonGreen',
'href' => helper::baseUrl() . 'courseCategoryadd',
'href' => helper::baseUrl() . 'course/categoryAdd',
'value' => template::ico('plus')
]); ?>
</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,29 @@
<?php echo template::formOpen('categoryAddForm'); ?>
<div class="row">
<div class="col1">
<?php echo template::button('categoryAddBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'course/category',
'value' => template::ico('left')
]); ?>
</div>
<div class="col2 offset9">
<?php echo template::submit('categoryAddSubmit'); ?>
</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('categoryAddTitle', [
'label' => 'Nom de la catégorie'
]); ?>
</div>
</div>
</div>
</div>
</div>

View File

@ -1,20 +1,27 @@
<div class="row">
<div class="col1">
<?php echo template::button('courseModulesBack', [
<?php echo template::button('courseBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . $this->getUrl(2),
'value' => template::ico('left')
]); ?>
</div>
<div class="col1 offset9">
<?php echo template::button('courseGroup', [
<div class="col1 offset8">
<?php echo template::button('courseUser', [
'href' => helper::baseUrl() . 'course/user',
'value' => template::ico('users'),
'help' => 'Etudiants inscrits'
]); ?>
</div>
<div class="col1">
<?php echo template::button('courseCategory', [
'href' => helper::baseUrl() . 'course/category',
'value' => template::ico('table'),
'help' => 'Catégories de cours'
]); ?>
</div>
<div class="col1 ">
<?php echo template::button('courseModulesAdd', [
<?php echo template::button('courseAdd', [
'class' => 'buttonGreen',
'href' => helper::baseUrl() . 'course/add',
'value' => template::ico('plus')

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