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
|
|
|
|
*
|
|
|
|
* @code<String> Code RFID de la machine
|
|
|
|
* @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-04 13:45:29 +00:00
|
|
|
$create_machine = new Repo('machine/create', [$code, $name];
|
2016-02-14 13:16:47 +00:00
|
|
|
$id_machine = $create_machine->answer();
|
|
|
|
|
|
|
|
// 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-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-04 13:45:29 +00:00
|
|
|
$create_group = new Repo('cluster/create', [$name] );
|
2016-02-14 13:16:47 +00:00
|
|
|
$id_group = $create_group->answer();
|
|
|
|
|
|
|
|
// 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-03 12:57:25 +00:00
|
|
|
/* [3] Association au groupe
|
2016-02-14 13:16:47 +00:00
|
|
|
=========================================================*/
|
2016-07-04 13:45:29 +00:00
|
|
|
$assoc_goup = new Repo('cluster/link', [$id_group, $id_machine, clusterRepo::MACHINE_CLASS]);
|
2016-02-14 13:16:47 +00:00
|
|
|
$id_assoc = $assoc_goup->answer();
|
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
|
|
|
if( $id_assoc === false )
|
2016-07-04 13:45:29 +00:00
|
|
|
return ['ModuleError' => ManagerError::ModuleError];
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
|
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
/* [4] Gestion du retour
|
2016-02-14 13:16:47 +00:00
|
|
|
=========================================================*/
|
2016-07-04 13:45:29 +00:00
|
|
|
return [
|
2016-02-14 13:16:47 +00:00
|
|
|
'ModuleError' => ManagerError::Success,
|
|
|
|
'id_machine' => $id_machine,
|
|
|
|
'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-04 13:45:29 +00:00
|
|
|
$link_machine = new Repo('cluster/link', [$id_cluster, $id_machine, clusterRepo::MACHINE_CLASS]);
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [];
|
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-04 13:45:29 +00:00
|
|
|
$link_machine = new Repo('cluster/unlink', [$id_cluster, $id_machine, clusterRepo::MACHINE_CLASS]);
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [];
|
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-04 13:45:29 +00:00
|
|
|
$machine = new Repo('machine/search', [$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
|
|
|
|
$machines = new Repo('machine/getAll');
|
|
|
|
|
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-04 13:45:29 +00:00
|
|
|
$request = new Repo('machine/getById', [$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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LA MACHINE DE CODE DONNE
|
|
|
|
*
|
|
|
|
* @code<String> Code de la machine en question
|
|
|
|
*
|
|
|
|
* @return machine<Array> Machine de code donne
|
|
|
|
*
|
|
|
|
*/
|
2016-07-03 12:57:25 +00:00
|
|
|
public static function getByCode($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-02-14 14:30:35 +00:00
|
|
|
// On recupere les donnees
|
2016-07-04 13:45:29 +00:00
|
|
|
$request = new Repo('machine/getByCode', [$code]);
|
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-07-03 12:57:25 +00:00
|
|
|
|
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'machine' => $answer ];
|
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-04 13:45:29 +00:00
|
|
|
$request = new Repo('machine/getByName', [$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-04 13:45:29 +00:00
|
|
|
$request = new Repo('machine/getClusters', [$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 [ '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
|
|
|
|
* @code<String> Code RFID 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-04 13:45:29 +00:00
|
|
|
$machine_exists = new Repo('machine/getById', [$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
|
|
|
'code' => !is_null($code) && $machine_data['code'] != $code,
|
|
|
|
'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
|
|
|
'code' => ($correct_param['code']) ? $code : $machine_data['code'],
|
|
|
|
'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-02-16 18:59:55 +00:00
|
|
|
$id_machine,
|
|
|
|
$opt_data['code'],
|
|
|
|
$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-04 13:45:29 +00:00
|
|
|
$request = new Repo('machine/delete', [$id_machine]);
|
2016-02-14 14:30:35 +00:00
|
|
|
$answer = $request->answer();
|
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
return [ 'status' => $answer ];
|
2016-02-14 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-10 07:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-02 15:46:59 +00:00
|
|
|
?>
|