ZwiiCampus/module/workshop/workshop.php

178 lines
6.4 KiB
PHP
Raw Normal View History

2023-10-19 11:41:54 +02:00
<?php
/**
* 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>
2024-01-14 19:31:22 +01:00
* @copyright Copyright (C) 2018-2024, Frédéric Tempez
2023-10-19 11:41:54 +02:00
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
*/
class workshop extends common
2023-10-19 11:41:54 +02:00
{
const VERSION = '1.01';
const REALNAME = 'Liste des espaces';
2023-10-19 11:41:54 +02:00
const DATADIRECTORY = ''; // Contenu localisé inclus par défaut (page.json et module.json)
public static $actions = [
'config' => self::GROUP_ADMIN,
'index' => self::GROUP_VISITOR
];
public static $courseCategories = [
'all' => 'Toutes les catégories'
];
public static $coursesLayout = [
2023-11-15 18:06:49 +01:00
12 => 'Un contenu par ligne',
6 => 'Deux contenu par ligne',
4 => 'Trois contenu par ligne',
3 => 'Quatre contenu par ligne',
2 => 'Six contenu par ligne',
2023-10-19 11:41:54 +02:00
];
2023-10-19 22:48:57 +02:00
public static $coursesAccess = [];
2023-10-19 13:47:36 +02:00
2023-10-19 22:48:57 +02:00
public static $coursesEnrolment = [];
2023-10-19 13:47:36 +02:00
2023-10-19 22:48:57 +02:00
public static $default = [
'config' => array(
'category' => 'general',
'title' => true,
'author' => true,
'description' => true,
'access' => true,
'enrolment' => true,
'layout' => 6,
'template' => true,
'unsuscribe' => false,
2023-10-19 22:48:57 +02:00
),
'caption' => array(
'accessopen' => 'Ouvert',
'accessdate' => 'P&eacute;riode d&#039;ouverture du %s au %s',
'accessclose' => 'Ferm&eacute;',
'enrolguest' => 'Anonyme',
'enrolself' => 'Membres',
'enrolselfkey' => 'Membres avec cl&eacute;',
2023-11-25 14:36:49 +01:00
'enrolMandatory' => 'Inscription par l\'enseignant',
'url' => 'Acc&eacute;der au contenu',
'unsuscribe' => 'Me d&eacute;sinscrire',
'enrolmentLimit' => 'Date limite des inscriptions',
2023-10-19 22:48:57 +02:00
)
];
2023-10-19 13:47:36 +02:00
2023-10-19 11:41:54 +02:00
/**
* Configuration
*/
public function config()
{
2023-10-19 22:48:57 +02:00
// Contrôle de la configuration par défaut
$this->update();
2023-10-19 11:41:54 +02:00
// Soumission du formulaire
if (
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
$this->setData([
'module',
$this->getUrl(0),
'config',
[
'category' => $this->getInput('coursesConfigCategories'),
'title' => $this->getInput('coursesConfigShowTitle', helper::FILTER_BOOLEAN),
'author' => $this->getInput('coursesConfigShowAuthor', helper::FILTER_BOOLEAN),
'description' => $this->getInput('coursesConfigShowDescription', helper::FILTER_BOOLEAN),
'unsuscribe'=> $this->getInput('coursesConfigShowUnsuscribe', helper::FILTER_BOOLEAN),
2023-10-19 11:41:54 +02:00
'access' => $this->getInput('coursesConfigShowAccess', helper::FILTER_BOOLEAN),
'openingdate' => $this->getInput('coursesConfigShowOpeningDate', helper::FILTER_BOOLEAN),
'closingdate' => $this->getInput('coursesConfigShowClosingDate', helper::FILTER_BOOLEAN),
2023-10-19 11:41:54 +02:00
'enrolment' => $this->getInput('coursesConfigShowEnrolment', helper::FILTER_BOOLEAN),
2023-10-19 15:27:57 +02:00
'caption' => $this->getInput('coursesConfigCaption', helper::FILTER_STRING_SHORT),
2023-10-19 11:41:54 +02:00
'layout' => $this->getInput('coursesConfigLayout', helper::FILTER_INT),
'template' => $this->getInput('coursesConfigTemplate', helper::FILTER_BOOLEAN),
]
]);
2023-10-19 22:48:57 +02:00
$this->setData([
'module',
$this->getUrl(0),
'caption',
[
'accessopen' => $this->getInput('coursesCaptionAccessOpen', helper::FILTER_STRING_SHORT),
'accessdate' => $this->getInput('coursesCaptionAccessDate', helper::FILTER_STRING_SHORT),
'accessclose' => $this->getInput('coursesCaptionAccessClose', helper::FILTER_STRING_SHORT),
'enrolguest' => $this->getInput('coursesCaptionGuest', helper::FILTER_STRING_SHORT),
'enrolself' => $this->getInput('coursesCaptionSelf', helper::FILTER_STRING_SHORT),
'enrolselfkey' => $this->getInput('coursesCaptionSelfKey', helper::FILTER_STRING_SHORT),
2023-11-25 14:36:49 +01:00
'enrolMandatory' => $this->getInput('coursesCaptionMandatory', helper::FILTER_STRING_SHORT),
2023-10-19 22:48:57 +02:00
'url' => $this->getInput('coursesCaptionUrl', helper::FILTER_STRING_SHORT),
'unsuscribe' => $this->getInput('coursesCaptionUnsuscribe', helper::FILTER_STRING_SHORT),
'enrolmentLimit' => $this->getInput('coursesCaptionEnrolmentLimit', helper::FILTER_STRING_SHORT),
2023-10-19 22:48:57 +02:00
]
]);
2023-10-19 11:41:54 +02:00
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(),
'notification' => helper::translate('Modifications enregistrées'),
'state' => true
]);
}
2023-11-15 18:06:49 +01:00
// Liste des catégories de contenu
2023-10-19 11:41:54 +02:00
self::$courseCategories = array_merge(self::$courseCategories, $this->getData(['category']));
// Valeurs en sortie
$this->addOutput([
'title' => helper::translate('Configuration du module'),
'view' => 'config'
]);
}
public function index()
{
2023-10-19 22:48:57 +02:00
// Contrôle de la configuration par défaut
$this->update();
// Mise à jour des étiquettes
self::$coursesAccess[self::COURSE_ACCESS_OPEN] = $this->getData(['module', $this->getUrl(0), 'caption', 'accessopen']);
self::$coursesAccess[self::COURSE_ACCESS_DATE] = $this->getData(['module', $this->getUrl(0), 'caption', 'accessdate']);
self::$coursesAccess[self::COURSE_ACCESS_CLOSE] = $this->getData(['module', $this->getUrl(0), 'caption', 'accessclose']);
self::$coursesEnrolment[self::COURSE_ENROLMENT_GUEST] = $this->getData(['module', $this->getUrl(0), 'caption', 'enrolguest']);
self::$coursesEnrolment[self::COURSE_ENROLMENT_SELF] = $this->getData(['module', $this->getUrl(0), 'caption', 'enrolself']);
self::$coursesEnrolment[self::COURSE_ENROLMENT_SELF_KEY] = $this->getData(['module', $this->getUrl(0), 'caption', 'enrolselfkey']);
2023-11-25 14:36:49 +01:00
self::$coursesEnrolment[self::COURSE_ENROLMENT_MANDATORY] = $this->getData(['module', $this->getUrl(0), 'caption', 'enrolMandatory']);
2023-10-19 22:48:57 +02:00
2023-10-19 11:41:54 +02:00
// Valeurs en sortie
$this->addOutput([
'showBarEditButton' => true,
'showPageContent' => true,
'view' => 'index'
]);
}
2023-10-19 22:48:57 +02:00
// Initialise avec des valeurs par défaut
private function update()
{
$check = false;
foreach (self::$default['config'] as $key => $value) {
if (is_null($this->getData(['module', $this->getUrl(0), 'config', $key]))) {
$this->setData(['module', $this->getUrl(0), 'config', $key, $value]);
$check = true;
}
}
foreach (self::$default['caption'] as $key => $value) {
if (is_null($this->getData(['module', $this->getUrl(0), 'caption', $key]))) {
$this->setData(['module', $this->getUrl(0), 'caption', $key, $value]);
$check = true;
}
}
if ($check) {
header('refresh:0');
}
}
2023-10-19 11:41:54 +02:00
}