forked from ZwiiCMS-Team/ZwiiCampus
update :
creation des bases de données report dans les espaces avec les historiques des utilisateurs
This commit is contained in:
parent
0b14519567
commit
e58ce9cda0
@ -225,13 +225,13 @@ class common
|
||||
'language' => '',
|
||||
'profil' => '',
|
||||
'category' => '',
|
||||
'enrolment' => '',
|
||||
];
|
||||
|
||||
private $contentFiles = [
|
||||
'page' => '',
|
||||
'module' => '',
|
||||
'theme' => '',
|
||||
'enrolment' => '',
|
||||
];
|
||||
|
||||
public static $fontsWebSafe = [
|
||||
@ -598,13 +598,13 @@ class common
|
||||
return file_put_contents(self::DATA_DIR . $path . '/content/' . $page . '.html', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Lire les données des historiques
|
||||
* @param string courseId
|
||||
* @param array $keys Clé(s) des données
|
||||
* @return array tableau demandé
|
||||
*/
|
||||
public function getEnrolment($courseId, $keys = [])
|
||||
*/
|
||||
public function getReport($courseId, $keys = [])
|
||||
{
|
||||
$data = json_decode(file_get_contents(self::DATA_DIR . $courseId . '/' . 'enrolment.json'), true);
|
||||
|
||||
@ -635,7 +635,7 @@ class common
|
||||
* @param string contenu de la page
|
||||
* @return int nombre d'octets écrits ou erreur
|
||||
*/
|
||||
public function setEnrolement($courseId, $value)
|
||||
public function setReport($courseId, $value)
|
||||
{
|
||||
return file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
@ -26,23 +26,29 @@ if (
|
||||
if (
|
||||
$this->getData(['core', 'dataVersion']) < 1800
|
||||
) {
|
||||
|
||||
// Déplace les incriptions dans les cours
|
||||
if (file_exists(self::DATA_DIR . 'enrolment.json')) {
|
||||
$old_enrolment = json_decode(file_get_contents(self::DATA_DIR . 'enrolment.json'), true);
|
||||
$old_enrolment = $old_enrolment['enrolment'];
|
||||
foreach ($this->getData(['course']) as $courseId => $courseValues) {
|
||||
if (array_key_exists($courseId, $old_enrolment)) {
|
||||
file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode(['enrolment' => [$courseId => $old_enrolment[$courseId]]], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), LOCK_EX);
|
||||
} else {
|
||||
// Création d'une structure vide
|
||||
file_put_contents(self::DATA_DIR . $courseId . '/enrolment.json', json_encode(['enrolment' => [$courseId => []]], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), LOCK_EX);
|
||||
// Déplace les historiques dans les dossiers des esapaces
|
||||
// Parcourir les espaces
|
||||
foreach ($this->getData(['course']) as $courseId => $courseValues) {
|
||||
$data = [];
|
||||
//Parcourir les participants
|
||||
foreach ($this->getData(['user']) as $userId => $userValues) {
|
||||
// Un historique existe pour ce participant
|
||||
$report = $this->getData(['enrolment', $courseId, $userId, 'history']);
|
||||
if ( is_array($report)
|
||||
) {
|
||||
// Ecriture dans un fichier report dans le dossier de l'espace
|
||||
$data = array_merge($data, [$userId => $report]);
|
||||
// Nettoyage du fichier des inscriptions
|
||||
// Ce fichier ne contient que l'id du participant et de la date et de l'id de la dernière page vue
|
||||
//$this->deleteData(['enrolment', $courseId, $userId, 'history']);
|
||||
}
|
||||
}
|
||||
file_put_contents(self::DATA_DIR . $courseId . '/report.json', json_encode(['report' => $data], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), LOCK_EX);
|
||||
}
|
||||
unlink(self::DATA_DIR . 'enrolment.json');
|
||||
$this->setData(['core', 'dataVersion', 1800]);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
$t = $this->getEnrolment('6571b5913e87e', ['pablorodriguez', 'history', 'les-titres-ou-headers']);
|
||||
echo"<pre>";
|
||||
|
@ -28,8 +28,8 @@ class course extends common
|
||||
'usersDelete' => self::GROUP_EDITOR, //Fait
|
||||
'usersHistoryExport' => self::GROUP_EDITOR, //fait
|
||||
'userDelete' => self::GROUP_EDITOR, //Fait
|
||||
'userHistory' => self::GROUP_EDITOR, //Fait
|
||||
'userHistoryExport' => self::GROUP_EDITOR, //Fait
|
||||
'userReport' => self::GROUP_EDITOR, //Fait
|
||||
'userReportExport' => self::GROUP_EDITOR, //Fait
|
||||
'backup' => self::GROUP_EDITOR, // Fait
|
||||
'restore' => self::GROUP_EDITOR, //Fait
|
||||
'clone' => self::GROUP_ADMIN,
|
||||
@ -74,7 +74,7 @@ class course extends common
|
||||
public static $pagesList = ['accueil' => 'Accueil'];
|
||||
|
||||
|
||||
public static $userHistory = [];
|
||||
public static $userReport = [];
|
||||
|
||||
public static $userGraph = [];
|
||||
|
||||
@ -712,8 +712,8 @@ class course extends common
|
||||
? helper::dateUTF8('%H:%M', $this->getData(['enrolment', $courseId, $userId, 'datePageView']))
|
||||
: '',
|
||||
$this->getData(['user', $userId, 'tags']),
|
||||
template::button('userHistory' . $userId, [
|
||||
'href' => helper::baseUrl() . 'course/userHistory/' . $courseId . '/' . $userId,
|
||||
template::button('userReport' . $userId, [
|
||||
'href' => helper::baseUrl() . 'course/userReport/' . $courseId . '/' . $userId,
|
||||
'value' => !empty ($userValue['history']) ? min(round(($viewPages * 100) / $sumPages, 1), 100) . ' %' : '0%',
|
||||
'disable' => empty ($userValue['history'])
|
||||
]),
|
||||
@ -1164,7 +1164,7 @@ class course extends common
|
||||
/**
|
||||
* Liste les pages consultées par un utilisateur
|
||||
*/
|
||||
public function userHistory()
|
||||
public function userReport()
|
||||
{
|
||||
|
||||
// Espace sélectionné
|
||||
@ -1211,7 +1211,7 @@ class course extends common
|
||||
if (isset ($pages[$pageId]['title'])) {
|
||||
$lastView = ($lastView === 0) ? $time : $lastView;
|
||||
$diff = $time - $lastView;
|
||||
self::$userHistory[] = [
|
||||
self::$userReport[] = [
|
||||
html_entity_decode($pages[$pageId]['title']),
|
||||
$time,
|
||||
($diff < 1800) ? sprintf("%d' %d''", floor($diff / 60), $diff % 60) : "Non significatif",
|
||||
@ -1230,16 +1230,16 @@ class course extends common
|
||||
}
|
||||
|
||||
// Décale les temps de consultation
|
||||
for ($i = 0; $i < count(self::$userHistory) - 1; $i++) {
|
||||
self::$userHistory[$i][2] = self::$userHistory[$i + 1][2];
|
||||
for ($i = 0; $i < count(self::$userReport) - 1; $i++) {
|
||||
self::$userReport[$i][2] = self::$userReport[$i + 1][2];
|
||||
}
|
||||
// Décale les temps de consultation
|
||||
for ($i = 0; $i < count(self::$userGraph) - 1; $i++) {
|
||||
self::$userHistory[$i][1] = self::$userHistory[$i + 1][1];
|
||||
self::$userReport[$i][1] = self::$userReport[$i + 1][1];
|
||||
}
|
||||
|
||||
// Formate le timestamp
|
||||
array_walk(self::$userHistory, function (&$item) {
|
||||
array_walk(self::$userReport, function (&$item) {
|
||||
$item[1] = helper::dateUTF8('%d/%m/%Y %H:%M:%S', $item[1]);
|
||||
});
|
||||
|
||||
@ -1257,7 +1257,7 @@ class course extends common
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => helper::translate('Historique ') . $this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']),
|
||||
'view' => 'userHistory',
|
||||
'view' => 'userReport',
|
||||
'vendor' => [
|
||||
"plotly"
|
||||
]
|
||||
@ -1371,7 +1371,7 @@ class course extends common
|
||||
}
|
||||
}
|
||||
|
||||
public function userHistoryExport()
|
||||
public function userReportExport()
|
||||
{
|
||||
|
||||
$courseId = $this->getUrl(2);
|
||||
@ -1416,7 +1416,7 @@ class course extends common
|
||||
if (isset ($pages[$pageId]['title'])) {
|
||||
$lastView = ($lastView === 0) ? $time : $lastView;
|
||||
$diff = $time - $lastView;
|
||||
self::$userHistory[] = [
|
||||
self::$userReport[] = [
|
||||
$pageId,
|
||||
html_entity_decode($pages[$pageId]['title']),
|
||||
$time,
|
||||
@ -1429,16 +1429,16 @@ class course extends common
|
||||
}
|
||||
|
||||
// Décale les temps de consultation
|
||||
for ($i = 0; $i < count(self::$userHistory) - 1; $i++) {
|
||||
self::$userHistory[$i][3] = self::$userHistory[$i + 1][3];
|
||||
for ($i = 0; $i < count(self::$userReport) - 1; $i++) {
|
||||
self::$userReport[$i][3] = self::$userReport[$i + 1][3];
|
||||
}
|
||||
// Formate le timestamp
|
||||
array_walk(self::$userHistory, function (&$item) {
|
||||
array_walk(self::$userReport, function (&$item) {
|
||||
$item[2] = helper::dateUTF8('%d/%m/%Y %H:%M:%S', $item[2]);
|
||||
});
|
||||
|
||||
// Ajoute les entêtes
|
||||
self::$userHistory = array_merge([0 => ['PageId', 'Page Titre', 'Consultation Date', 'Temps Consultation']], self::$userHistory);
|
||||
self::$userReport = array_merge([0 => ['PageId', 'Page Titre', 'Consultation Date', 'Temps Consultation']], self::$userReport);
|
||||
|
||||
// Dossier d'export
|
||||
if (is_dir(self::FILE_DIR . 'source/' . $courseId) === false) {
|
||||
@ -1451,7 +1451,7 @@ class course extends common
|
||||
|
||||
$file = fopen($filename, 'w');
|
||||
|
||||
foreach (self::$userHistory as $keys => $values) {
|
||||
foreach (self::$userReport as $keys => $values) {
|
||||
$data = $values;
|
||||
// Écrire la ligne dans le fichier CSV
|
||||
fputcsv($file, $data, ';');
|
||||
@ -1461,7 +1461,7 @@ class course extends common
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'course/userHistory/' . $courseId . '/' . $userId,
|
||||
'redirect' => helper::baseUrl() . 'course/userReport/' . $courseId . '/' . $userId,
|
||||
'notification' => 'Création ' . basename($filename) . ' dans le dossier "Export"',
|
||||
'state' => true,
|
||||
]);
|
||||
@ -1895,4 +1895,6 @@ class course extends common
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<div class="row">
|
||||
<div class="col1">
|
||||
<?php echo template::button('courseUserHistoryBack', [
|
||||
<?php echo template::button('courseuserReportBack', [
|
||||
'class' => 'buttonGrey',
|
||||
'href' => helper::baseUrl() . 'course/users/' . $this->getUrl(2),
|
||||
'value' => template::ico('left')
|
||||
@ -8,7 +8,7 @@
|
||||
</div>
|
||||
<div class="col1 offset10">
|
||||
<?php echo template::button('userDeleteAll', [
|
||||
'href' => helper::baseUrl() . 'course/userHistoryExport/' . $this->getUrl(2) . '/' . $this->getUrl(3),
|
||||
'href' => helper::baseUrl() . 'course/userReportExport/' . $this->getUrl(2) . '/' . $this->getUrl(3),
|
||||
'value' => template::ico('download'),
|
||||
'help' => 'Exporter',
|
||||
]) ?>
|
||||
@ -20,7 +20,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($module::$userHistory): ?>
|
||||
<?php if ($module::$userReport): ?>
|
||||
<div class="row">
|
||||
<div class="col4 offset2">
|
||||
<?php if ($this->getData(['course', $this->getUrl(2), 'access']) === self::COURSE_ACCESS_DATE): ?>
|
||||
@ -46,7 +46,7 @@
|
||||
</div>
|
||||
<div class="row textAlignCenter">
|
||||
<div class="col8">
|
||||
<?php echo template::table([6, 3, 3], $module::$userHistory, ['Page', 'Début de Consultation', 'Temps consultation']); ?>
|
||||
<?php echo template::table([6, 3, 3], $module::$userReport, ['Page', 'Début de Consultation', 'Temps consultation']); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
Loading…
Reference in New Issue
Block a user