Export Stats
This commit is contained in:
parent
77370d15e1
commit
e9a0bae6b9
@ -33,6 +33,7 @@ class course extends common
|
||||
'userDelete' => self::GROUP_ADMIN,
|
||||
'userDeleteAll' => self::GROUP_ADMIN,
|
||||
'userHistory' => self::GROUP_ADMIN,
|
||||
'usersHistoryExport' => self::GROUP_ADMIN,
|
||||
'userHistoryExport' => self::GROUP_ADMIN,
|
||||
];
|
||||
|
||||
@ -76,7 +77,7 @@ class course extends common
|
||||
$courseIdShortTitle = helper::arrayColumn($this->getData(['course']), 'title');
|
||||
ksort($courseIdShortTitle);
|
||||
foreach ($courseIdShortTitle as $courseId => $courseTitle) {
|
||||
$categorieUrl = helper::baseUrl(!helper::checkRewrite()) . 'course/suscribe/' . $courseId;
|
||||
$categorieUrl = helper::baseUrl() . 'course/suscribe/' . $courseId;
|
||||
$authorId = $this->getData(['course', $courseId, 'author']);
|
||||
$author = sprintf('%s %s', $this->getData(['user', $authorId, 'firstname']), $this->getData(['user', $authorId, 'lastname']));
|
||||
$access = self::$courseAccess[$this->getData(['course', $courseId, 'access'])];
|
||||
@ -753,10 +754,9 @@ class course extends common
|
||||
|
||||
}
|
||||
|
||||
public function userHistoryExport()
|
||||
public function usersHistoryExport()
|
||||
{
|
||||
|
||||
|
||||
$courseId = $this->getUrl(2);
|
||||
|
||||
// Statistiques du cours sélectionné calcul du nombre de pages
|
||||
@ -776,6 +776,17 @@ class course extends common
|
||||
// Tri du tableau par défaut par $userId
|
||||
ksort($users);
|
||||
|
||||
// Dossier temporaire
|
||||
if (is_dir(self::FILE_DIR . 'source/export') === false) {
|
||||
mkdir(self::FILE_DIR . 'source/export');
|
||||
}
|
||||
if (is_dir(self::FILE_DIR . 'source/export/' . $courseId) === false) {
|
||||
mkdir(self::FILE_DIR . 'source/export/' . $courseId);
|
||||
}
|
||||
$path = self::FILE_DIR . 'source/export/';
|
||||
|
||||
$filename = $path . $courseId . '/synthèse' . helper::dateUTF8('%Y%m%d', time()) . '.csv';
|
||||
|
||||
foreach ($users as $userId => $userValue) {
|
||||
$history = $userValue['history'];
|
||||
|
||||
@ -794,17 +805,11 @@ class course extends common
|
||||
round(($viewPages * 100) / $sumPages, 1)
|
||||
];
|
||||
|
||||
// Nom du fichier CSV
|
||||
if (is_dir(self::FILE_DIR . 'source/export') === false) {
|
||||
mkdir(self::FILE_DIR . 'source/export');
|
||||
}
|
||||
|
||||
$filename = self::FILE_DIR . 'source/export/export_' . helper::dateUTF8('%Y%m%d',time()) . '_' . $courseId . '.csv';
|
||||
|
||||
// Synthèse des historiques
|
||||
// ------------------------
|
||||
// Ouverture du fichier en écriture
|
||||
$file = fopen($filename, 'w');
|
||||
|
||||
// Écriture des données dans le fichier
|
||||
foreach (self::$courseUsers as $user) {
|
||||
// Décode les entités HTML dans chaque élément du tableau
|
||||
$decodedUser = array_map('html_entity_decode', $user);
|
||||
@ -812,7 +817,6 @@ class course extends common
|
||||
// Écrire la ligne dans le fichier CSV
|
||||
fputcsv($file, $decodedUser, ';');
|
||||
}
|
||||
|
||||
// Fermeture du fichier
|
||||
fclose($file);
|
||||
|
||||
@ -827,6 +831,62 @@ class course extends common
|
||||
|
||||
}
|
||||
|
||||
public function userHistoryExport()
|
||||
{
|
||||
|
||||
$courseId = $this->getUrl(2);
|
||||
$userId = $this->getUrl(3);
|
||||
$history = $this->getData(['enrolment', $courseId, $userId]);
|
||||
$data = json_decode(file_get_contents(self::DATA_DIR . $courseId . '/page.json'), true);
|
||||
$data = $data['page'];
|
||||
|
||||
// Dossier temporaire
|
||||
if (is_dir(self::FILE_DIR . 'source/export') === false) {
|
||||
mkdir(self::FILE_DIR . 'source/export');
|
||||
}
|
||||
if (is_dir(self::FILE_DIR . 'source/export/' . $courseId) === false) {
|
||||
mkdir(self::FILE_DIR . 'source/export/' . $courseId);
|
||||
}
|
||||
$path = self::FILE_DIR . 'source/export/';
|
||||
|
||||
$filename = $path . $courseId . '/' . $userId . '.csv';
|
||||
|
||||
// Exclure les barres et les pages masquées
|
||||
$count = 0;
|
||||
foreach ($data as $pageId => $pageData) {
|
||||
if ($pageData['position'] > 0) {
|
||||
$count++;
|
||||
$pages[$pageId] = [
|
||||
'number' => $count,
|
||||
'title' => $pageData['title'],
|
||||
];
|
||||
}
|
||||
}
|
||||
$file = fopen($filename, 'w');
|
||||
foreach ($history['history'] as $pageId => $time) {
|
||||
$data = array_map('html_entity_decode', array(
|
||||
$pageId,
|
||||
$pages[$pageId]['title'],
|
||||
$pages[$pageId]['number'],
|
||||
helper::dateUTF8('%d %B %Y - %H:%M:%S', $time),
|
||||
));
|
||||
|
||||
// Écrire la ligne dans le fichier CSV
|
||||
fputcsv($file, $data, ';');
|
||||
}
|
||||
// Fermeture du fichier
|
||||
fclose($file);
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'course/userHistory/' . $courseId . '/' . $userId,
|
||||
'notification' => 'Création ' . basename($filename) . ' dans le dossier "Export"',
|
||||
'state' => true,
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Génération du message d'inscription
|
||||
public function suscribe()
|
||||
{
|
||||
@ -863,7 +923,7 @@ class course extends common
|
||||
} else {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl(!helper::checkRewrite()) . 'course/suscribe/' . $courseId,
|
||||
'redirect' => helper::baseUrl() . 'course/suscribe/' . $courseId,
|
||||
'state' => false,
|
||||
'notification' => 'La clé est incorrecte'
|
||||
]);
|
||||
|
@ -8,11 +8,10 @@
|
||||
</div>
|
||||
<div class="col1 offset9">
|
||||
<?php echo template::button('userDeleteAll', [
|
||||
'href' => helper::baseUrl() . 'course/userHistoryExport/' . $this->getUrl(2),
|
||||
'href' => helper::baseUrl() . 'course/usersHistoryExport/' . $this->getUrl(2),
|
||||
'value' => template::ico('download'),
|
||||
'help' => 'Exporter',
|
||||
])
|
||||
?>
|
||||
]) ?>
|
||||
</div>
|
||||
<div class="col1">
|
||||
<?php echo template::button('userDeleteAll', [
|
||||
@ -20,8 +19,7 @@
|
||||
'href' => helper::baseUrl() . 'course/userDeleteAll/' . $this->getUrl(2),
|
||||
'value' => template::ico('trash'),
|
||||
'help' => 'Désinscrire tous les utilisateurs',
|
||||
])
|
||||
?>
|
||||
])?>
|
||||
</div>
|
||||
</div>
|
||||
<?php echo template::formOpen('courseFilterUserForm'); ?>
|
||||
|
@ -6,6 +6,13 @@
|
||||
'value' => template::ico('left')
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col1 offset10">
|
||||
<?php echo template::button('userDeleteAll', [
|
||||
'href' => helper::baseUrl() . 'course/userHistoryExport/' . $this->getUrl(2) . '/' . $this->getUrl(3),
|
||||
'value' => template::ico('download'),
|
||||
'help' => 'Exporter',
|
||||
]) ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($module::$userHistory): ?>
|
||||
<div class="row textAlignCenter">
|
||||
|
Loading…
Reference in New Issue
Block a user