Refactor module 'machineDefault' et repo 'machine' pour que soit un param du repo, mais automatiquement rempli par le module

This commit is contained in:
xdrm-brackets 2016-07-06 11:56:17 +02:00
parent e3934c9090
commit 798b88caa4
3 changed files with 314 additions and 126 deletions

View File

@ -23,7 +23,11 @@
/* [1] Creation de la machine
=========================================================*/
$create_machine = new Repo('machine/create', [$code, $name]);
$create_machine = new Repo('machine/create', [
$_SESSION['WAREHOUSE']['id'],
$code,
$name
]);
$id_machine = $create_machine->answer();
// Si une erreur est retournee, on retourne une erreur
@ -31,8 +35,6 @@
return ['ModuleError' => ManagerError::ModuleError];
/* [2] Creation du groupe de meme nom que la machine
=========================================================*/
$create_group = new Repo('cluster/create', [$name] );
@ -43,11 +45,14 @@
return ['ModuleError' => ManagerError::ModuleError];
/* [3] Association au groupe
=========================================================*/
$assoc_goup = new Repo('cluster/link', [$id_group, $id_machine, clusterRepo::MACHINE_CLASS]);
$assoc_goup = new Repo('cluster/link', [
$_SESSION['WAREHOUSE']['id'],
$id_group,
$id_machine,
clusterRepo::MACHINE_CLASS]
);
$id_assoc = $assoc_goup->answer();
// Si une erreur est retournee, on retourne une erreur
@ -55,7 +60,6 @@
return ['ModuleError' => ManagerError::ModuleError];
/* [4] Gestion du retour
=========================================================*/
return [
@ -82,7 +86,12 @@
extract($params);
/* Creation de l'association */
$link_machine = new Repo('cluster/link', [$id_cluster, $id_machine, clusterRepo::MACHINE_CLASS]);
$link_machine = new Repo('cluster/link', [
$_SESSION['WAREHOUSE']['id'],
$id_cluster,
$id_machine,
clusterRepo::MACHINE_CLASS
]);
return [];
@ -105,7 +114,12 @@
extract($params);
/* Suppression de l'association */
$link_machine = new Repo('cluster/unlink', [$id_cluster, $id_machine, clusterRepo::MACHINE_CLASS]);
$link_machine = new Repo('cluster/unlink', [
$_SESSION['WAREHOUSE']['id'],
$id_cluster,
$id_machine,
clusterRepo::MACHINE_CLASS
]);
return [];
@ -126,7 +140,10 @@
extract($params);
// On recupere les donnees
$machine = new Repo('machine/search', [$keywords]);
$machine = new Repo('machine/search', [
$_SESSION['WAREHOUSE']['id'],
$keywords
]);
return [ 'machines' => $machine->answer() ];
}
@ -142,7 +159,7 @@
*/
public static function getAll(){
// On recupere les donnees
$machines = new Repo('machine/getAll');
$machines = new Repo('machine/getAll', [$_SESSION['WAREHOUSE']['id']]);
return [ 'machines' => $machines->answer() ];
}
@ -162,7 +179,10 @@
extract($params);
// On recupere les donnees
$request = new Repo('machine/getById', [$id_machine]);
$request = new Repo('machine/getById', [
$_SESSION['WAREHOUSE']['id'],
$id_machine
]);
$answer = $request->answer();
// Si aucun resultat, on retourne une erreur
@ -188,7 +208,10 @@
extract($params);
// On recupere les donnees
$request = new Repo('machine/getByCode', [$code]);
$request = new Repo('machine/getByCode', [
$_SESSION['WAREHOUSE']['id'],
$code
]);
$answer = $request->answer();
// Si aucun resultat, on retourne une erreur
@ -215,7 +238,10 @@
// On recupere les donnees
$request = new Repo('machine/getByName', [$name]);
$request = new Repo('machine/getByName', [
$_SESSION['WAREHOUSE']['id'],
$name
]);
$answer = $request->answer();
// Si aucun resultat, on retourne une erreur
@ -241,7 +267,10 @@
extract($params);
// On recupere les donnees
$request = new Repo('machine/getClusters', [$id_machine]);
$request = new Repo('machine/getClusters', [
$_SESSION['WAREHOUSE']['id'],
$id_machine
]);
$answer = $request->answer();
// Si aucun resultat, on retourne une erreur
@ -271,7 +300,10 @@
/* [1] On verifie l'existence de la machine
=========================================================*/
$machine_exists = new Repo('machine/getById', [$id_machine]);
$machine_exists = new Repo('machine/getById', [
$_SESSION['WAREHOUSE']['id'],
$id_machine
]);
$machine_data = $machine_exists->answer();
// Si on a recupere aucune machine, on retourne une erreur
@ -324,7 +356,10 @@
extract($params);
// On recupere les donnees
$request = new Repo('machine/delete', [$id_machine]);
$request = new Repo('machine/delete', [
$_SESSION['WAREHOUSE']['id'],
$id_machine
]);
$answer = $request->answer();
return [ 'status' => $answer ];

