2016-02-10 07:54:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager\module;
|
2016-02-14 13:16:47 +00:00
|
|
|
use \manager\Database;
|
|
|
|
use \manager\sessionManager;
|
|
|
|
use \manager\ManagerError;
|
|
|
|
use \manager\Repo;
|
2016-02-14 14:17:26 +00:00
|
|
|
use \manager\repo\cluster as clusterRepo;
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-03 12:57:25 +00:00
|
|
|
public static function create($params){
|
|
|
|
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 )
|
2016-07-04 13:45:29 +00:00
|
|
|
return ['ModuleError' => ManagerError::ModuleError];
|
2016-02-14 13:16:47 +00:00
|
|
|
|
|
|
|
|
2016-07-09 13:06:59 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
/* [2] Creation du groupe de meme nom que la machine
|
2016-02-14 13:16:47 +00:00
|
|
|
=========================================================*/
|
2016-07-06 10:16:11 +00:00
|
|
|
$create_group = new Repo('cluster/create', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
2016-07-08 15:47:03 +00:00
|
|
|
$name,
|
2016-07-10 10:06:41 +00:00
|
|
|
clusterRepo::MACHINE_CLASS,
|
|
|
|
$id_machine
|
2016-07-06 10:16:11 +00:00
|
|
|
]);
|
|
|
|
$id_group = $create_group->answer();
|
2016-02-14 13:16:47 +00:00
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
|
|
|
if( $id_group === false )
|
2016-07-04 13:45:29 +00:00
|
|
|
return ['ModuleError' => ManagerError::ModuleError];
|
2016-02-14 13:16:47 +00:00
|
|
|
|
2016-07-10 13:23:53 +00:00
|
|
|
|
|
|
|
/* [3] Gestion du retour
|
2016-02-14 13:16:47 +00:00
|
|
|
=========================================================*/
|
2016-07-04 13:45:29 +00:00
|
|
|
return [
|
2016-07-06 09:56:17 +00:00
|
|
|
'id_machine' => $id_machine,
|
2016-02-14 13:16:47 +00:00
|
|
|
'id_cluster' => $id_group
|
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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-03 12:57:25 +00:00
|
|
|
public static function link($params){
|
|
|
|
extract($params);
|
2016-02-14 14:17:26 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
/* Creation de l'association */
|
2016-07-06 09:56:17 +00:00
|
|
|
$link_machine = new Repo('cluster/link', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_cluster,
|
|
|
|
$id_machine,
|
|
|
|
clusterRepo::MACHINE_CLASS
|
|
|
|
]);
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (1) On retourne l'erreur du repo */
|
|
|
|
return [ 'ModuleError' => $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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-03 12:57:25 +00:00
|
|
|
public static function unlink($params){
|
|
|
|
extract($params);
|
2016-02-14 14:17:26 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
/* Suppression de l'association */
|
2016-07-06 09:56:17 +00:00
|
|
|
$link_machine = new Repo('cluster/unlink', [
|
|
|
|
$_SESSION['WAREHOUSE']['id'],
|
|
|
|
$id_cluster,
|
|
|
|
$id_machine,
|
|
|
|
clusterRepo::MACHINE_CLASS
|
|
|
|
]);
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (1) On retourne l'erreur du repo */
|
|
|
|
return [ 'ModuleError' => $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
|
|
|
*
|
|
|
|
*/
|
2016-07-03 12:57:25 +00:00
|
|
|
public static function search($params){
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getAll(){
|
|
|
|
// 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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-03 12:57:25 +00:00
|
|
|
public static function getById($params){
|
|
|
|
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 )
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'ModuleError' => ManagerError::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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getByName($params){
|
|
|
|
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 )
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'ModuleError' => ManagerError::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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-03 12:57:25 +00:00
|
|
|
public static function getClusters($params){
|
|
|
|
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 )
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'ModuleError' => ManagerError::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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-03 12:57:25 +00:00
|
|
|
public static function edit($params){
|
|
|
|
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) )
|
2016-07-04 13:45:29 +00:00
|
|
|
return ['ModuleError' => ManagerError::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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-03 12:57:25 +00:00
|
|
|
public static function delete($params){
|
|
|
|
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();
|
|
|
|
|
|
|
|
if( !$deleted_machine )
|
|
|
|
return [ 'status' => false ];
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On récupère le groupe personnel
|
|
|
|
=========================================================*/
|
|
|
|
$get_personal_cluster = new Repo('cluster/getPersonal', [
|
|
|
|
$id_warehouse,
|
|
|
|
$id_machine,
|
|
|
|
clusterRepo::MACHINE_CLASS
|
|
|
|
]);
|
|
|
|
|
|
|
|
$personal_cluster = $get_personal_cluster->answer();
|
|
|
|
|
|
|
|
// si erreur
|
|
|
|
if( $personal_cluster === false )
|
|
|
|
return [ 'status' => false ];
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] On supprime le groupe personnel
|
|
|
|
=========================================================*/
|
|
|
|
$del_cluster = new Repo('cluster/delete', [
|
|
|
|
$id_warehouse,
|
|
|
|
$personal_cluster['id_cluster']
|
|
|
|
]);
|
|
|
|
|
|
|
|
$deleted = $del_cluster->answer();
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
|
2016-07-12 13:16:07 +00:00
|
|
|
return [ 'status' => $deleted ];
|
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
|
|
|
|
*
|
|
|
|
* @return data<Array> Données d'initialisation du système
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function init($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
/* [1] On récupére la liste des actions
|
|
|
|
=========================================================*/
|
|
|
|
$actionsReq = new Repo('action/getAll');
|
|
|
|
$actions = ($actionsReq->error==0) ? $actionsReq->answer() : [];
|
|
|
|
|
|
|
|
/* [2] On récupère la liste des états
|
|
|
|
=========================================================*/
|
|
|
|
$statesReq = new Repo('state/getAll');
|
|
|
|
$states = ($statesReq->error==0) ? $statesReq->answer() : [];
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] Retorne les données
|
|
|
|
=========================================================*/
|
|
|
|
return [
|
|
|
|
'actions' => $actions,
|
|
|
|
'states' => $states
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function sync($params){
|
|
|
|
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
|
|
|
|
if( $checkToken->answer() !== true )
|
|
|
|
return [ 'ModuleError' => ManagerError::TokenError ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [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
|
|
|
?>
|