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])));
|
$r = in_array($userId, array_keys($this->getData(['enrolment', $courseId])));
|
||||||
break;
|
break;
|
||||||
case self::GROUP_MEMBER:
|
case self::GROUP_MEMBER:
|
||||||
$r = $this->courseIsAvailable($courseId) &&
|
$r = in_array($userId, array_keys($this->getData(['enrolment', $courseId]))) &&
|
||||||
(in_array($userId, array_keys($this->getData(['enrolment', $courseId]))) ||
|
$this->getData(['course', $courseId, 'enrolment']) <= self::COURSE_ENROLMENT_SELF;
|
||||||
$this->getData(['course', $courseId, 'enrolment']) <= self::COURSE_ENROLMENT_SELF);
|
|
||||||
break;
|
break;
|
||||||
// Visiteur non connecté
|
// Visiteur non connecté
|
||||||
case self::GROUP_VISITOR:
|
case self::GROUP_VISITOR:
|
||||||
case false:
|
case false:
|
||||||
$r = $this->courseIsAvailable($courseId) &&
|
$r = $this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST;
|
||||||
$this->getData(['course', $courseId, 'enrolment']) === self::COURSE_ENROLMENT_GUEST;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$r = false;
|
$r = false;
|
||||||
@ -1489,6 +1487,9 @@ class common
|
|||||||
*/
|
*/
|
||||||
public function courseIsAvailable($courseId)
|
public function courseIsAvailable($courseId)
|
||||||
{
|
{
|
||||||
|
if ($courseId === 'home') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
$access = $this->getData(['course', $courseId, 'access']);
|
$access = $this->getData(['course', $courseId, 'access']);
|
||||||
switch ($access) {
|
switch ($access) {
|
||||||
case self::COURSE_ACCESS_OPEN:
|
case self::COURSE_ACCESS_OPEN:
|
||||||
|
@ -22,7 +22,6 @@ class course extends common
|
|||||||
'add' => self::GROUP_ADMIN,
|
'add' => self::GROUP_ADMIN,
|
||||||
'delete' => self::GROUP_ADMIN,
|
'delete' => self::GROUP_ADMIN,
|
||||||
'swap' => self::GROUP_VISITOR,
|
'swap' => self::GROUP_VISITOR,
|
||||||
'change' => self::GROUP_VISITOR,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public static $courseAccess = [
|
public static $courseAccess = [
|
||||||
@ -42,7 +41,7 @@ class course extends common
|
|||||||
|
|
||||||
public static $courses = [];
|
public static $courses = [];
|
||||||
|
|
||||||
public static $changeMessages = [];
|
public static $swapMessage = '';
|
||||||
|
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
@ -243,10 +242,10 @@ class course extends common
|
|||||||
|
|
||||||
// Bouton de connexion ou d'inscription
|
// Bouton de connexion ou d'inscription
|
||||||
// C'est un prof ou un admin
|
// C'est un prof ou un admin
|
||||||
self::$changeMessages = $this->getUser('group') >= self::GROUP_EDITOR
|
self::$changeMessages = $this->getUser('group') >= self::GROUP_EDITOR
|
||||||
? 'Se connecter'
|
? 'Se connecter'
|
||||||
// C'est un étudiant ou un visiteur
|
// C'est un étudiant ou un visiteur
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
@ -266,21 +265,70 @@ class course extends common
|
|||||||
// Cours sélectionnée
|
// Cours sélectionnée
|
||||||
$courseId = $this->getUrl(2);
|
$courseId = $this->getUrl(2);
|
||||||
|
|
||||||
if (
|
// Le cours est disponible ?
|
||||||
// home n'est pas présent dans la base de données des cours
|
if ($courseId === 'home') {
|
||||||
$courseId === 'home' ||
|
|
||||||
// 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;
|
$_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
|
// Soumission du formulaire
|
||||||
$this->addOutput([
|
if (
|
||||||
'redirect' => helper::baseUrl()
|
$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.
|
* This file is part of Zwii.
|
||||||
* For full copyright and license information, please see the LICENSE
|
* For full copyright and license information, please see the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*
|
*
|
||||||
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
||||||
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
||||||
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
||||||
* @link http://zwiicms.fr/
|
* @link http://zwiicms.fr/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @import url("site/data/admin.css"); */
|
/** @import url("site/data/admin.css"); */
|
||||||
|
|
||||||
/** NE PAS EFFACER
|
/** NE PAS EFFACER
|
||||||
* admin.css
|
* admin.css
|
||||||
*/
|
*/
|
@ -1,27 +1,27 @@
|
|||||||
<?php echo template::formOpen('courseChangeForm'); ?>
|
<?php echo template::formOpen('courseChangeForm'); ?>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col12">
|
<div class="col12">
|
||||||
<?php echo "<h3>Auteur : " . $this->getData(['course', $this->getUrl(2), 'author' ]) . "</h3>"; ?>
|
<?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> 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> 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>";?>
|
<?php echo "<p> Inscription : " . $module::$courseEnrolment[$this->getData(['course', $this->getUrl(2), 'enrolment' ])]. "</p>";?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col2">
|
<div class="col2">
|
||||||
<?php echo template::button('courseChangeBack', [
|
<?php echo template::button('courseChangeBack', [
|
||||||
'href' => helper::baseUrl(),
|
'href' => helper::baseUrl(),
|
||||||
'value' => template::ico('left')
|
'value' => template::ico('left')
|
||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="col3 offset7">
|
<div class="col3 offset7">
|
||||||
<?php echo template::submit('courseChangeSubmit', [
|
<?php echo template::submit('courseChangeSubmit', [
|
||||||
'value' => 'Se connecter',
|
'value' => $module::$swapMessage,
|
||||||
'disabled' => !$this->courseIsAvailable($this->getUrl(2)),
|
'disabled' => !$this->courseIsAvailable($this->getUrl(2)),
|
||||||
'ico' => ''
|
'ico' => ''
|
||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php echo template::formClose(); ?>
|
<?php echo template::formClose(); ?>
|
Loading…
Reference in New Issue
Block a user