Edit and Delete course
This commit is contained in:
parent
c21214fe44
commit
6af831a87c
@ -17,9 +17,10 @@ class course extends common
|
|||||||
{
|
{
|
||||||
|
|
||||||
public static $actions = [
|
public static $actions = [
|
||||||
'index' => self::GROUP_TEACHER,
|
'index' => self::GROUP_ADMIN,
|
||||||
|
'edit' => self::GROUP_ADMIN,
|
||||||
'add' => self::GROUP_ADMIN,
|
'add' => self::GROUP_ADMIN,
|
||||||
//
|
'delete' => self::GROUP_ADMIN,
|
||||||
'swap' => self::GROUP_VISITOR,
|
'swap' => self::GROUP_VISITOR,
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -31,15 +32,38 @@ class course extends common
|
|||||||
|
|
||||||
public static $courseEnrolment = [
|
public static $courseEnrolment = [
|
||||||
0 => 'Anonyme',
|
0 => 'Anonyme',
|
||||||
1 => 'Auto-inscrition',
|
1 => 'Auto-inscrition libre',
|
||||||
2 => 'Auto-inscription avec clé',
|
2 => 'Auto-inscription avec clé',
|
||||||
3 => 'Manuelle'
|
3 => 'Manuelle'
|
||||||
];
|
];
|
||||||
|
|
||||||
public static $courseTeachers = [];
|
public static $courseTeachers = [];
|
||||||
|
|
||||||
|
public static $courses = [];
|
||||||
|
|
||||||
public function index()
|
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
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'title' => helper::translate('Cours'),
|
'title' => helper::translate('Cours'),
|
||||||
@ -80,8 +104,6 @@ class course extends common
|
|||||||
// BDD des inscrits
|
// BDD des inscrits
|
||||||
file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode(array()));
|
file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode(array()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'redirect' => helper::baseUrl() . 'course',
|
'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
|
* Traitement du changement de langue
|
||||||
* Fonction utilisée par le noyau
|
* Fonction utilisée par le noyau
|
||||||
|
@ -51,13 +51,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col4">
|
<div class="col4">
|
||||||
<?php echo template::date('courseOpeningDate', [
|
<?php echo template::date('courseOpeningDate', [
|
||||||
'type' => 'date',
|
'type' => 'datetime-local',
|
||||||
'label' => 'Ouverture',
|
'label' => 'Ouverture',
|
||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="col4">
|
<div class="col4">
|
||||||
<?php echo template::date('courseClosingDate', [
|
<?php echo template::date('courseClosingDate', [
|
||||||
'type' => 'date',
|
'type' => 'datetime-local',
|
||||||
'label' => 'Fermeture',
|
'label' => 'Fermeture',
|
||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
|
18
core/module/course/view/edit/edit.css
Normal file
18
core/module/course/view/edit/edit.css
Normal 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
|
||||||
|
*/
|
20
core/module/course/view/edit/edit.js.php
Normal file
20
core/module/course/view/edit/edit.js.php
Normal 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());
|
||||||
|
});
|
88
core/module/course/view/edit/edit.php
Normal file
88
core/module/course/view/edit/edit.php
Normal 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(); ?>
|
25
core/module/course/view/index/index.js.php
Normal file
25
core/module/course/view/index/index.js.php
Normal 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"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -14,3 +14,4 @@
|
|||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php echo template::table([3 , 3, 4, 1, 1], $module::$courses, ['Titre court', 'Auteur', 'Description', '', '']); ?>
|
Loading…
Reference in New Issue
Block a user