Clone course

This commit is contained in:
Fred Tempez 2024-01-14 20:56:23 +01:00
parent 62d1a00a91
commit 2d4e835269
2 changed files with 81 additions and 42 deletions

View File

@ -38,6 +38,7 @@ class course extends common
'userHistoryExport' => self::GROUP_EDITOR,
'backup' => self::GROUP_EDITOR,
'restore' => self::GROUP_EDITOR,
'clone' => self::GROUP_ADMIN
];
public static $courseAccess = [
@ -92,9 +93,11 @@ class course extends common
: '';
$categorieUrl = helper::baseUrl() . 'course/swap/' . $courseId;
$info = sprintf('<strong>%s<br /></strong>Auteur : %s<br />Id : <a href="%s" target="_blank">%s<br />', $this->getData(['course', $courseId, 'title']), $author, $categorieUrl, $courseId);
$enrolment = sprintf('Accès : %s<br />Inscription : %s<br />',
self::$courseAccess[$this->getData(['course', $courseId, 'access'])],
self::$courseEnrolment[$this->getData(['course', $courseId, 'enrolment'])]);
$enrolment = sprintf(
'Accès : %s<br />Inscription : %s<br />',
self::$courseAccess[$this->getData(['course', $courseId, 'access'])],
self::$courseEnrolment[$this->getData(['course', $courseId, 'enrolment'])]
);
self::$courses[] = [
$info,
$this->getData(['course', $courseId, 'description']),
@ -281,28 +284,28 @@ class course extends common
public function manage()
{
// Liste des enseignants pour le sélecteur d'auteurs
$teachers = $this->getData(['user']);
foreach ($teachers as $teacherId => $teacherInfo) {
if ($teacherInfo["group"] >= 2) {
self::$courseTeachers[$teacherId] = $teacherInfo["firstname"] . ' ' . $teacherInfo["lastname"];
}
}
// Liste des catégories de contenu
self::$courseCategories = $this->getData(['category']);
// Liste des pages disponibles
$this->initDB('page', $this->getUrl(2));
self::$pagesList = $this->getData(['page']);
foreach (self::$pagesList as $page => $pageId) {
if (
$this->getData(['page', $page, 'block']) === 'bar' ||
$this->getData(['page', $page, 'disable']) === true
) {
unset(self::$pagesList[$page]);
}
}
// Liste des enseignants pour le sélecteur d'auteurs
$teachers = $this->getData(['user']);
foreach ($teachers as $teacherId => $teacherInfo) {
if ($teacherInfo["group"] >= 2) {
self::$courseTeachers[$teacherId] = $teacherInfo["firstname"] . ' ' . $teacherInfo["lastname"];
}
}
// Liste des catégories de contenu
self::$courseCategories = $this->getData(['category']);
// Liste des pages disponibles
$this->initDB('page', $this->getUrl(2));
self::$pagesList = $this->getData(['page']);
foreach (self::$pagesList as $page => $pageId) {
if (
$this->getData(['page', $page, 'block']) === 'bar' ||
$this->getData(['page', $page, 'disable']) === true
) {
unset(self::$pagesList[$page]);
}
}
// Valeurs en sortie
$this->addOutput([
@ -311,6 +314,34 @@ class course extends common
]);
}
/**
* Duplique un cours et l'affiche dans l'éditeur
*/
public function clone()
{
// Cours à dupliquer
$courseId = $this->getUrl(2);
// Id du nouveau cours
$target = uniqid();
// Créer la structure de données
mkdir(self::DATA_DIR . $target);
$this->copyDir(self::DATA_DIR . $courseId, self::DATA_DIR . $target);
$data = $this->getData(['course', $courseId]);
$this->setData(['course', $target, $data]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'course/edit/' . $target,
'notification' => helper::translate('Espace dupliqué'),
'state' => true
]);
}
public function delete()
{
@ -342,9 +373,9 @@ class course extends common
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'course/manage',
'redirect' => helper::baseUrl() . 'course',
'notification' => $success ? helper::translate('Espace supprimé') : helper::translate('Erreur de suppression'),
'state' => $success
'state' => $success
]);
}

View File

@ -6,37 +6,45 @@
'value' => template::ico('left')
]); ?>
</div>
<div class="col1 offset7">
</div>
<div class="row textAlignCenter">
<div class="col2">
<?php echo template::button('categoryUser' . $this->getUrl(2), [
'href' => helper::baseUrl() . 'course/users/' . $this->getUrl(2),
'value' => template::ico('users'),
'help' => 'Participants'
'value' => 'Participants',
'ico' => 'users'
]); ?>
</div>
<div class="col1">
<?php echo
template::button('courseManageEdit' . $this->getUrl(2), [
<div class="col2">
<?php echo template::button('courseManageEdit' . $this->getUrl(2), [
'href' => helper::baseUrl() . 'course/edit/' . $this->getUrl(2),
'value' => template::ico('pencil'),
'help' => 'Éditer'
'value' => 'Éditer',
'ico' => 'pencil'
]); ?>
</div>
<div class="col1">
<div class="col2">
<?php echo
template::button('courseManageDuplicate' . $this->getUrl(2), [
'href' => helper::baseUrl() . 'course/clone/' . $this->getUrl(2),
'value' => 'Cloner',
'ico' => 'clone'
]); ?>
</div>
<div class="col2">
<?php echo
template::button('courseManageDownload' . $this->getUrl(2), [
'href' => helper::baseUrl() . 'course/backup/' . $this->getUrl(2),
'value' => template::ico('download-cloud'),
'help' => 'Sauvegarder'
'value' => 'Sauvegarder',
'ico' => 'download-cloud'
]); ?>
</div>
<div class="col1 ">
<div class="col2 ">
<?php echo
template::button('courseManageDelete' . $this->getUrl(2), [
'class' => 'courseDelete buttonRed',
'href' => helper::baseUrl() . 'course/delete/' . $this->getUrl(2),
'value' => template::ico('trash'),
'help' => 'Supprimer'
'value' => 'Supprimer',
'ico' => 'trash'
]); ?>
</div>
<div class="row">