Fonction de listage des cours et bdd enrolment dans la config

This commit is contained in:
Fred Tempez 2023-09-16 17:27:22 +02:00
parent 06a01de7bc
commit 965b431e69
4 changed files with 96 additions and 35 deletions

View File

@ -898,15 +898,17 @@ class layout extends common
$leftItems .= '<li><select id="barSelectCourse" >'; $leftItems .= '<li><select id="barSelectCourse" >';
$leftItems .= '<option name="' . helper::translate('Accueil') . '" value="' . helper::baseUrl(true) . 'course/swap/home" ' . ('home' === self::$siteContent ? 'selected' : '') . '>' . helper::translate('Accueil') . '</option>'; $leftItems .= '<option name="' . helper::translate('Accueil') . '" value="' . helper::baseUrl(true) . 'course/swap/home" ' . ('home' === self::$siteContent ? 'selected' : '') . '>' . helper::translate('Accueil') . '</option>';
foreach ($this->getData(['course']) as $key => $value) { foreach ($this->getData(['course']) as $key => $value) {
$leftItems .= '<option name="' . $value['shortTitle'] . '" value="' . helper::baseUrl(true) . 'course/swap/' . $key . '" ' . ($key === self::$siteContent ? 'selected' : '') . '>' . $value['shortTitle'] . '</option>'; $leftItems .= '<option name="' . $value['shortTitle'] . '" value="' . helper::baseUrl(true) . 'course/swap/' . $key . '" ' . ($key === self::$siteContent ? 'selected' : '') . '>' . $value['shortTitle'] . '</option>';
} }
$leftItems .= '</select></li>'; $leftItems .= '</select></li>';
} }
// Bouton Gérer les cours // Bouton Gérer les cours
$leftItems .= '<li>' . template::ico('cubes', [ if ($this->getUser('group') >= self::GROUP_ADMIN) {
'href' => helper::baseUrl() . 'course', $leftItems .= '<li>' . template::ico('cubes', [
'help' => 'Cours' 'href' => helper::baseUrl() . 'course',
]) . '</li>'; 'help' => 'Cours'
]) . '</li>';
}
// Liste des pages // Liste des pages
if ($this->getUser('group') >= self::GROUP_TEACHER) { if ($this->getUser('group') >= self::GROUP_TEACHER) {
$leftItems .= '<li><select id="barSelectPage">'; $leftItems .= '<li><select id="barSelectPage">';

View File

@ -205,6 +205,7 @@ class common
'user' => '', 'user' => '',
'language' => '', 'language' => '',
'profil' => '', 'profil' => '',
'enrolment' => '',
]; ];
private $configFiles = [ private $configFiles = [
@ -218,6 +219,7 @@ class common
'user' => '', 'user' => '',
'language' => '', 'language' => '',
'profil' => '', 'profil' => '',
'enrolment' => '',
]; ];
private $contentFiles = [ private $contentFiles = [
@ -347,7 +349,6 @@ class common
} }
} }
// Charge le site d'accueil // Charge le site d'accueil
//if (self::$siteContent === 'home') {
foreach ($this->contentFiles as $stageId => $item) { foreach ($this->contentFiles as $stageId => $item) {
if ( if (
file_exists(self::DATA_DIR . self::$siteContent . '/' . $stageId . '.json') === false file_exists(self::DATA_DIR . self::$siteContent . '/' . $stageId . '.json') === false
@ -355,7 +356,7 @@ class common
$this->initData($stageId); $this->initData($stageId);
} }
} }
//}
} }
// Récupère un utilisateur connecté // Récupère un utilisateur connecté
@ -826,7 +827,6 @@ class common
} }
} }
/** /**
* Accède à une valeur des variables http (ordre de recherche en l'absence de type : _COOKIE, _POST) * Accède à une valeur des variables http (ordre de recherche en l'absence de type : _COOKIE, _POST)
* @param string $key Clé de la valeur * @param string $key Clé de la valeur

View File

@ -44,7 +44,7 @@ class course extends common
public function index() public function index()
{ {
$courseIdShortTitle = helper::arrayColumn($this->getData(['course']), 'shortTitle'); $courseIdShortTitle = helper::arrayColumn($this->getData(['course']), 'shortTitle');
ksort( $courseIdShortTitle); ksort($courseIdShortTitle);
foreach ($courseIdShortTitle as $courseId => $courseTitle) { foreach ($courseIdShortTitle as $courseId => $courseTitle) {
self::$courses[] = [ self::$courses[] = [
$courseTitle, $courseTitle,
@ -64,6 +64,7 @@ class course extends common
]; ];
} }
//var_dump($this->getCourseHierarchy(1, 1));
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'title' => helper::translate('Cours'), 'title' => helper::translate('Cours'),
@ -83,13 +84,14 @@ class course extends common
$this->isPost() $this->isPost()
) { ) {
$courseId = uniqid(); $courseId = uniqid();
$author = $this->getInput('courseAddAuthor');
$this->setData([ $this->setData([
'course', 'course',
$courseId, $courseId,
[ [
'title' => $this->getInput('courseAddTitle', helper::FILTER_STRING_SHORT, true), 'title' => $this->getInput('courseAddTitle', helper::FILTER_STRING_SHORT, true),
'shortTitle' => $this->getInput('courseAddShortTitle', helper::FILTER_STRING_SHORT, true), 'shortTitle' => $this->getInput('courseAddShortTitle', helper::FILTER_STRING_SHORT, true),
'author' => $this->getInput('courseAddAuthor'), 'author' => $author,
'description' => $this->getInput('courseAddDescription', helper::FILTER_STRING_SHORT, true), 'description' => $this->getInput('courseAddDescription', helper::FILTER_STRING_SHORT, true),
'access' => $this->getInput('courseAddAccess'), 'access' => $this->getInput('courseAddAccess'),
'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME), 'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME),
@ -101,8 +103,16 @@ class course extends common
// Créer la structure de données // Créer la structure de données
mkdir(self::DATA_DIR . $courseId); mkdir(self::DATA_DIR . $courseId);
// BDD des inscrits // BDD des inscrits
file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode(array())); $this->setData([
'enrolment',
$courseId,
[
'teacher' => $author,
'students' => []
]
]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
@ -127,29 +137,35 @@ class course extends common
]); ]);
} }
public function delete() { public function delete()
{
if ( if (
$this->getUser('permission', __CLASS__, __FUNCTION__) !== true || $this->getUser('permission', __CLASS__, __FUNCTION__) !== true ||
// Le cours n'existe pas // Le cours n'existe pas
$this->getData(['course', $this->getUrl(2)]) === null $this->getData(['course', $this->getUrl(2)]) === null
// Groupe insuffisant // Groupe insuffisant
and ($this->getUrl('group') < self::GROUP_TEACHER) and ($this->getUrl('group') < self::GROUP_TEACHER)
) { ) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'access' => false 'access' => false
]); ]);
// Suppression // Suppression
} else { } else {
$this->deleteData(['course', $this->getUrl(2)]); $this->deleteData(['course', $this->getUrl(2)]);
// Valeurs en sortie $this->deleteData(['enrolment', $this->getUrl(2)]);
$this->addOutput([ if (is_dir(self::DATA_DIR . $this->getUrl(2))) {
'redirect' => helper::baseUrl() . 'course', $this->deleteDir(self::DATA_DIR . $this->getUrl(2));
'notification' => helper::translate('Cours supprimé'), }
'state' => true
]); // Valeurs en sortie
} $this->addOutput([
'redirect' => helper::baseUrl() . 'course',
'notification' => helper::translate('Cours supprimé'),
'state' => true
]);
}
} }
@ -165,22 +181,34 @@ class course extends common
$this->isPost() $this->isPost()
) { ) {
$courseId = $this->getUrl(2); $courseId = $this->getUrl(2);
$author = $this->getInput('courseAddAuthor');
$this->setData([ $this->setData([
'course', 'course',
$courseId, $courseId,
[ [
'title' => $this->getInput('courseEditTitle', helper::FILTER_STRING_SHORT, true), 'title' => $this->getInput('courseEditTitle', helper::FILTER_STRING_SHORT, true),
'shortTitle' => $this->getInput('courseEditShortTitle', helper::FILTER_STRING_SHORT, true), 'shortTitle' => $this->getInput('courseEditShortTitle', helper::FILTER_STRING_SHORT, true),
'author' => $this->getInput('courseEditAuthor'), 'author' =>$author,
'description' => $this->getInput('courseEditDescription', helper::FILTER_STRING_SHORT, true), 'description' => $this->getInput('courseEditDescription', helper::FILTER_STRING_SHORT, true),
'access' => $this->getInput('courseEditAccess'), 'access' => $this->getInput('courseEditAccess', helper::FILTER_INT),
'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME), 'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME),
'closingDate' => $this->getInput('courseClosingDate', helper::FILTER_DATETIME), 'closingDate' => $this->getInput('courseClosingDate', helper::FILTER_DATETIME),
'enrolment' => $this->getInput('courseEditEnrolment'), 'enrolment' => $this->getInput('courseEditEnrolment', helper::FILTER_INT),
'enrolmentKey' => $this->getInput('courseEditEnrolmentKey'), 'enrolmentKey' => $this->getInput('courseEditEnrolmentKey'),
] ]
]); ]);
// BDD des inscrits
$students = is_null($this->getData(['enrolment', $courseId, 'students'])) ? [] : $this->getData([ 'enrolment', $courseId, 'students']);
$this->setData([
'enrolment',
$courseId,
[
'teacher' => $author,
'students' => $students
]
]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'course', 'redirect' => helper::baseUrl() . 'course',
@ -228,4 +256,34 @@ class course extends common
]); ]);
} }
/**
* Retourne un tableau des cours
* @param string $access
* - 0 le cours est ouvert
* - 1 le cours est ouvert entre les dates
* - 2 le cours est fermé
* @param string $enrolment
* - 0 accès est anonyme
* - 1 accès libre
* - 2 accès avec clé
* - 3 manuel, le prof inscrits
*/
public function getCourseHierarchy($access = null, $enrolment = null)
{
$courses = $this->getData(['course']);
$response = [];
foreach ($courses as $courseId => $courseValues) {
$response[] = ($access === $courseValues['access'] || $access === null)
? $courseId : '';
$response[] = ($enrolment === $courseValues['enrolment'] || $enrolment === null)
? $courseId : '';
}
$response = array_unique($response);
$response = array_filter($response, function ($value) {
// Supprime les éléments vides (null, "", 0, false, etc.)
return !empty($value);
});
return $response;
}
} }

View File

@ -667,7 +667,8 @@ class init extends common
'comment' => 'Contrôle total', 'comment' => 'Contrôle total',
] ]
], ],
'course' => [] 'course' => [],
'enrolment' => []
]; ];
public static $siteTemplate = [ public static $siteTemplate = [