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