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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function create($code=null, $name=null){
|
|
|
|
/* [1] Normalisation + verification des donnees
|
|
|
|
=========================================================*/
|
|
|
|
$correct_param = Database::check('machine.code', $code);
|
|
|
|
$correct_param = $correct_param && Database::check('machine.name', $name);
|
|
|
|
|
|
|
|
// Si les parametres ne sont pas corrects, on retourne une erreur
|
|
|
|
if( !$correct_param )
|
|
|
|
return array('ModuleError' => ManagerError::ParamError);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Creation de la machine
|
|
|
|
=========================================================*/
|
|
|
|
$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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] Creation du groupe de meme nom que la machine
|
|
|
|
=========================================================*/
|
|
|
|
$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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] Association au groupe
|
|
|
|
=========================================================*/
|
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
|
|
|
|
|
|
|
|
|
|
|
/* [5] Gestion du retour
|
|
|
|
=========================================================*/
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function link($id_cluster, $id_machine){
|
|
|
|
/* [1] Normalisation + verification des donnees
|
|
|
|
=========================================================*/
|
|
|
|
$correct_param = Database::check('auto_increment_id', $id_cluster);
|
|
|
|
$correct_param = $correct_param && Database::check('auto_increment_id', $id_machine);
|
|
|
|
|
|
|
|
// Si les parametres ne sont pas corrects, on retourne une erreur
|
|
|
|
if( !$correct_param )
|
|
|
|
return array('ModuleError' => ManagerError::ParamError);
|
|
|
|
|
|
|
|
/* [2] Creation de l'association
|
|
|
|
=========================================================*/
|
|
|
|
$link_machine = new Repo('cluster/link', array($id_cluster, $id_machine, clusterRepo::MACHINE_CLASS));
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
return $link_machine;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function unlink($id_cluster, $id_machine){
|
|
|
|
/* [1] Normalisation + verification des donnees
|
|
|
|
=========================================================*/
|
|
|
|
$correct_param = Database::check('auto_increment_id', $id_cluster);
|
|
|
|
$correct_param = $correct_param && Database::check('auto_increment_id', $id_machine);
|
|
|
|
|
|
|
|
// Si les parametres ne sont pas corrects, on retourne une erreur
|
|
|
|
if( !$correct_param )
|
|
|
|
return array('ModuleError' => ManagerError::ParamError);
|
|
|
|
|
|
|
|
/* [2] Suppression de l'association
|
|
|
|
=========================================================*/
|
|
|
|
$link_machine = new Repo('cluster/unlink', array($id_cluster, $id_machine, clusterRepo::MACHINE_CLASS));
|
2016-07-02 15:46:59 +00:00
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
return $link_machine;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 13:32:33 +00:00
|
|
|
/* RENVOIE UNE MACHINE EN FONCTION D'UN MOT CLE
|
|
|
|
*
|
|
|
|
* @keyword<String> Element de recherche
|
|
|
|
*
|
|
|
|
* @return machines<Array> Retourne la liste des machines trouvees
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function search($keyword){
|
|
|
|
// On recupere les donnees
|
|
|
|
$machine = new Repo('machine/search', array($keyword));
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getById($id_machine){
|
|
|
|
// 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 )
|
|
|
|
return array( 'ModuleError' => ManagerError::ModuleError );
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getByCode($code){
|
|
|
|
// On recupere les donnees
|
|
|
|
$request = new Repo('machine/getByCode', array($code));
|
|
|
|
$answer = $request->answer();
|
|
|
|
|
|
|
|
// Si aucun resultat, on retourne une erreur
|
|
|
|
if( $answer === false )
|
|
|
|
return array( 'ModuleError' => ManagerError::ModuleError );
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getClusters($id_machine){
|
|
|
|
// 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 )
|
|
|
|
return array( 'ModuleError' => ManagerError::ModuleError );
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function edit($id_machine=null, $code=null, $name=null){
|
2016-02-16 18:59:55 +00:00
|
|
|
// Si @id_machine n'est pas au bon format, on retourne une erreur
|
|
|
|
if( !Database::check('auto_increment_id', $id_machine) )
|
|
|
|
return array('ModuleError' => ManagerError::ModuleError);
|
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-02-16 14:04:48 +00:00
|
|
|
return array('ModuleError' => ManagerError::ModuleError);
|
|
|
|
|
|
|
|
|
2016-02-16 18:59:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [2] Normalisation + verification des donnees
|
|
|
|
=========================================================*/
|
|
|
|
|
|
|
|
/* (1) Verification des parametres (si correct et different)*/
|
|
|
|
$correct_param = array(
|
|
|
|
'code' => Database::check('machine.code', $code ) && $machine_data['code'] != $code,
|
|
|
|
'name' => Database::check('machine.name', $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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function delete($id_machine){
|
|
|
|
// 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
|
|
|
?>
|