Fix erreur de création d'un cours avec le thème

This commit is contained in:
Fred Tempez 2023-10-04 17:57:07 +02:00
parent 6845a60b09
commit ca0c9aa102

View File

@ -101,6 +101,24 @@ class course extends common
$this->isPost() $this->isPost()
) { ) {
$courseId = uniqid(); $courseId = uniqid();
// Créer la structure de données
mkdir(self::DATA_DIR . $courseId);
$this->initDB('page', $courseId);
$this->initDB('module', $courseId);
$this->initDB('theme', $courseId);
$this->initData('page', $courseId);
$this->initData('module', $courseId);
$this->initData('theme', $courseId);
// BDD des inscrits
$this->setData([
'enrolment',
$courseId,
[]
]);
$this->setData([ $this->setData([
'course', 'course',
$courseId, $courseId,
@ -119,20 +137,6 @@ class course extends common
] ]
]); ]);
// Créer la structure de données
mkdir(self::DATA_DIR . $courseId);
$this->initDB('page', $courseId);
$this->initDB('module', $courseId);
$this->initData('page', $courseId);
$this->initData('module', $courseId);
// BDD des inscrits
$this->setData([
'enrolment',
$courseId,
[]
]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'course', 'redirect' => helper::baseUrl() . 'course',
@ -229,11 +233,11 @@ class course extends common
public function delete() public function delete()
{ {
$courseId = $this->getUrl(2);
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', $courseId]) === null
// Groupe insuffisant // Groupe insuffisant
and ($this->getUrl('group') < self::GROUP_EDITOR) and ($this->getUrl('group') < self::GROUP_EDITOR)
) { ) {
@ -243,17 +247,22 @@ class course extends common
]); ]);
// Suppression // Suppression
} else { } else {
$this->deleteData(['course', $this->getUrl(2)]); if (is_dir(self::DATA_DIR . $courseId)) {
$this->deleteData(['enrolment', $this->getUrl(2)]); $success = $this->deleteDir(self::DATA_DIR . $courseId);
if (is_dir(self::DATA_DIR . $this->getUrl(2))) { $this->deleteData(['course', $courseId]);
$this->deleteDir(self::DATA_DIR . $this->getUrl(2)); $this->deleteData(['enrolment', $courseId]);
}
// Activer le site d'accueil
if ($success) {
self::$siteContent = 'home';
} }
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'course', 'redirect' => helper::baseUrl() . 'course',
'notification' => helper::translate('Cours supprimé'), 'notification' => $success ? helper::translate('Cours supprimé') : helper::translate('Erreur de suppression'),
'state' => true 'state' => $success
]); ]);
} }