Changement de cours WIP

This commit is contained in:
Fred Tempez 2023-09-22 19:33:03 +02:00
parent bcf01dc8fa
commit 033528c50b
4 changed files with 114 additions and 65 deletions

View File

@ -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:

View File

@ -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()
@ -266,9 +265,33 @@ class course extends common
// Cours sélectionnée
$courseId = $this->getUrl(2);
// 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,
]);
}
// Soumission du formulaire
if (
$this->isPost()
) {
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]))
@ -276,11 +299,36 @@ class course extends common
// 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,
]);
}
}

View File

@ -17,7 +17,7 @@
</div>
<div class="col3 offset7">
<?php echo template::submit('courseChangeSubmit', [
'value' => 'Se connecter',
'value' => $module::$swapMessage,
'disabled' => !$this->courseIsAvailable($this->getUrl(2)),
'ico' => ''
]); ?>