181 lines
5.1 KiB
PHP
181 lines
5.1 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 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 )
|
|
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 [
|
|
'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
|
|
=========================================================*/
|
|
$actionsReq = new Repo('action/getAll');
|
|
$actions = ($actionsReq->error->get()==Err::Success) ? $actionsReq->answer() : [];
|
|
// var_dump($actionsReq->answer());
|
|
|
|
|
|
/* [2] On regroupe les actions par TIMEOUT
|
|
=========================================================*/
|
|
$sorted_actions = [];
|
|
|
|
foreach($actions as $a=>$action){
|
|
/* (1) Si aucune valeur pour ce TIMEOUT, on crée un tableau vide */
|
|
if( !isset($sorted_actions[$action['timeout']]) )
|
|
$sorted_actions[$action['timeout']] = [];
|
|
|
|
/* (2) On ajoute l'action au TIMEOUT */
|
|
$sorted_actions[$action['timeout']][] = [
|
|
'id_action' => intval($action['id_action']),
|
|
'name' => strtolower($action['name']),
|
|
'required' => $action['required'],
|
|
'action' => $action['action']
|
|
];
|
|
}
|
|
|
|
|
|
/* [3] On récupère la liste des états
|
|
=========================================================*/
|
|
$globalStatesReq = new Repo('global_state/getAll');
|
|
$globalStates = ($globalStatesReq->error->get()==Err::Success) ? $globalStatesReq->answer() : [];
|
|
|
|
|
|
/* [4] On récupère la liste des MODULES (puces)
|
|
=========================================================*/
|
|
$chipsReq = new Repo('chip/getForMachine', [$_SESSION['WAREHOUSE']['id'], $_SESSION['SATS']['id']]);
|
|
$chips = ($chipsReq->error->get()==Err::Success) ? $chipsReq->answer() : [];
|
|
|
|
|
|
foreach($chips as &$chip){
|
|
/* (1) On récupére la liste des PINS de chaque PUCE
|
|
---------------------------------------------------------*/
|
|
|
|
$chip['pins'] = explode(',', $chip['pins']);
|
|
|
|
if( !is_array($chip['pins']) )
|
|
$chip['pins'] = [];
|
|
|
|
/* (2) On récupère valeurs pour chaque état de chaque PUCE
|
|
---------------------------------------------------------*/
|
|
$chip['states'] = [];
|
|
|
|
$statesReq = new Repo('state/getForChip', [$chip['id_chip']]);
|
|
$states = ($statesReq->error->get()==Err::Success) ? $statesReq->answer() : [];
|
|
|
|
// On met en forme les données : "val1,val2,val3" -> [val1, val2, val3]
|
|
foreach($states as $s=>$state){
|
|
|
|
$chip['states'][$state['state']] = explode(',', $state['value']);
|
|
|
|
foreach($chip['states'][$state['state']] as $s2=>$state2)
|
|
$chip['states'][$state['state']][$s2] = intval($state2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/* [5] On récupère les utilisateurs + accès sur la machine
|
|
=========================================================*/
|
|
/* (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,
|
|
'states' => $globalStates,
|
|
'chips' => $chips,
|
|
'permissions' => $indexed_permissions
|
|
] ];
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|