2017-09-26 15:28:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace api\module;
|
|
|
|
use \database\core\DatabaseDriver;
|
|
|
|
use \manager\sessionManager;
|
|
|
|
use \error\core\Error;
|
|
|
|
use \error\core\Err;
|
|
|
|
use \database\core\Repo;
|
|
|
|
use \api\core\Request;
|
|
|
|
|
2017-09-28 14:57:30 +00:00
|
|
|
class fetchDefault{
|
2017-09-26 15:28:09 +00:00
|
|
|
|
|
|
|
public function __construct(){}
|
|
|
|
public function __destruct(){}
|
|
|
|
|
|
|
|
/* [0] Dispatch des données d'une feature d'une machine
|
|
|
|
*
|
|
|
|
* @etree<String> Nom (complet) de l'e-tree
|
|
|
|
* @data<mixed> Données à traiter
|
|
|
|
*
|
|
|
|
* @return saved<numeric> Code de réception (nombre d'entrées ou autre)
|
|
|
|
*
|
|
|
|
=========================================================*/
|
|
|
|
public function dispatch($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
/* (1) On parse le nom complet
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Requête */
|
|
|
|
$etree_parse_req = new Repo('etree/parse', [$etree]);
|
|
|
|
|
|
|
|
/* (2) On récupère la réponse */
|
|
|
|
$etree_data = $etree_parse_req->answer();
|
|
|
|
|
|
|
|
/* (3) Gestion erreur */
|
|
|
|
if( $etree_data === false )
|
|
|
|
return ['error' => new Error(Err::FormatError)];
|
|
|
|
|
|
|
|
/* (4) On calcule le nom de la méthode */
|
|
|
|
$method_name = $etree_data['module_name'].'_'.$etree_data['etree_name'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Gestion du dispatch
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Formulation requête */
|
2017-09-28 14:57:30 +00:00
|
|
|
$request = new Request("fetchDefault/$method_name", [
|
2017-09-26 15:28:09 +00:00
|
|
|
'data' => $data
|
|
|
|
]);
|
|
|
|
|
|
|
|
/* (2) Gestion erreur */
|
|
|
|
if( $request->error->get() != Err::Success )
|
|
|
|
return ['error' => new Error(Err::ModuleError)];
|
|
|
|
|
|
|
|
/* (3) Exécution */
|
|
|
|
$response = $request->dispatch();
|
|
|
|
|
|
|
|
/* (4) Gestion erreur */
|
|
|
|
if( $response->error->get() != Err::Success )
|
|
|
|
return ['error' => new Error(Err::ModuleError)];
|
|
|
|
|
|
|
|
/* (5) Remontée du résultat */
|
|
|
|
return [
|
|
|
|
'saved' => $response->get('saved')
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Gestion des données historiques de l'etree READ du module RFID
|
|
|
|
*
|
|
|
|
* @data<mixed> Données à traiter
|
|
|
|
*
|
|
|
|
* @return saved<numeric> Nombre de lignes ajoutées
|
|
|
|
*
|
|
|
|
=========================================================*/
|
|
|
|
public function rfid_read($params){
|
2017-09-27 16:32:30 +00:00
|
|
|
extract($params);
|
2017-09-26 15:28:09 +00:00
|
|
|
|
|
|
|
/* (1) Initialisation du compteur de lignes enregistrées */
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Create history entry in db */
|
|
|
|
foreach($data as $entry){
|
|
|
|
|
|
|
|
// {1} Build request to store each entry //
|
|
|
|
$log_req = new Request('historyDefault/create', [
|
|
|
|
'timestamp' => $entry[0],
|
|
|
|
'id_user' => $entry[1],
|
|
|
|
'id_action' => $entry[2],
|
|
|
|
'id_machine' => $_SESSION['SATS']['id']
|
|
|
|
]);
|
|
|
|
|
|
|
|
// {2} Process + get response //
|
|
|
|
$log_res = $log_req->dispatch();
|
|
|
|
|
2017-10-13 14:46:30 +00:00
|
|
|
// {3} Ignore failure //
|
|
|
|
// if( $log_res->error->get() != Err::Success )
|
|
|
|
// continue;
|
2017-09-26 15:28:09 +00:00
|
|
|
|
|
|
|
// {4} Register count if success //
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Retourne le nombre d'entrées enregistrées */
|
|
|
|
return [ 'saved' => $count ];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-13 14:46:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Gestion des données historiques de l'etree SIMPLE du module MOTHEURE
|
|
|
|
*
|
|
|
|
* @data<mixed> Données à traiter
|
|
|
|
*
|
|
|
|
* @return saved<numeric> Nombre de lignes ajoutées
|
|
|
|
*
|
|
|
|
=========================================================*/
|
|
|
|
public function motheure_simple($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
/* (1) Initialize data
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Initialisation du compteur de lignes enregistrées */
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
/* (2) Calcl the total to add */
|
|
|
|
$total = 0;
|
|
|
|
|
|
|
|
foreach($data as $entry){
|
|
|
|
|
|
|
|
// Only if positive numeric
|
|
|
|
if( is_numeric($entry) && $entry > 0 )
|
|
|
|
$total += intval($entry);
|
|
|
|
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (2) Update the table in the database
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Build request to store each entry */
|
|
|
|
$upd_req = new Request('motheure/increment', [
|
|
|
|
'count' => $total
|
|
|
|
]);
|
|
|
|
|
2017-10-13 16:43:52 +00:00
|
|
|
/* (2) Process + get response */
|
2017-10-13 16:39:51 +00:00
|
|
|
$upd_res = $upd_req->dispatch();
|
2017-10-13 14:46:30 +00:00
|
|
|
|
2017-10-13 16:43:52 +00:00
|
|
|
/* (3) Manage error */
|
|
|
|
if( $upd_res->error->get() != Err::Success )
|
|
|
|
return ['error' => $upd_res->error];
|
|
|
|
|
|
|
|
/* (4) Retourne le nombre d'entrées enregistrées */
|
2017-10-13 14:46:30 +00:00
|
|
|
return [ 'saved' => $count ];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-26 15:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|