2017-09-28 14:57:30 +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;
|
|
|
|
|
|
|
|
class deployDefault{
|
|
|
|
|
|
|
|
public function __construct(){}
|
|
|
|
public function __destruct(){}
|
|
|
|
|
|
|
|
/* [0] Dispatch pour envoyer les données d'une feature d'une machine
|
|
|
|
*
|
|
|
|
* @etree<String> Nom (complet) de l'e-tree
|
|
|
|
*
|
|
|
|
* @return data<mixed> Données à synchroniser à la machine
|
|
|
|
*
|
|
|
|
=========================================================*/
|
|
|
|
public function dispatch($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
/* (1) On parse le nom complet
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$method_name = str_replace('-', '_', $etree);
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Gestion du dispatch
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Formulation requête */
|
|
|
|
$request = new Request("deployDefault/$method_name", []);
|
|
|
|
|
|
|
|
/* (2) Gestion erreur */
|
|
|
|
if( $request->error->get() != Err::Success )
|
2017-09-28 15:33:16 +00:00
|
|
|
return ['error' => $request->error];
|
2017-09-28 14:57:30 +00:00
|
|
|
|
|
|
|
/* (3) Exécution */
|
|
|
|
$response = $request->dispatch();
|
|
|
|
|
|
|
|
/* (4) Gestion erreur */
|
|
|
|
if( $response->error->get() != Err::Success )
|
2017-09-28 15:33:16 +00:00
|
|
|
return ['error' => $response->error];
|
2017-09-28 14:57:30 +00:00
|
|
|
|
|
|
|
/* (5) Remontée du résultat */
|
|
|
|
return [
|
|
|
|
'data' => $response->get('data')
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Génération des données de fonctionnement de l'etree READ du module RFID
|
|
|
|
*
|
|
|
|
* @data<mixed> Données à traiter
|
|
|
|
*
|
|
|
|
* @return data<mixed> Données à synchroniser (permissions, etc)
|
|
|
|
*
|
|
|
|
=========================================================*/
|
|
|
|
public function rfid_read($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] On récupére la liste des actions
|
|
|
|
=========================================================*/
|
2017-09-28 17:13:22 +00:00
|
|
|
/* (1) On récupère les actions */
|
2017-09-28 14:57:30 +00:00
|
|
|
$actionsReq = new Repo('action/getAll');
|
|
|
|
$actions = ($actionsReq->error->get()==Err::Success) ? $actionsReq->answer() : [];
|
|
|
|
|
|
|
|
|
2017-09-28 17:13:22 +00:00
|
|
|
/* (2) On regroupe les actions par TIMEOUT */
|
2017-09-28 14:57:30 +00:00
|
|
|
$sorted_actions = [];
|
|
|
|
|
|
|
|
foreach($actions as $a=>$action){
|
2017-09-28 17:13:22 +00:00
|
|
|
/* (3) Si aucune valeur pour ce TIMEOUT, on crée un tableau vide */
|
2017-09-28 14:57:30 +00:00
|
|
|
if( !isset($sorted_actions[$action['timeout']]) )
|
|
|
|
$sorted_actions[$action['timeout']] = [];
|
|
|
|
|
2017-09-28 17:13:22 +00:00
|
|
|
/* (4) On ajoute l'action au TIMEOUT */
|
2017-09-28 14:57:30 +00:00
|
|
|
$sorted_actions[$action['timeout']][] = [
|
|
|
|
'id_action' => intval($action['id_action']),
|
|
|
|
'name' => strtolower($action['name']),
|
|
|
|
'required' => $action['required'],
|
|
|
|
'action' => $action['action']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-28 17:13:22 +00:00
|
|
|
/* [2] On récupère les utilisateurs + accès sur la machine
|
2017-09-28 14:57:30 +00:00
|
|
|
=========================================================*/
|
|
|
|
/* (1) On récupère les utilisateurs et leurs permissions */
|
|
|
|
$permissionsReq = new Repo('action_merge/getAccess', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$_SESSION['SATS']['id']
|
|
|
|
]);
|
|
|
|
$permissions = ($permissionsReq->error->get()==Err::Success) ? $permissionsReq->answer() : [];
|
|
|
|
|
|
|
|
/* (2) Pour formatte et indexe les permissions par CODE RFID */
|
|
|
|
$indexed_permissions = [];
|
|
|
|
|
|
|
|
foreach($permissions as $p=>$permission){
|
|
|
|
$actionList = explode(',', $permission['id_action']);
|
|
|
|
|
|
|
|
|
|
|
|
foreach($actionList as $a=>$action)
|
|
|
|
$actionList[$a] = intval($action);
|
|
|
|
|
|
|
|
sort($actionList);
|
|
|
|
|
|
|
|
$indexed_permissions[$permission['code']] = [
|
|
|
|
'id_user' => intval($permission['id_user']),
|
|
|
|
'actions' => $actionList
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Retourne les données récupérées */
|
|
|
|
return [ 'data' => [
|
|
|
|
'actions' => $sorted_actions,
|
|
|
|
'permissions' => $indexed_permissions
|
|
|
|
] ];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|