121 lines
2.8 KiB
PHP
121 lines
2.8 KiB
PHP
|
<?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;
|
||
|
|
||
|
class moduleDefault{
|
||
|
|
||
|
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 */
|
||
|
$request = new Request("moduleDefault/$method_name", [
|
||
|
'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){
|
||
|
|
||
|
/* (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();
|
||
|
|
||
|
// {3} Exit on failure //
|
||
|
if( $log_res->error->get() != Err::Success )
|
||
|
break;
|
||
|
|
||
|
// {4} Register count if success //
|
||
|
$count++;
|
||
|
}
|
||
|
|
||
|
|
||
|
/* (3) Retourne le nombre d'entrées enregistrées */
|
||
|
return [ 'saved' => $count ];
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
?>
|