forked from ZwiiCMS-Team/ZwiiCampus
Export Stats
This commit is contained in:
parent
77370d15e1
commit
e9a0bae6b9
@ -33,6 +33,7 @@ class course extends common
|
|||||||
'userDelete' => self::GROUP_ADMIN,
|
'userDelete' => self::GROUP_ADMIN,
|
||||||
'userDeleteAll' => self::GROUP_ADMIN,
|
'userDeleteAll' => self::GROUP_ADMIN,
|
||||||
'userHistory' => self::GROUP_ADMIN,
|
'userHistory' => self::GROUP_ADMIN,
|
||||||
|
'usersHistoryExport' => self::GROUP_ADMIN,
|
||||||
'userHistoryExport' => self::GROUP_ADMIN,
|
'userHistoryExport' => self::GROUP_ADMIN,
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ class course extends common
|
|||||||
$courseIdShortTitle = helper::arrayColumn($this->getData(['course']), 'title');
|
$courseIdShortTitle = helper::arrayColumn($this->getData(['course']), 'title');
|
||||||
ksort($courseIdShortTitle);
|
ksort($courseIdShortTitle);
|
||||||
foreach ($courseIdShortTitle as $courseId => $courseTitle) {
|
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']);
|
$authorId = $this->getData(['course', $courseId, 'author']);
|
||||||
$author = sprintf('%s %s', $this->getData(['user', $authorId, 'firstname']), $this->getData(['user', $authorId, 'lastname']));
|
$author = sprintf('%s %s', $this->getData(['user', $authorId, 'firstname']), $this->getData(['user', $authorId, 'lastname']));
|
||||||
$access = self::$courseAccess[$this->getData(['course', $courseId, 'access'])];
|
$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);
|
$courseId = $this->getUrl(2);
|
||||||
|
|
||||||
// Statistiques du cours sélectionné calcul du nombre de pages
|
// 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
|
// Tri du tableau par défaut par $userId
|
||||||
ksort($users);
|
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) {
|
foreach ($users as $userId => $userValue) {
|
||||||
$history = $userValue['history'];
|
$history = $userValue['history'];
|
||||||
|
|
||||||
@ -794,17 +805,11 @@ class course extends common
|
|||||||
round(($viewPages * 100) / $sumPages, 1)
|
round(($viewPages * 100) / $sumPages, 1)
|
||||||
];
|
];
|
||||||
|
|
||||||
// Nom du fichier CSV
|
// Synthèse des historiques
|
||||||
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';
|
|
||||||
|
|
||||||
// Ouverture du fichier en écriture
|
// Ouverture du fichier en écriture
|
||||||
$file = fopen($filename, 'w');
|
$file = fopen($filename, 'w');
|
||||||
|
|
||||||
// Écriture des données dans le fichier
|
|
||||||
foreach (self::$courseUsers as $user) {
|
foreach (self::$courseUsers as $user) {
|
||||||
// Décode les entités HTML dans chaque élément du tableau
|
// Décode les entités HTML dans chaque élément du tableau
|
||||||
$decodedUser = array_map('html_entity_decode', $user);
|
$decodedUser = array_map('html_entity_decode', $user);
|
||||||
@ -812,14 +817,13 @@ class course extends common
|
|||||||
// Écrire la ligne dans le fichier CSV
|
// Écrire la ligne dans le fichier CSV
|
||||||
fputcsv($file, $decodedUser, ';');
|
fputcsv($file, $decodedUser, ';');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fermeture du fichier
|
// Fermeture du fichier
|
||||||
fclose($file);
|
fclose($file);
|
||||||
|
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'redirect' => helper::baseUrl(!helper::checkRewrite()) . 'course/user/' . $courseId,
|
'redirect' => helper::baseUrl(!helper::checkRewrite()) . 'course/user/' . $courseId,
|
||||||
'notification' => 'Création ' . basename ($filename) . ' dans le dossier "Export"',
|
'notification' => 'Création ' . basename($filename) . ' dans le dossier "Export"',
|
||||||
'state' => true,
|
'state' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -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
|
// Génération du message d'inscription
|
||||||
public function suscribe()
|
public function suscribe()
|
||||||
{
|
{
|
||||||
@ -863,7 +923,7 @@ class course extends common
|
|||||||
} else {
|
} else {
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'redirect' => helper::baseUrl(!helper::checkRewrite()) . 'course/suscribe/' . $courseId,
|
'redirect' => helper::baseUrl() . 'course/suscribe/' . $courseId,
|
||||||
'state' => false,
|
'state' => false,
|
||||||
'notification' => 'La clé est incorrecte'
|
'notification' => 'La clé est incorrecte'
|
||||||
]);
|
]);
|
||||||
|
@ -8,11 +8,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col1 offset9">
|
<div class="col1 offset9">
|
||||||
<?php echo template::button('userDeleteAll', [
|
<?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'),
|
'value' => template::ico('download'),
|
||||||
'help' => 'Exporter',
|
'help' => 'Exporter',
|
||||||
])
|
]) ?>
|
||||||
?>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col1">
|
<div class="col1">
|
||||||
<?php echo template::button('userDeleteAll', [
|
<?php echo template::button('userDeleteAll', [
|
||||||
@ -20,8 +19,7 @@
|
|||||||
'href' => helper::baseUrl() . 'course/userDeleteAll/' . $this->getUrl(2),
|
'href' => helper::baseUrl() . 'course/userDeleteAll/' . $this->getUrl(2),
|
||||||
'value' => template::ico('trash'),
|
'value' => template::ico('trash'),
|
||||||
'help' => 'Désinscrire tous les utilisateurs',
|
'help' => 'Désinscrire tous les utilisateurs',
|
||||||
])
|
])?>
|
||||||
?>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php echo template::formOpen('courseFilterUserForm'); ?>
|
<?php echo template::formOpen('courseFilterUserForm'); ?>
|
||||||
|
@ -6,6 +6,13 @@
|
|||||||
'value' => template::ico('left')
|
'value' => template::ico('left')
|
||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
<?php if ($module::$userHistory): ?>
|
<?php if ($module::$userHistory): ?>
|
||||||
<div class="row textAlignCenter">
|
<div class="row textAlignCenter">
|
||||||
|
Loading…
Reference in New Issue
Block a user