2016-02-10 07:54:23 +00:00
|
|
|
<?php
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
namespace api\module;
|
2016-11-05 13:57:35 +00:00
|
|
|
use \database\core\DatabaseDriver;
|
2016-02-14 13:16:47 +00:00
|
|
|
use \manager\sessionManager;
|
2016-10-18 17:09:47 +00:00
|
|
|
use \error\core\Error;
|
2017-01-30 18:59:06 +00:00
|
|
|
use \error\core\Err;
|
2016-10-18 14:03:03 +00:00
|
|
|
use \database\core\Repo;
|
2016-02-10 07:54:23 +00:00
|
|
|
|
2016-02-11 15:00:41 +00:00
|
|
|
class machineDefault{
|
2016-02-10 07:54:23 +00:00
|
|
|
|
2017-01-30 17:39:21 +00:00
|
|
|
public function __construct(){}
|
|
|
|
public function __destruct(){}
|
|
|
|
|
2016-02-10 07:54:23 +00:00
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
/* CREATION D'UNE NOUVELLE MACHINE DANS LA BDD
|
|
|
|
*
|
|
|
|
* @name<String> Identifiant de la machine
|
|
|
|
*
|
|
|
|
* @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){
|
2016-07-03 12:57:25 +00:00
|
|
|
extract($params);
|
2016-02-14 13:16:47 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
/* [1] Creation de la machine
|
2016-02-14 13:16:47 +00:00
|
|
|
=========================================================*/
|
2016-07-06 09:56:17 +00:00
|
|
|
$create_machine = new Repo('machine/create', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$name
|
|
|
|
]);
|
2016-07-09 12:13:08 +00:00
|
|
|
$id_machine = $create_machine->answer();
|
2016-02-14 13:16:47 +00:00
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
|
|
|
if( $id_machine === false )
|
2017-02-19 11:14:03 +00:00
|
|
|
return ['error' => new Error(Err::ModuleError)];
|
2016-02-14 13:16:47 +00:00
|
|
|
|
|
|
|
|
2016-07-09 13:06:59 +00:00
|
|
|
|
2016-07-21 09:04:18 +00:00
|
|
|
/* [2] Gestion du retour
|
2016-02-14 13:16:47 +00:00
|
|
|
=========================================================*/
|
2016-07-04 13:45:29 +00:00
|
|
|
return [
|
2016-07-21 09:04:18 +00:00
|
|
|
'id_machine' => $id_machine
|
2016-07-04 13:45:29 +00:00
|
|
|
];
|
2016-02-10 07:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
/* AJOUTE UNE MACHINE DONNEE A UN GROUPE DONNE
|
|
|
|
*
|
|
|
|
* @id_cluster<int> UID du groupe
|
|
|
|
* @id_machine<int> UID de la machine
|
|
|
|
*
|
|
|
|
* @return association<int> Renvoie l'UID de l'association cree
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function link($params){
|
2016-07-03 12:57:25 +00:00
|
|
|
extract($params);
|
2016-02-14 14:17:26 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
/* Creation de l'association */
|
2016-07-20 16:41:24 +00:00
|
|
|
$link_machine = new Repo('machine_cluster/link', [
|
2016-07-06 09:56:17 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_cluster,
|
2016-07-20 16:41:24 +00:00
|
|
|
$id_machine
|
2016-07-06 09:56:17 +00:00
|
|
|
]);
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (1) On retourne l'erreur du repo */
|
2017-01-30 18:59:06 +00:00
|
|
|
return [ 'error' => $link_machine->answer() ];
|
2016-02-14 14:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* RETIRE UNE MACHINE DONNEE A UN GROUPE DONNE
|
|
|
|
*
|
|
|
|
* @id_cluster<int> UID du groupe
|
|
|
|
* @id_machine<int> UID de la machine
|
|
|
|
*
|
|
|
|
* @return association<int> Renvoie l'UID de l'association cree
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function unlink($params){
|
2016-07-03 12:57:25 +00:00
|
|
|
extract($params);
|
2016-02-14 14:17:26 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
/* Suppression de l'association */
|
2016-07-20 15:34:30 +00:00
|
|
|
$link_machine = new Repo('machine_cluster/unlink', [
|
2016-07-06 09:56:17 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_cluster,
|
2016-07-20 16:41:24 +00:00
|
|
|
$id_machine
|
2016-07-06 09:56:17 +00:00
|
|
|
]);
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (1) On retourne l'erreur du repo */
|
2017-01-30 18:59:06 +00:00
|
|
|
return [ 'error' => $link_machine->answer() ];
|
2016-02-14 14:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 13:32:33 +00:00
|
|
|
/* RENVOIE UNE MACHINE EN FONCTION D'UN MOT CLE
|
|
|
|
*
|
2016-07-03 12:57:25 +00:00
|
|
|
* @keywords<String> Element de recherche
|
2016-02-16 13:32:33 +00:00
|
|
|
*
|
2016-07-03 12:57:25 +00:00
|
|
|
* @return machines<Array> Retourne la liste des machines trouvees
|
2016-02-16 13:32:33 +00:00
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function search($params){
|
2016-07-03 12:57:25 +00:00
|
|
|
extract($params);
|
|
|
|
|
2016-02-16 13:32:33 +00:00
|
|
|
// On recupere les donnees
|
2016-07-06 09:56:17 +00:00
|
|
|
$machine = new Repo('machine/search', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$keywords
|
|
|
|
]);
|
2016-02-16 13:32:33 +00:00
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'machines' => $machine->answer() ];
|
2016-02-16 13:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
/* RENVOIE LA LISTE EXHAUSTIVE DES MACHINES
|
|
|
|
*
|
|
|
|
* @return machines<Array> Liste des machines
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function getAll(){
|
2016-02-14 14:30:35 +00:00
|
|
|
// On recupere les donnees
|
2016-07-06 09:56:17 +00:00
|
|
|
$machines = new Repo('machine/getAll', [$_SESSION['WAREHOUSE']['id']]);
|
2016-02-14 14:30:35 +00:00
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'machines' => $machines->answer() ];
|
2016-02-14 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LA MACHINE D'UID DONNE
|
|
|
|
*
|
|
|
|
* @id_machine<int> UID de la machine en question
|
|
|
|
*
|
|
|
|
* @return machine<Array> Machine d'UID donne
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function getById($params){
|
2016-07-03 12:57:25 +00:00
|
|
|
extract($params);
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
// On recupere les donnees
|
2016-07-06 09:56:17 +00:00
|
|
|
$request = new Repo('machine/getById', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_machine
|
|
|
|
]);
|
2016-02-14 14:30:35 +00:00
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
2017-01-30 18:59:06 +00:00
|
|
|
return [ 'error' => new Error(Err::NoMatchFound) ];
|
2016-02-14 14:30:35 +00:00
|
|
|
|
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'machine' => $answer ];
|
2016-02-14 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
/* RENVOIE LA MACHINE DE NAME DONNE
|
|
|
|
*
|
|
|
|
* @name<String> Name de l'utilisateur en question
|
|
|
|
*
|
|
|
|
* @return machine<Array> Machine de name donne
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function getByName($params){
|
2016-07-03 12:57:25 +00:00
|
|
|
extract($params);
|
|
|
|
|
|
|
|
|
|
|
|
// On recupere les donnees
|
2016-07-06 09:56:17 +00:00
|
|
|
$request = new Repo('machine/getByName', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$name
|
|
|
|
]);
|
2016-07-03 12:57:25 +00:00
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
2017-01-30 18:59:06 +00:00
|
|
|
return [ 'error' => new Error(Err::NoMatchFound) ];
|
2016-02-14 14:30:35 +00:00
|
|
|
|
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'machine' => $answer ];
|
2016-02-14 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LES GROUPES D'UNE MACHINE DONNEE
|
|
|
|
*
|
|
|
|
* @id_machine<int> UID de la machine en question
|
|
|
|
*
|
|
|
|
* @return clusters<Array> Groupes de la machine donne
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function getClusters($params){
|
2016-07-03 12:57:25 +00:00
|
|
|
extract($params);
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
// On recupere les donnees
|
2016-07-06 09:56:17 +00:00
|
|
|
$request = new Repo('machine/getClusters', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_machine
|
|
|
|
]);
|
2016-07-18 10:51:32 +00:00
|
|
|
$answer = $request->answer();
|
2016-02-14 14:30:35 +00:00
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
2017-01-30 18:59:06 +00:00
|
|
|
return [ 'error' => new Error(Err::NoMatchFound) ];
|
2016-02-14 14:30:35 +00:00
|
|
|
|
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'clusters' => $answer ];
|
2016-02-14 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 14:04:48 +00:00
|
|
|
/* MODIFIE UNE MACHINE DONNEE
|
|
|
|
*
|
|
|
|
* @id_machine<int> UID de la machine
|
|
|
|
* @name<String> Identifiant l'utilisateur
|
|
|
|
*
|
|
|
|
* @return status<Boolean> Retourne si oui ou non tout s'est bien deroule
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function edit($params){
|
2016-07-03 12:57:25 +00:00
|
|
|
extract($params);
|
2016-02-16 14:04:48 +00:00
|
|
|
|
|
|
|
|
2016-02-16 18:59:55 +00:00
|
|
|
/* [1] On verifie l'existence de la machine
|
2016-02-16 14:04:48 +00:00
|
|
|
=========================================================*/
|
2016-07-06 09:56:17 +00:00
|
|
|
$machine_exists = new Repo('machine/getById', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_machine
|
|
|
|
]);
|
2016-02-16 18:59:55 +00:00
|
|
|
$machine_data = $machine_exists->answer();
|
2016-02-16 14:04:48 +00:00
|
|
|
|
2016-02-16 18:59:55 +00:00
|
|
|
// Si on a recupere aucune machine, on retourne une erreur
|
|
|
|
if( !is_array($machine_data) )
|
2017-01-30 18:59:06 +00:00
|
|
|
return ['error' => new Error(Err::NoMatchFound)];
|
2016-02-16 14:04:48 +00:00
|
|
|
|
|
|
|
|
2016-02-16 18:59:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [2] Normalisation + verification des donnees
|
|
|
|
=========================================================*/
|
|
|
|
|
|
|
|
/* (1) Verification des parametres (si correct et different)*/
|
2016-07-04 13:45:29 +00:00
|
|
|
$correct_param = [
|
2016-07-03 12:57:25 +00:00
|
|
|
'name' => !is_null($name) && $machine_data['name'] != $name
|
2016-07-04 13:45:29 +00:00
|
|
|
];
|
2016-02-16 18:59:55 +00:00
|
|
|
|
|
|
|
/* (2) Gestion des parametres optionnels */
|
2016-07-04 13:45:29 +00:00
|
|
|
$opt_data = [
|
2016-02-16 18:59:55 +00:00
|
|
|
'name' => ($correct_param['name']) ? $name : $machine_data['name']
|
2016-07-04 13:45:29 +00:00
|
|
|
];
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-02-16 18:59:55 +00:00
|
|
|
|
2016-02-16 14:04:48 +00:00
|
|
|
/* [3] Modification de la machine
|
|
|
|
=========================================================*/
|
2016-07-04 13:45:29 +00:00
|
|
|
$request = new Repo('machine/edit', [
|
2016-07-06 10:16:11 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
2016-02-16 18:59:55 +00:00
|
|
|
$id_machine,
|
|
|
|
$opt_data['name']
|
2016-07-04 13:45:29 +00:00
|
|
|
]);
|
2016-02-16 18:59:55 +00:00
|
|
|
|
2016-02-16 14:04:48 +00:00
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'status' => $request->answer() ];
|
2016-02-16 14:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
/* SUPPRIME UNE MACHINE DONNEE
|
|
|
|
*
|
|
|
|
* @id_machine<int> UID de la machine 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){
|
2016-07-03 12:57:25 +00:00
|
|
|
extract($params);
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
// On recupere les donnees
|
2016-07-12 13:16:07 +00:00
|
|
|
$del_machine = new Repo('machine/delete', [
|
2016-07-06 09:56:17 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_machine
|
|
|
|
]);
|
2016-07-12 13:16:07 +00:00
|
|
|
$deleted_machine = $del_machine->answer();
|
|
|
|
|
|
|
|
|
2016-07-20 17:57:05 +00:00
|
|
|
return [ 'status' => $deleted_machine ];
|
2016-02-14 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-18 08:42:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-18 09:03:17 +00:00
|
|
|
/* ENVOI DES DONNEES D'INITIALISATION DU SYSTEME DES MACHINES
|
|
|
|
*
|
2017-02-19 11:14:03 +00:00
|
|
|
* @return id_machine<int> UID de la machine
|
|
|
|
* @return token<string> Nouveau token d'identification (hashage cyclique)
|
|
|
|
* @return unlock<string> Code de déblocage de la machine
|
2016-07-18 09:03:17 +00:00
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function init($params){
|
2016-07-18 09:03:17 +00:00
|
|
|
extract($params);
|
|
|
|
|
2017-02-19 11:14:03 +00:00
|
|
|
|
|
|
|
/* [1] On essaie de débloquer la machine
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) On rédige la requête */
|
|
|
|
$unlockReq = new Repo('machine/unlock', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_machine,
|
|
|
|
$unlock,
|
|
|
|
$token
|
|
|
|
]);
|
|
|
|
|
|
|
|
/* (2) On gère l'erreur */
|
|
|
|
if( $unlockReq->error->get() != Err::Success || !$unlockReq->answer() )
|
|
|
|
return [ 'error' => new Error(Err::TokenError) ];
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On récupére la liste des actions
|
2016-07-18 09:03:17 +00:00
|
|
|
=========================================================*/
|
|
|
|
$actionsReq = new Repo('action/getAll');
|
2017-02-19 08:16:03 +00:00
|
|
|
$actions = ($actionsReq->error->get()==Err::Success) ? $actionsReq->answer() : [];
|
2016-09-09 09:02:56 +00:00
|
|
|
// var_dump($actionsReq->answer());
|
2016-07-18 09:03:17 +00:00
|
|
|
|
2017-02-19 11:14:03 +00:00
|
|
|
|
|
|
|
/* [3] On regroupe les actions par TIMEOUT
|
2016-07-19 09:46:03 +00:00
|
|
|
=========================================================*/
|
|
|
|
$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']][] = [
|
2017-02-19 08:16:03 +00:00
|
|
|
'id_action' => intval($action['id_action']),
|
|
|
|
'name' => strtolower($action['name']),
|
2016-07-19 16:01:16 +00:00
|
|
|
'previous' => $action['previous'],
|
|
|
|
'action' => $action['action']
|
2016-07-19 09:46:03 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-02-19 11:14:03 +00:00
|
|
|
|
|
|
|
/* [4] On récupère la liste des états
|
2016-07-18 09:03:17 +00:00
|
|
|
=========================================================*/
|
2016-07-19 09:27:35 +00:00
|
|
|
$globalStatesReq = new Repo('global_state/getAll');
|
2017-02-19 08:16:03 +00:00
|
|
|
$globalStates = ($globalStatesReq->error->get()==Err::Success) ? $globalStatesReq->answer() : [];
|
2016-07-19 09:27:35 +00:00
|
|
|
|
2017-02-19 11:14:03 +00:00
|
|
|
|
|
|
|
/* [5] On récupère la liste des MODULES (puces)
|
2016-07-19 09:27:35 +00:00
|
|
|
=========================================================*/
|
2016-07-24 10:00:49 +00:00
|
|
|
$chipsReq = new Repo('chip/getAll', [$_SESSION['WAREHOUSE']['id']]);
|
2017-02-19 08:16:03 +00:00
|
|
|
$chips = ($chipsReq->error->get()==Err::Success) ? $chipsReq->answer() : [];
|
2016-07-19 09:27:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
foreach($chips as $c=>$chip){
|
2016-07-19 09:46:03 +00:00
|
|
|
/* [5] On récupére la liste des PINS de chaque PUCE
|
2016-07-19 09:27:35 +00:00
|
|
|
=========================================================*/
|
|
|
|
$pinsReq = new Repo('pin_merge/getByIdChip', [$chip['id_chip']]);
|
2017-02-19 08:16:03 +00:00
|
|
|
$pins = ($pinsReq->error->get()==Err::Success) ? $pinsReq->answer() : [];
|
2016-07-19 09:27:35 +00:00
|
|
|
|
|
|
|
$chips[$c]['pins'] = [];
|
|
|
|
foreach($pins as $p=>$pin)
|
2017-02-19 08:16:03 +00:00
|
|
|
$chips[$c]['pins'][$p] = intval($pin['pin']);
|
2016-07-19 09:27:35 +00:00
|
|
|
|
|
|
|
|
2016-07-19 09:46:03 +00:00
|
|
|
/* [6] On récupère valeurs pour chaque état de chaque PUCE
|
2016-07-19 09:27:35 +00:00
|
|
|
=========================================================*/
|
|
|
|
$chips[$c]['states'] = [];
|
|
|
|
|
|
|
|
$statesReq = new Repo('state/getForChip', [$chip['id_chip']]);
|
2017-02-19 08:16:03 +00:00
|
|
|
$states = ($statesReq->error->get()==Err::Success) ? $statesReq->answer() : [];
|
2016-07-19 09:27:35 +00:00
|
|
|
|
|
|
|
// On met en forme les données : "val1,val2,val3" -> [val1, val2, val3]
|
2017-02-19 08:16:03 +00:00
|
|
|
foreach($states as $s=>$state){
|
|
|
|
|
2016-07-19 09:27:35 +00:00
|
|
|
$chips[$c]['states'][$state['state']] = explode(',', $state['pin_values']);
|
2017-02-19 08:16:03 +00:00
|
|
|
foreach($chips[$c]['states'][$state['state']] as $s2=>$state2)
|
|
|
|
$chips[$c]['states'][$state['state']][$s2] = intval($state2);
|
|
|
|
}
|
2016-07-19 09:27:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-18 09:03:17 +00:00
|
|
|
|
2017-02-19 11:14:03 +00:00
|
|
|
/* [6] On récupère les utilisateurs + accès sur la machine
|
2016-07-19 16:01:16 +00:00
|
|
|
=========================================================*/
|
|
|
|
/* (1) On récupère les utilisateurs et leurs permissions */
|
2017-02-19 08:16:03 +00:00
|
|
|
$permissionsReq = new Repo('action_merge/getAccess', [
|
2016-07-19 16:01:16 +00:00
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_machine
|
|
|
|
]);
|
2017-02-19 08:16:03 +00:00
|
|
|
$permissions = ($permissionsReq->error->get()==Err::Success) ? $permissionsReq->answer() : [];
|
2016-07-19 16:01:16 +00:00
|
|
|
|
|
|
|
/* (2) Pour formatte et indexe les permissions par CODE RFID */
|
|
|
|
$indexed_permissions = [];
|
|
|
|
|
2016-08-06 09:32:50 +00:00
|
|
|
foreach($permissions as $p=>$permission){
|
2017-02-19 08:16:03 +00:00
|
|
|
$actionList = explode(',', $permission['id_action']);
|
|
|
|
|
|
|
|
foreach($actionList as $a=>$action)
|
|
|
|
$actionList[$a] = intval($action);
|
|
|
|
|
2016-08-06 09:32:50 +00:00
|
|
|
sort($actionList);
|
|
|
|
|
2016-07-20 08:55:04 +00:00
|
|
|
$indexed_permissions[$permission['code']] = [
|
2017-02-19 08:16:03 +00:00
|
|
|
'id_user' => intval($permission['id_user']),
|
2016-08-06 09:32:50 +00:00
|
|
|
'actions' => $actionList
|
2016-07-20 08:55:04 +00:00
|
|
|
];
|
2016-08-06 09:32:50 +00:00
|
|
|
}
|
2016-07-19 16:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-18 09:03:17 +00:00
|
|
|
|
2016-07-19 16:01:16 +00:00
|
|
|
/* [N] Retourne les données
|
2016-07-18 09:03:17 +00:00
|
|
|
=========================================================*/
|
|
|
|
return [
|
2016-07-19 17:04:17 +00:00
|
|
|
'actions' => $sorted_actions,
|
|
|
|
'states' => $globalStates,
|
|
|
|
'chips' => $chips,
|
|
|
|
'permissions' => $indexed_permissions
|
2016-07-18 09:03:17 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
}
|
2016-07-18 08:42:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-07 15:59:31 +00:00
|
|
|
/* SYNCHRONISE UNE MACHINE
|
|
|
|
*
|
|
|
|
* @token<String> Token de synchronisation de la machine
|
|
|
|
* @data<Array> Données de la synchronisation
|
2016-07-17 08:27:59 +00:00
|
|
|
* @renew<String> Renouvellement du token de synchronisation de la machine (opt.)
|
2016-07-07 15:59:31 +00:00
|
|
|
*
|
|
|
|
* @return data<Array> Données de retour de synchronisation
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
public function sync($params){
|
2016-07-07 15:59:31 +00:00
|
|
|
extract($params);
|
|
|
|
|
2016-07-17 08:27:59 +00:00
|
|
|
/* [0] Vérification du token
|
|
|
|
=========================================================*/
|
|
|
|
$checkToken = new Repo('machine/checkToken', [ $_SESSION['WAREHOUSE']['id'], $token, $renew ]);
|
|
|
|
|
|
|
|
// Si token incorrect, on envoie une erreur
|
2017-02-19 14:46:52 +00:00
|
|
|
if( !$checkToken->answer() )
|
2017-01-30 18:59:06 +00:00
|
|
|
return [ 'error' => new Error(Err::TokenError) ];
|
2016-07-17 08:27:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Initialisation des variables
|
|
|
|
=========================================================*/
|
|
|
|
$data = ['a', 'b'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Données à reçues
|
|
|
|
=========================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] Données à envoyer
|
|
|
|
=========================================================*/
|
|
|
|
|
2016-07-07 15:59:31 +00:00
|
|
|
|
|
|
|
return [
|
2016-07-17 08:27:59 +00:00
|
|
|
'data' => $data
|
2016-07-07 15:59:31 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
|
2016-02-10 07:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-02 15:46:59 +00:00
|
|
|
?>
|