diff --git a/manager/repo/cluster.php b/manager/repo/cluster.php index 2f868d1..cdef24a 100755 --- a/manager/repo/cluster.php +++ b/manager/repo/cluster.php @@ -14,16 +14,17 @@ /* CREATION D'UN GROUPE * + * @id_warehouse UID de l'entrepot * @name Nom du groupe * * @return id_user Renvoie l'UID du groupe cree * Renvoie FALSE si une erreur occure * */ - public static function create($name){ + public static function create($id_warehouse, $name){ /* [1] Verification de l'unicite de name =========================================================*/ - $check_unique = ( self::getByName($name) === false ); + $check_unique = ( self::getByName($id_warehouse, $name) === false ); // Si un groupe a deja ce nom, on renvoie une erreur if( !$check_unique ) @@ -32,13 +33,16 @@ /* [2] Creation du groupe =========================================================*/ - $insert_user = Database::getPDO()->prepare("INSERT INTO cluster(id_cluster, name) - VALUES(DEFAULT, :name)"); - $insert_user->execute([ ':name' => $name ]); + $insert_user = Database::getPDO()->prepare("INSERT INTO cluster(id_cluster, id_warehouse, name) + VALUES(DEFAULT, :id_warehouse, :name)"); + $insert_user->execute([ + ':id_warehouse' => $id_warehouse, + ':name' => $name + ]); /* [3] On retourne l'id_group ou FALSE si erreur =========================================================*/ - $check_group = self::getByName($name); + $check_group = self::getByName($id_warehouse, $name); // Si n'existe pas on retourne FALSE if( $check_group === false ) @@ -57,6 +61,7 @@ /* ASSOCIATION D'UN(E) UTILISATEUR/MACHINE A UN GROUPE * + * @id_warehouse UID de l'entrepot * @id_cluster UID du groupe * @id_entity UID de la machine ou de l'utilisateur * @class Spefication du type d'entite (0=user;1=machine) @@ -65,10 +70,10 @@ * Renvoie FALSE si une erreur occure * */ - public static function link($id_cluster, $id_entity, $class){ + public static function link($id_warehouse, $id_cluster, $id_entity, $class){ /* [1] Verification de l'existence du groupe =========================================================*/ - $group_check = self::getById($id_cluster); + $group_check = self::getById($id_warehouse, $id_cluster); // Si le groupe n'existe pas, on retourne ue erreur if( $group_check === false ) @@ -82,13 +87,13 @@ /* (1) Utilisateur */ if( $class == self::USER_CLASS ){ // On verifie si c'est un utilisateur - $user_check = userRepo::getById($id_entity); + $user_check = userRepo::getById($id_warehouse, $id_entity); $entity_exists = ( $user_check !== FALSE ); /* (2) Machine */ }elseif( $class == self::MACHINE_CLASS ){ // On verifie si c'est une machine - $machine_check = machineRepo::getById($id_entity); + $machine_check = machineRepo::getById($id_warehouse, $id_entity); $entity_exists = ( $machine_check !== FALSE ); } @@ -138,6 +143,7 @@ /* SUPPRIME UNE ASSOCIATION D'UN(E) UTILISATEUR/MACHINE A UN GROUPE * + * @id_warehouse UID de l'entrepot * @id_cluster UID du groupe * @id_entity UID de la machine ou de l'utilisateur * @class Spefication du type d'entite (0=user;1=machine) @@ -145,17 +151,20 @@ * @return status Retourne si oui ou non l'association a bien ete supprimee * */ - public static function unlink($id_cluster, $id_entity, $class){ + public static function unlink($id_warehouse, $id_cluster, $id_entity, $class){ /* [1] On redige/execute la requete =========================================================*/ - $delete_cluster_merge = Database::getPDO()->prepare("DELETE FROM cluster_merge - WHERE id_cluster = :id_cluster - AND id_entity = :id_entity - AND class = :class"); + $delete_cluster_merge = Database::getPDO()->prepare("DELETE FROM cluster_merge as cm, cluster as c + WHERE cm.id_cluster = c.id_cluster + AND c.id_warehouse = :id_warehouse + AND cm.id_cluster = :id_cluster + AND cm.id_entity = :id_entity + AND cm.class = :class"); $delete_cluster_merge->execute([ - ':id_cluster' => $id_cluster, - ':id_entity' => $id_entity, - ':class' => $class + ':id_warehouse' => $id_warehouse, + ':id_cluster' => $id_cluster, + ':id_entity' => $id_entity, + ':class' => $class ]); @@ -267,16 +276,22 @@ /* SUPPRIME UN GROUPE DONNE * + * @id_warehouse UID de l'entrepot * @id_cluster UID du groupe en question * * @return status Retourne si oui ou non le groupe a bien ete supprime * */ - public static function delete($id_cluster){ + public static function delete($id_warehouse, $id_cluster){ /* [1] On redige/execute la requete =========================================================*/ - $delete_group = Database::getPDO()->prepare("DELETE FROM cluster WHERE id_cluster = :id_cluster"); - $delete_group->execute([ ':id_cluster' => $id_cluster ]); + $delete_group = Database::getPDO()->prepare("DELETE FROM cluster + WHERE id_warehouse = :id_warehouse + AND id_cluster = :id_cluster"); + $delete_group->execute([ + ':id_warehouse' => $id_warehouse, + ':id_cluster' => $id_cluster + ]); /* [2] On verifie que le groupe n'existe plus