2017-01-11 15:28:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace api\module;
|
|
|
|
use \database\core\DatabaseDriver;
|
|
|
|
use \manager\sessionManager;
|
|
|
|
use \error\core\Error;
|
2017-02-21 14:16:21 +00:00
|
|
|
use \error\core\Err;
|
2017-01-11 15:28:21 +00:00
|
|
|
use \database\core\Repo;
|
|
|
|
|
|
|
|
class historyDefault{
|
|
|
|
|
2017-01-30 17:39:21 +00:00
|
|
|
public function __construct(){}
|
|
|
|
public function __destruct(){}
|
2017-01-11 15:28:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* CREATION D'UNE NOUVELLE ENTREE DANS LA BDD
|
|
|
|
*
|
|
|
|
* @id_user<int> UID de l'utilisateur
|
|
|
|
* @id_machine<int> UID la machine
|
|
|
|
* @id_action<int> UID de l'action
|
|
|
|
* @timestamp<int> timestamp de l'action
|
|
|
|
*
|
|
|
|
* @return status<Boolean> Retourne si oui ou non, tout s'est bien passe
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function create($params){
|
2017-01-11 15:28:21 +00:00
|
|
|
extract($params);
|
|
|
|
|
|
|
|
/* [1] Creation de l'utilisateur
|
|
|
|
=========================================================*/
|
|
|
|
$create_entry = new Repo('history/create', [
|
2017-02-20 07:21:34 +00:00
|
|
|
$id_user,
|
2017-01-11 15:28:21 +00:00
|
|
|
$id_machine,
|
|
|
|
$id_action,
|
|
|
|
$timestamp
|
|
|
|
]);
|
|
|
|
$id_entry = $create_entry->answer();
|
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
|
|
|
if( $id_entry === false )
|
2017-02-21 14:16:21 +00:00
|
|
|
return ['error' => new Error(Err::ModuleError)];
|
2017-01-11 15:28:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [2] Gestion du retour
|
|
|
|
=========================================================*/
|
|
|
|
return [
|
|
|
|
'id_history' => $id_entry
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE UN UTILISATEUR EN FONCTION D'UN MOT CLE
|
|
|
|
*
|
|
|
|
* @keywords<String> Element de recherche
|
|
|
|
*
|
|
|
|
* @return users<Array> Retourne la liste des utilisateurs trouves
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function search($params){
|
2017-01-11 15:28:21 +00:00
|
|
|
extract($params);
|
|
|
|
|
|
|
|
// On recupere les donnees
|
|
|
|
$user = new Repo('history/search', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$keywords
|
|
|
|
]);
|
|
|
|
|
|
|
|
return [ 'history' => $user->answer() ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LA LISTE EXHAUSTIVE DES ACCES
|
|
|
|
*
|
|
|
|
* @return history<Array> Liste des entrées de l'historique
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function getAll(){
|
2017-01-11 15:28:21 +00:00
|
|
|
// On recupere les donnees
|
|
|
|
$entries = new Repo('history/getAll', [ $_SESSION['WAREHOUSE']['id'] ]);
|
|
|
|
|
|
|
|
return [ 'history' => $entries->answer() ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* SUPPRIME UNE ENTREE
|
|
|
|
*
|
|
|
|
* @id_history<int> UID de l'entree en question
|
|
|
|
*
|
|
|
|
* @return status<Boolean> Retourne si oui ou non tout s'est bien deroule
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function delete($params){
|
2017-01-11 15:28:21 +00:00
|
|
|
extract($params);
|
|
|
|
|
|
|
|
/* [1] On supprime l'utilisateur
|
|
|
|
=========================================================*/
|
|
|
|
$del_entry = new Repo('history/delete', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_history
|
|
|
|
]);
|
|
|
|
$deleted_entry = $del_entry->answer();
|
|
|
|
|
|
|
|
|
|
|
|
return [ 'status' => $deleted_entry ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-29 18:08:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* ARCHIVE L'HISTORIQUE D'UN ENTREPOT
|
|
|
|
*
|
|
|
|
* @return archive<File> Fichier de l'archive (.csv format)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function archive($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
/* [1] Récupération des logs
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Requête */
|
|
|
|
$logs = new Repo('history/getAll', [$_SESSION['WAREHOUSE']['id']]);
|
|
|
|
|
|
|
|
/* (2) Gestion erreur */
|
|
|
|
if( $logs->error->get() != Err::Success )
|
|
|
|
return [ 'error' => $logs->error ];
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Création du contenu fichier
|
|
|
|
=========================================================*/
|
|
|
|
$BODY = "TIMESTAMP,MACHINE,UTILISATEUR,ACTION\n";
|
|
|
|
|
|
|
|
foreach($logs->answer() as $log)
|
|
|
|
$BODY .= $log['timestamp'].','.$log['machine_name'].','.$log['user_name'].','.$log['action_name']."\n";
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] Renvoi du fichier
|
|
|
|
=========================================================*/
|
|
|
|
return [
|
|
|
|
'headers' => [
|
|
|
|
'Content-Type' => 'text/csv',
|
|
|
|
'Content-Disposition' => 'attachment; filename=archive-'.date('dmY').'.csv'
|
|
|
|
],
|
|
|
|
'body' => $BODY
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-11-11 17:46:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (x) Return the machine history for an history entry
|
|
|
|
*
|
|
|
|
* @id_entry<id> UID of the history entry
|
|
|
|
*
|
|
|
|
* @return timeline<array> Machine timeline data
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
|
|
|
|
public function get_timeline($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
/* (1) Get history entry data
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Request */
|
|
|
|
$entry = new Repo('history/getById', [$id_entry]);
|
|
|
|
|
|
|
|
/* (2) Get response */
|
|
|
|
$entry = $entry->answer();
|
|
|
|
|
|
|
|
/* (3) Manage error */
|
|
|
|
if( !is_array($entry) )
|
|
|
|
return ['error' => new Error(Err::RepoError)];
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Get history for machine
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Request */
|
|
|
|
$timeline = new Repo('history/getByIdMachine', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$entry['id_machine']
|
|
|
|
]);
|
|
|
|
|
|
|
|
/* (2) Get response */
|
|
|
|
$timeline = $timeline->answer();
|
|
|
|
|
|
|
|
/* (3) Manage error */
|
|
|
|
if( $timeline === false )
|
|
|
|
return ['error' => new Error(Err::RepoError)];
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Return data
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
return [ 'timeline' => $timeline ];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-12 12:01:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (x) Return the entry data for an history id
|
|
|
|
*
|
|
|
|
* @id_entry<id> UID of the history entry
|
|
|
|
*
|
|
|
|
* @return data<array> Entry data
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
|
|
|
|
public function getById($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
/* (1) Get history entry data
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Request */
|
|
|
|
$entry = new Repo('history/getById', [$id_entry]);
|
|
|
|
|
|
|
|
/* (2) Get response */
|
|
|
|
$entry = $entry->answer();
|
|
|
|
|
|
|
|
/* (3) Manage error */
|
|
|
|
if( !is_array($entry) )
|
|
|
|
return ['error' => new Error(Err::RepoError)];
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Return data
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
return [ 'entry' => $entry ];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-11 15:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|