View File

@ -10,6 +10,7 @@
/* CREATION D'UNE MACHINE
*
* @id_warehouse<int> UID de l'entrepot
* @code<String> Code de la machine
* @name<String> Nom de la machine
*
@ -17,7 +18,7 @@
* Renvoie FALSE si une erreur occure
*
*/
public static function create($code, $name){
public static function create($id_warehouse, $code, $name){
/* [1] Verification de l'unicite de code+name
=========================================================*/
$check_unique = ( self::getByCode($code) === false );
@ -33,7 +34,7 @@
$insert_machine = Database::getPDO()->prepare("INSERT INTO machine(id_machine, id_warehouse, code, name)
VALUES(DEFAULT, :id_warehouse, :code, :name)");
$insert_machine->execute([
':id_warehouse' => $_SESSION['WAREHOUSE']['id'],
':id_warehouse' => $id_warehouse,
':code' => $code,
':name' => $name
]);
@ -57,12 +58,13 @@
/* RENVOIE UNE LISTE DE MACHINE EN FONCTION D'UN MOT CLE
*
* @id_warehouse<int> UID de l'entrepot
* @keyword<String> Element de recherche
*
* @return machines<Array> Retourne les machines trouvees
*
*/
public static function search($keyword){
public static function search($id_warehouse, $keyword){
// On recupere les donnees
$searchmachines = Database::getPDO()->prepare("SELECT * FROM machine
WHERE id_warehouse = :id_warehouse
@ -72,7 +74,7 @@
");
$searchmachines->execute([
':id_warehouse' => $_SESSION['WAREHOUSE']['id']
':id_warehouse' => $id_warehouse
]);
return Database::delNumeric( $searchmachines->fetchAll() );
@ -85,20 +87,25 @@
/* RENVOIE LES GROUPES AUQUEL APPARTIENT UNE MACHINE DONNEE
*
* @id_warehouse<int> UID de l'entrepot
* @id_machine<int> UID de la machine en question
*
* @return clusters<Array> Retourne la liste des groupes auquel appartient la machine
*
*/
public static function getClusters($id_machine){
public static function getClusters($id_warehouse, $id_machine){
/* [1] On redige/execute la requete
=========================================================*/
$get_clusters = Database::getPDO()->prepare("SELECT c.* FROM cluster as c, cluster_merge as cm
$get_clusters = Database::getPDO()->prepare("SELECT c.*
FROM cluster as c, cluster_merge as cm, machine as m
WHERE cm.id_cluster = c.id_cluster
AND cm.id_entity = m.id_machine
AND m.id_warehouse = :id_warehouse
AND cm.id_entity = :id_machine
AND cm.class = :class
ORDER BY c.id_cluster");
$get_clusters->execute([
':id_warehouse' => $id_warehouse,
':id_machine' => $id_machine,
':class' => clusterRepo::MACHINE_CLASS
]);
@ -117,6 +124,7 @@
/* MODIFICATION D'UNE MACHINE DONNEE
*
* @id_warehouse<int> UID de l'entrepot
* @id_machine<int> UID de la machine
* @code<String> Code RFID de la machine
* @name<String> Identifiant l'utilisateur
@ -124,7 +132,7 @@
* @return status<Boolean> Renvoie si oui ou non tout s'est bien passe
*
*/
public static function edit($id_machine=null, $code=null, $name=null){
public static function edit($id_warehouse, $id_machine=null, $code=null, $name=null){
/* [1] Verification de l'unicite de code+name (si differents)
=========================================================*/
// On recupere les machine ayant le meme code ou name (si existent)
@ -149,7 +157,7 @@
':code' => $code,
':name' => $name,
':id_machine' => $id_machine,
':id_warehouse' => $_SESSION['WAREHOUSE']['id']
':id_warehouse' => $id_warehouse
]);
@ -175,18 +183,21 @@
/* SUPPRIME UNE MACHINE DONNE
*
* @id_warehouse<int> UID de l'entrepot
* @id_machine<int> UID de la machine en question
*
* @return status<Boolean> Retourne si oui ou non la machine a bien ete supprime
*
*/
public static function delete($id_machine){
public static function delete($id_warehouse, $id_machine){
/* [1] On redige/execute la requete
=========================================================*/
$delete_machine = Database::getPDO()->prepare("DELETE FROM machine WHERE id_machine = :id_machine AND id_warehouse = :id_warehouse");
$delete_machine = Database::getPDO()->prepare("DELETE FROM machine
WHERE id_machine = :id_machine
AND id_warehouse = :id_warehouse");
$delete_machine->execute([
':id_machine' => $id_machine,
':id_warehouse' => $_SESSION['WAREHOUSE']['id']
':id_warehouse' => $id_warehouse
]);
@ -203,6 +214,148 @@
/* RETOURNE UNE MACHINE SPECIFIQUE
*
* @id_warehouse<id> UID de l'entrepot
* @id_machine<id> UID de la machine
*
* @return machine<Array> Données de la machine
* FALSE si aucun résultat
*
*/
public static function getById($id_warehouse, $id_machine){
/* [1] On rédige/execute la requête
=========================================================*/
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
FROM machine as m
WHERE m.id_warehouse = :id_warehouse
AND m.id_machine = :id_machine");
$get->execute([
':id_warehouse' => $id_warehouse,
':id_machine' => $id_machine
]);
/* [2] Gestion des données
=========================================================*/
$found = $get->fetch();
// Si aucun résultat
if( $found === false )
return false;
return Database::delNumeric( $found );
}
/* RETOURNE UNE MACHINE SPECIFIQUE
*
* @id_warehouse<id> UID de l'entrepot
* @code<String> Code RFID de la machine
*
* @return machine<Array> Données de la machine
* FALSE si aucun résultat
*
*/
public static function getByCode($id_warehouse, $code){
/* [1] On rédige/execute la requête
=========================================================*/
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
FROM machine as m
WHERE m.id_warehouse = :id_warehouse
AND m.code = :code");
$get->execute([
':id_warehouse' => $id_warehouse,
':code' => $code
]);
/* [2] Gestion des données
=========================================================*/
$found = $get->fetch();
// Si aucun résultat
if( $found === false )
return false;
return Database::delNumeric( $found );
}
/* RETOURNE UNE MACHINE SPECIFIQUE
*
* @id_warehouse<id> UID de l'entrepot
* @name<String> Nom de la machine
*
* @return machine<Array> Données de la machine
* FALSE si aucun résultat
*
*/
public static function getByName($id_warehouse, $name){
/* [1] On rédige/execute la requête
=========================================================*/
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
FROM machine as m
WHERE m.id_warehouse = :id_warehouse
AND m.name = :name");
$get->execute([
':id_warehouse' => $id_warehouse,
':name' => $name
]);
/* [2] Gestion des données
=========================================================*/
$found = $get->fetch();
// Si aucun résultat
if( $found === false )
return false;
return Database::delNumeric( $found );
}
/* RETOURNE TOUTES LES MACHINES DE L'ENTREPOT
*
* @id_warehouse<id> UID de l'entrepot
*
* @return machines<Array> Données des la machine
*
*/
public static function getAll($id_warehouse){
/* [1] On rédige/execute la requête
=========================================================*/
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
FROM machine as m
WHERE m.id_warehouse = :id_warehouse");
$get->execute([
':id_warehouse' => $id_warehouse
]);
return Database::delNumeric( $get->fetchAll() );
}