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
|
|
|
=========================================================*/
|
|
|
|
$create_machine = new Repo('machine/create', array($code, $name) );
|
|
|
|
$id_machine = $create_machine->answer();
|
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
|
|
|
if( $id_machine === false )
|
|
|
|
return array('ModuleError' => ManagerError::ModuleError);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
=========================================================*/
|
|
|
|
$create_group = new Repo('cluster/create', array($name) );
|
|
|
|
$id_group = $create_group->answer();
|
|
|
|
|
|
|
|
// Si une erreur est retournee, on retourne une erreur
|
|
|
|
if( $id_group === false )
|
|
|
|
return array('ModuleError' => ManagerError::ModuleError);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
/* [3] Association au groupe
|
2016-02-14 13:16:47 +00:00
|
|
|
=========================================================*/
|
2016-02-14 14:17:26 +00:00
|
|
|
$assoc_goup = new Repo('cluster/link', array($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 )
|
|
|
|
return array('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-02-10 07:54:23 +00:00
|
|
|
return array(
|
2016-02-14 13:16:47 +00:00
|
|
|
'ModuleError' => ManagerError::Success,
|
|
|
|
'id_machine' => $id_machine,
|
|
|
|
'id_cluster' => $id_group
|
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-02-14 14:17:26 +00:00
|
|
|
$link_machine = new Repo('cluster/link', array($id_cluster, $id_machine, clusterRepo::MACHINE_CLASS));
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
return array();
|
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-02-14 14:17:26 +00:00
|
|
|
$link_machine = new Repo('cluster/unlink', array($id_cluster, $id_machine, clusterRepo::MACHINE_CLASS));
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
return array();
|
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-03 12:57:25 +00:00
|
|
|
$machine = new Repo('machine/search', array($keywords));
|
2016-02-16 13:32:33 +00:00
|
|
|
|
|
|
|
return array(
|
|
|
|
'machines' => $machine->answer()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'machines' => $machines->answer()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
$request = new Repo('machine/getById', array($id_machine));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
2016-07-03 12:57:25 +00:00
|
|
|
return array( 'ModuleError' => ManagerError::NoMatchFound );
|
2016-02-14 14:30:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'machine' => $answer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
$request = new Repo('machine/getByCode', array($code));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
2016-07-03 12:57:25 +00:00
|
|
|
return array( 'ModuleError' => ManagerError::NoMatchFound );
|
|
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'machine' => $answer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
$request = new Repo('machine/getByName', array($name));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
|
|
|
return array( 'ModuleError' => ManagerError::NoMatchFound );
|
2016-02-14 14:30:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'machine' => $answer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
$request = new Repo('machine/getClusters', array($id_machine));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
2016-07-03 12:57:25 +00:00
|
|
|
return array( 'ModuleError' => ManagerError::NoMatchFound );
|
2016-02-14 14:30:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'clusters' => $answer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
=========================================================*/
|
|
|
|
$machine_exists = new Repo('machine/getById', array($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-03 12:57:25 +00:00
|
|
|
return array('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)*/
|
|
|
|
$correct_param = array(
|
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-02 15:46:59 +00:00
|
|
|
);
|
2016-02-16 18:59:55 +00:00
|
|
|
|
|
|
|
/* (2) Gestion des parametres optionnels */
|
|
|
|
$opt_data = array(
|
|
|
|
'code' => ($correct_param['code']) ? $code : $machine_data['code'],
|
|
|
|
'name' => ($correct_param['name']) ? $name : $machine_data['name']
|
|
|
|
);
|
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-02-16 18:59:55 +00:00
|
|
|
$request = new Repo('machine/edit', array(
|
|
|
|
$id_machine,
|
|
|
|
$opt_data['code'],
|
|
|
|
$opt_data['name']
|
|
|
|
));
|
|
|
|
|
2016-02-16 14:04:48 +00:00
|
|
|
|
|
|
|
return array(
|
2016-02-16 18:59:55 +00:00
|
|
|
'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
|
|
|
|
$request = new Repo('machine/delete', array($id_machine));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'status' => $answer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-10 07:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-02 15:46:59 +00:00
|
|
|
?>
|