forked from ZwiiCMS-Team/ZwiiCampus
Changement de cours WIP
This commit is contained in:
parent
bcf01dc8fa
commit
033528c50b
@ -1466,15 +1466,13 @@ class common
|
||||
$r = in_array($userId, array_keys($this->getData(['enrolment', $courseId])));
|
||||
break;
|
||||
case self::GROUP_MEMBER:
|
||||
$r = $this->courseIsAvailable($courseId) &&
|
||||
(in_array($userId, array_keys($this->getData(['enrolment', $courseId]))) ||
|
||||
$this->getData(['course', $courseId, 'enrolment']) <= self::COURSE_ENROLMENT_SELF);
|
||||
$r = in_array($userId, array_keys($this->getData(['enrolment', $courseId]))) &&
|
||||
$this->getData(['course', $courseId, 'enrolment']) <= self::COURSE_ENROLMENT_SELF;
|
||||
break;
|
||||
// Visiteur non connecté
|
||||
case self::GROUP_VISITOR:
|
||||
case false:
|
||||
$r = $this->courseIsAvailable($courseId) &&
|
||||
$this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST;
|
||||
$r = $this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST;
|
||||
break;
|
||||
default:
|
||||
$r = false;
|
||||
@ -1489,6 +1487,9 @@ class common
|
||||
*/
|
||||
public function courseIsAvailable($courseId)
|
||||
{
|
||||
if ($courseId === 'home') {
|
||||
return true;
|
||||
}
|
||||
$access = $this->getData(['course', $courseId, 'access']);
|
||||
switch ($access) {
|
||||
case self::COURSE_ACCESS_OPEN:
|
||||
|
@ -22,7 +22,6 @@ class course extends common
|
||||
'add' => self::GROUP_ADMIN,
|
||||
'delete' => self::GROUP_ADMIN,
|
||||
'swap' => self::GROUP_VISITOR,
|
||||
'change' => self::GROUP_VISITOR,
|
||||
];
|
||||
|
||||
public static $courseAccess = [
|
||||
@ -42,7 +41,7 @@ class course extends common
|
||||
|
||||
public static $courses = [];
|
||||
|
||||
public static $changeMessages = [];
|
||||
public static $swapMessage = '';
|
||||
|
||||
|
||||
public function index()
|
||||
@ -243,10 +242,10 @@ class course extends common
|
||||
|
||||
// Bouton de connexion ou d'inscription
|
||||
// C'est un prof ou un admin
|
||||
self::$changeMessages = $this->getUser('group') >= self::GROUP_EDITOR
|
||||
? 'Se connecter'
|
||||
// C'est un étudiant ou un visiteur
|
||||
: '';
|
||||
self::$changeMessages = $this->getUser('group') >= self::GROUP_EDITOR
|
||||
? 'Se connecter'
|
||||
// C'est un étudiant ou un visiteur
|
||||
: '';
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
@ -266,21 +265,70 @@ class course extends common
|
||||
// Cours sélectionnée
|
||||
$courseId = $this->getUrl(2);
|
||||
|
||||
if (
|
||||
// home n'est pas présent dans la base de données des cours
|
||||
$courseId === 'home' ||
|
||||
// Contrôle la validité du cours demandé
|
||||
(is_dir(self::DATA_DIR . $courseId) &&
|
||||
$this->getData(['course', $courseId]))
|
||||
) {
|
||||
// Stocker la sélection
|
||||
// Le cours est disponible ?
|
||||
if ($courseId === 'home') {
|
||||
$_SESSION['ZWII_SITE_CONTENT'] = $courseId;
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl(),
|
||||
]);
|
||||
} elseif ($this->courseIsAvailable($courseId) === false) {
|
||||
$message = 'Ce cours est fermé.';
|
||||
if ($this->getData(['course', $courseId, 'access']) === self::COURSE_ACCESS_DATE) {
|
||||
$from = helper::dateUTF8('%m %B %Y', $this->getData(['course', $courseId, 'openingDate'])) . helper::translate(' à ') . helper::dateUTF8('%H:%M', $this->getData(['course', $courseId, 'openingDate']));
|
||||
$to = helper::dateUTF8('%m %B %Y', $this->getData(['course', $courseId, 'closingDate'])) . helper::translate(' à ') . helper::dateUTF8('%H:%M', $this->getData(['course', $courseId, 'closingDate']));
|
||||
$message = sprintf(helper::translate('Ce cours ouvre le <br>%s <br> et ferme le %s'), $from, $to);
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl(),
|
||||
'notification' => helper::translate($message),
|
||||
'state' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl()
|
||||
]);
|
||||
// Soumission du formulaire
|
||||
if (
|
||||
$this->isPost()
|
||||
) {
|
||||
if (
|
||||
// Contrôle la validité du cours demandé
|
||||
(is_dir(self::DATA_DIR . $courseId) &&
|
||||
$this->getData(['course', $courseId]))
|
||||
) {
|
||||
// Stocker la sélection
|
||||
$_SESSION['ZWII_SITE_CONTENT'] = $courseId;
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl()
|
||||
]);
|
||||
} else {
|
||||
|
||||
// Génération du message d'inscription
|
||||
$userId = $this->getUser('id');
|
||||
// L'étudiant est-il inscrit
|
||||
self::$swapMessage = 'Se connecter';
|
||||
if ($this->courseUserEnrolment($courseId, $userId) === false) {
|
||||
// Inscription libre
|
||||
if ($this->getData(['course', $courseId, 'enrolment']) <= self::COURSE_ENROLMENT_SELF) {
|
||||
self::$swapMessage = helper::translate('S\'inscrire');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => sprintf(helper::translate('Accéder au cours %s'), $this->getData(['course', $this->getUrl(2), 'shortTitle'])),
|
||||
'view' => 'swap',
|
||||
'display' => self::DISPLAY_LAYOUT_LIGHT,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
/**
|
||||
* 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 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/
|
||||
*/
|
||||
|
||||
/** @import url("site/data/admin.css"); */
|
||||
|
||||
/** NE PAS EFFACER
|
||||
* admin.css
|
||||
*/
|
||||
/**
|
||||
* 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 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/
|
||||
*/
|
||||
|
||||
/** @import url("site/data/admin.css"); */
|
||||
|
||||
/** NE PAS EFFACER
|
||||
* admin.css
|
||||
*/
|
@ -1,27 +1,27 @@
|
||||
<?php echo template::formOpen('courseChangeForm'); ?>
|
||||
<div class="row">
|
||||
<div class="col12">
|
||||
<?php echo "<h3>Auteur : " . $this->getData(['course', $this->getUrl(2), 'author' ]) . "</h3>"; ?>
|
||||
<?php echo "<p> Description : " . $this->getData(['course', $this->getUrl(2), 'description' ]) . "</p>"; ?>
|
||||
<?php echo "<p> Disponibilité : " . $module::$courseAccess[$this->getData(['course', $this->getUrl(2), 'access' ])] . "</p>";?>
|
||||
<?php echo "<p> Inscription : " . $module::$courseEnrolment[$this->getData(['course', $this->getUrl(2), 'enrolment' ])]. "</p>";?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col2">
|
||||
<?php echo template::button('courseChangeBack', [
|
||||
'href' => helper::baseUrl(),
|
||||
'value' => template::ico('left')
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3 offset7">
|
||||
<?php echo template::submit('courseChangeSubmit', [
|
||||
'value' => 'Se connecter',
|
||||
'disabled' => !$this->courseIsAvailable($this->getUrl(2)),
|
||||
'ico' => ''
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echo template::formOpen('courseChangeForm'); ?>
|
||||
<div class="row">
|
||||
<div class="col12">
|
||||
<?php echo "<h3>Auteur : " . $this->getData(['course', $this->getUrl(2), 'author' ]) . "</h3>"; ?>
|
||||
<?php echo "<p> Description : " . $this->getData(['course', $this->getUrl(2), 'description' ]) . "</p>"; ?>
|
||||
<?php echo "<p> Disponibilité : " . $module::$courseAccess[$this->getData(['course', $this->getUrl(2), 'access' ])] . "</p>";?>
|
||||
<?php echo "<p> Inscription : " . $module::$courseEnrolment[$this->getData(['course', $this->getUrl(2), 'enrolment' ])]. "</p>";?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col2">
|
||||
<?php echo template::button('courseChangeBack', [
|
||||
'href' => helper::baseUrl(),
|
||||
'value' => template::ico('left')
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3 offset7">
|
||||
<?php echo template::submit('courseChangeSubmit', [
|
||||
'value' => $module::$swapMessage,
|
||||
'disabled' => !$this->courseIsAvailable($this->getUrl(2)),
|
||||
'ico' => ''
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echo template::formClose(); ?>
|
Loading…
Reference in New Issue
Block a user