2016-02-14 11:37:19 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace manager\repo;
|
|
|
|
|
use \manager\Database;
|
2016-07-08 17:33:58 +00:00
|
|
|
|
use \manager\ManagerError;
|
2016-02-14 11:37:19 +00:00
|
|
|
|
use \manager\repo\machine as machineRepo;
|
|
|
|
|
use \manager\repo\user as userRepo;
|
|
|
|
|
|
2016-07-04 10:13:35 +00:00
|
|
|
|
class cluster extends parentRepo{
|
|
|
|
|
|
|
|
|
|
protected static function table_name(){ static $table_name = 'cluster'; return $table_name; }
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
2016-02-14 14:17:26 +00:00
|
|
|
|
const USER_CLASS = 0;
|
|
|
|
|
const MACHINE_CLASS = 1;
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
/* CREATION D'UN GROUPE
|
|
|
|
|
*
|
2016-07-06 10:24:04 +00:00
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-14 11:37:19 +00:00
|
|
|
|
* @name<String> Nom du groupe
|
2016-07-10 10:06:41 +00:00
|
|
|
|
* @class<int> Type d'entités du groupe
|
|
|
|
|
* @owner<int> Si défini -> UID de l'entité qui a ce groupe comme groupe PERSONNEL
|
2016-02-14 11:37:19 +00:00
|
|
|
|
*
|
|
|
|
|
* @return id_user<int> Renvoie l'UID du groupe cree
|
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
|
*
|
|
|
|
|
*/
|
2016-07-10 10:06:41 +00:00
|
|
|
|
public static function create($id_warehouse, $name, $class, $owner=null){
|
2016-02-14 11:37:19 +00:00
|
|
|
|
/* [1] Verification de l'unicite de name
|
|
|
|
|
=========================================================*/
|
2016-07-06 10:24:04 +00:00
|
|
|
|
$check_unique = ( self::getByName($id_warehouse, $name) === false );
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
// Si un groupe a deja ce nom, on renvoie une erreur
|
|
|
|
|
if( !$check_unique )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Creation du groupe
|
|
|
|
|
=========================================================*/
|
2016-07-10 10:06:41 +00:00
|
|
|
|
$insert_user = Database::getPDO()->prepare("INSERT INTO cluster(id_cluster, id_warehouse, name, class, personal)
|
|
|
|
|
VALUES(DEFAULT, :id_warehouse, :name, :class, :personal)");
|
2016-07-06 10:24:04 +00:00
|
|
|
|
$insert_user->execute([
|
|
|
|
|
':id_warehouse' => $id_warehouse,
|
2016-07-08 15:47:03 +00:00
|
|
|
|
':name' => $name,
|
2016-07-10 10:06:41 +00:00
|
|
|
|
':class' => $class,
|
|
|
|
|
':personal' => $owner
|
2016-07-06 10:24:04 +00:00
|
|
|
|
]);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
/* [3] On retourne l'id_group ou FALSE si erreur
|
|
|
|
|
=========================================================*/
|
2016-07-06 10:24:04 +00:00
|
|
|
|
$check_group = self::getByName($id_warehouse, $name);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
// Si n'existe pas on retourne FALSE
|
|
|
|
|
if( $check_group === false )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Sinon, on retourne son id
|
|
|
|
|
return $check_group['id_cluster'];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-14 12:28:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
/* ASSOCIATION D'UN(E) UTILISATEUR/MACHINE A UN GROUPE
|
|
|
|
|
*
|
2016-07-06 10:24:04 +00:00
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-14 11:37:19 +00:00
|
|
|
|
* @id_cluster<int> UID du groupe
|
|
|
|
|
* @id_entity<int> UID de la machine ou de l'utilisateur
|
2016-02-14 14:17:26 +00:00
|
|
|
|
* @class<int> Spefication du type d'entite (0=user;1=machine)
|
2016-02-14 11:37:19 +00:00
|
|
|
|
*
|
2016-07-09 13:06:59 +00:00
|
|
|
|
* @return error<int> Renvoie le code 'ManagerError'
|
2016-02-14 11:37:19 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
2016-07-06 10:24:04 +00:00
|
|
|
|
public static function link($id_warehouse, $id_cluster, $id_entity, $class){
|
2016-02-14 11:37:19 +00:00
|
|
|
|
/* [1] Verification de l'existence du groupe
|
|
|
|
|
=========================================================*/
|
2016-07-06 10:24:04 +00:00
|
|
|
|
$group_check = self::getById($id_warehouse, $id_cluster);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
// Si le groupe n'existe pas, on retourne ue erreur
|
|
|
|
|
if( $group_check === false )
|
2016-07-08 17:33:58 +00:00
|
|
|
|
return ManagerError::NoMatchFound;
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Verification de l'existente de l'entite
|
|
|
|
|
=========================================================*/
|
2016-02-14 14:17:26 +00:00
|
|
|
|
$entity_exists = false;
|
|
|
|
|
/* (1) Utilisateur */
|
2016-07-02 16:35:34 +00:00
|
|
|
|
if( $class == self::USER_CLASS ){
|
2016-02-14 14:17:26 +00:00
|
|
|
|
// On verifie si c'est un utilisateur
|
2016-07-06 10:24:04 +00:00
|
|
|
|
$user_check = userRepo::getById($id_warehouse, $id_entity);
|
2016-07-03 12:20:42 +00:00
|
|
|
|
$entity_exists = ( $user_check !== FALSE );
|
2016-02-14 14:17:26 +00:00
|
|
|
|
|
2016-07-02 16:35:34 +00:00
|
|
|
|
/* (2) Machine */
|
|
|
|
|
}elseif( $class == self::MACHINE_CLASS ){
|
2016-02-14 14:17:26 +00:00
|
|
|
|
// On verifie si c'est une machine
|
2016-07-06 10:24:04 +00:00
|
|
|
|
$machine_check = machineRepo::getById($id_warehouse, $id_entity);
|
2016-02-14 14:17:26 +00:00
|
|
|
|
$entity_exists = ( $machine_check !== FALSE );
|
|
|
|
|
}
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
// Si aucune entite existante, on retourne une erreur
|
2016-02-14 14:17:26 +00:00
|
|
|
|
if( !$entity_exists )
|
2016-07-08 17:33:58 +00:00
|
|
|
|
return ManagerError::NoMatchFound;
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
|
2016-02-14 12:28:35 +00:00
|
|
|
|
/* [3] Verification que l'existente n'existe pas deja
|
|
|
|
|
=========================================================*/
|
2016-07-08 17:33:58 +00:00
|
|
|
|
$already_cluster_merge = self::getMerge($id_warehouse, $id_cluster, $id_entity, $class);
|
2016-02-14 12:28:35 +00:00
|
|
|
|
|
|
|
|
|
// Si l'association existe deja, on ne la cree donc pas
|
|
|
|
|
if( $already_cluster_merge !== false )
|
2016-07-08 17:33:58 +00:00
|
|
|
|
return ManagerError::Success;
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
2016-02-14 12:28:35 +00:00
|
|
|
|
|
|
|
|
|
/* [4] On cree l'association
|
2016-02-14 11:37:19 +00:00
|
|
|
|
=========================================================*/
|
2016-07-08 15:47:03 +00:00
|
|
|
|
$link_entity = Database::getPDO()->prepare("INSERT INTO cluster_merge(id_cluster_merge, id_cluster, id_entity)
|
|
|
|
|
VALUES(DEFAULT, :id_cluster, :id_entity)");
|
2016-07-04 13:45:29 +00:00
|
|
|
|
$link_entity->execute([
|
2016-02-14 11:37:19 +00:00
|
|
|
|
':id_cluster' => $id_cluster,
|
2016-07-08 15:47:03 +00:00
|
|
|
|
':id_entity' => $id_entity
|
2016-07-04 13:45:29 +00:00
|
|
|
|
]);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
2016-02-14 12:28:35 +00:00
|
|
|
|
/* [5] On retourne l'id_cluster_merge ou FALSE si erreur
|
2016-02-14 11:37:19 +00:00
|
|
|
|
=========================================================*/
|
2016-07-08 17:33:58 +00:00
|
|
|
|
$check_cluster_merge = self::getMerge($id_warehouse, $id_cluster, $id_entity, $class);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
// Si n'existe pas on retourne FALSE
|
2016-07-03 12:20:42 +00:00
|
|
|
|
if( !is_array($check_cluster_merge) )
|
2016-07-09 13:06:59 +00:00
|
|
|
|
return ManagerError::RepoError;
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
// Sinon, on retourne son id
|
2016-07-08 17:33:58 +00:00
|
|
|
|
return ManagerError::Success;
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 12:28:35 +00:00
|
|
|
|
/* SUPPRIME UNE ASSOCIATION D'UN(E) UTILISATEUR/MACHINE A UN GROUPE
|
|
|
|
|
*
|
2016-07-06 10:24:04 +00:00
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-14 12:28:35 +00:00
|
|
|
|
* @id_cluster<int> UID du groupe
|
|
|
|
|
* @id_entity<int> UID de la machine ou de l'utilisateur
|
2016-02-14 14:17:26 +00:00
|
|
|
|
* @class<int> Spefication du type d'entite (0=user;1=machine)
|
2016-02-14 12:28:35 +00:00
|
|
|
|
*
|
2016-07-09 13:06:59 +00:00
|
|
|
|
* @return error<int> Renvoie le code 'ManagerError'
|
2016-02-14 12:28:35 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
2016-07-06 10:24:04 +00:00
|
|
|
|
public static function unlink($id_warehouse, $id_cluster, $id_entity, $class){
|
2016-07-08 17:33:58 +00:00
|
|
|
|
/* [1] On récupère l'UID du lien
|
2016-02-14 12:28:35 +00:00
|
|
|
|
=========================================================*/
|
2016-07-08 17:33:58 +00:00
|
|
|
|
/* (1) On récupère le lien */
|
|
|
|
|
$get_merge_id = self::getMerge($id_warehouse, $id_cluster, $id_entity, $class);
|
|
|
|
|
|
|
|
|
|
/* (2) Si on ne trouve rien */
|
|
|
|
|
if( $get_merge_id == false )
|
|
|
|
|
return ManagerError::NoMatchFound;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On supprime le lien
|
|
|
|
|
=========================================================*/
|
|
|
|
|
$delete_cluster_merge = Database::getPDO()->prepare("DELETE FROM cluster_merge
|
|
|
|
|
WHERE id_cluster_merge = :uid");
|
2016-07-04 13:45:29 +00:00
|
|
|
|
$delete_cluster_merge->execute([
|
2016-07-08 17:33:58 +00:00
|
|
|
|
':uid' => $get_merge_id['id_cluster_merge']
|
2016-07-04 13:45:29 +00:00
|
|
|
|
]);
|
2016-02-14 12:28:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On verifie que l'association n'existe plus
|
|
|
|
|
=========================================================*/
|
2016-07-08 17:33:58 +00:00
|
|
|
|
if( self::getMerge($id_warehouse, $id_cluster, $id_entity, $class) !== false )
|
|
|
|
|
return ManagerError::ModuleError;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ManagerError::Success;
|
2016-02-14 12:28:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
/* RENVOIE L'ID D'UNE ASSOCIATION D'UN(E) UTILISATEUR/MACHINE A UN GROUPE
|
|
|
|
|
*
|
2016-07-08 17:33:58 +00:00
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-14 11:37:19 +00:00
|
|
|
|
* @id_cluster<int> UID du groupe
|
|
|
|
|
* @id_entity<int> UID de la machine ou de l'utilisateur
|
2016-02-14 14:17:26 +00:00
|
|
|
|
* @class<int> Spefication du type d'entite (0=user;1=machine)
|
2016-02-14 11:37:19 +00:00
|
|
|
|
*
|
|
|
|
|
* @return association<int> Renvoie l'UID de l'association cree
|
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
|
*
|
|
|
|
|
*/
|
2016-07-08 17:33:58 +00:00
|
|
|
|
public static function getMerge($id_warehouse, $id_cluster, $id_entity, $class){
|
2016-02-14 11:37:19 +00:00
|
|
|
|
// On ecrit la requete
|
2016-07-08 15:47:03 +00:00
|
|
|
|
$request = Database::getPDO()->prepare("SELECT cm.*
|
|
|
|
|
FROM cluster_merge as cm, cluster as c
|
2016-07-08 17:33:58 +00:00
|
|
|
|
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 c.class = :class");
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
// On execute la requete
|
2016-07-04 13:45:29 +00:00
|
|
|
|
$request->execute([
|
2016-07-08 17:33:58 +00:00
|
|
|
|
':id_warehouse' => $id_warehouse,
|
|
|
|
|
':id_cluster' => $id_cluster,
|
|
|
|
|
':id_entity' => $id_entity,
|
|
|
|
|
':class' => $class
|
2016-07-04 13:45:29 +00:00
|
|
|
|
]);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
// On recupere 1 seule relation
|
2016-02-14 14:17:26 +00:00
|
|
|
|
$answer = $request->fetch();
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
// Gestion d'erreur -> aucun resultat
|
|
|
|
|
if( $answer === false )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// On retourne en supprimant les indices numeriques
|
|
|
|
|
return Database::delNumeric( $answer, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-08 18:28:44 +00:00
|
|
|
|
/* RENVOIE LA LISTE DES GROUPES D'UN ENTREPOT
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
*
|
2016-07-09 10:44:06 +00:00
|
|
|
|
* @return clusters<Array> Renvoie la liste des groupes
|
2016-07-08 18:28:44 +00:00
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function getAll($id_warehouse){
|
|
|
|
|
// On ecrit la requete
|
2016-07-10 13:23:53 +00:00
|
|
|
|
$request = Database::getPDO()->prepare("SELECT c.id_cluster, c.name, c.class
|
2016-07-09 13:06:59 +00:00
|
|
|
|
FROM cluster as c
|
|
|
|
|
WHERE c.id_warehouse = :id_warehouse
|
2016-07-10 10:06:41 +00:00
|
|
|
|
AND c.personal is null
|
2016-07-08 18:28:44 +00:00
|
|
|
|
ORDER BY c.name ASC");
|
|
|
|
|
|
|
|
|
|
// On execute la requete
|
|
|
|
|
$request->execute([
|
|
|
|
|
':id_warehouse' => $id_warehouse
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// On retourne en supprimant les indices numeriques
|
|
|
|
|
return Database::delNumeric( $request->fetchAll() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-09 10:44:06 +00:00
|
|
|
|
/* RENVOIE LA LISTE D'UN GROUPE SPECIFIQUE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @id<int> UID du groupe
|
|
|
|
|
*
|
|
|
|
|
* @return cluster<Array> Renvoie le groupe correspondant
|
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function getById($id_warehouse, $id){
|
|
|
|
|
// On ecrit la requete
|
|
|
|
|
$request = Database::getPDO()->prepare("SELECT c.*
|
2016-07-09 13:06:59 +00:00
|
|
|
|
FROM cluster as c
|
|
|
|
|
WHERE c.id_warehouse = :id_warehouse
|
|
|
|
|
AND c.id_cluster = :id");
|
2016-07-09 10:44:06 +00:00
|
|
|
|
|
|
|
|
|
// On execute la requete
|
|
|
|
|
$request->execute([
|
|
|
|
|
':id_warehouse' => $id_warehouse,
|
|
|
|
|
':id' => $id
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$fetch = $request->fetch();
|
|
|
|
|
|
|
|
|
|
// Si aucun résultat
|
|
|
|
|
if( $fetch == false )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// On retourne en supprimant les indices numeriques
|
|
|
|
|
return Database::delNumeric( $fetch, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LA LISTE D'UN GROUPE SPECIFIQUE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @name<String> Nom du groupe
|
|
|
|
|
*
|
|
|
|
|
* @return cluster<Array> Renvoie le groupe correspondant
|
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function getByName($id_warehouse, $name){
|
|
|
|
|
// On ecrit la requete
|
|
|
|
|
$request = Database::getPDO()->prepare("SELECT c.*
|
2016-07-09 13:06:59 +00:00
|
|
|
|
FROM cluster as c
|
|
|
|
|
WHERE c.id_warehouse = :id_warehouse
|
|
|
|
|
AND c.name = :name");
|
2016-07-09 10:44:06 +00:00
|
|
|
|
|
|
|
|
|
// On execute la requete
|
|
|
|
|
$request->execute([
|
|
|
|
|
':id_warehouse' => $id_warehouse,
|
|
|
|
|
':name' => $name
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$fetch = $request->fetch();
|
|
|
|
|
|
|
|
|
|
// Si aucun résultat
|
|
|
|
|
if( $fetch == false )
|
|
|
|
|
return false;
|
2016-07-12 13:16:07 +00:00
|
|
|
|
|
|
|
|
|
// On retourne en supprimant les indices numeriques
|
|
|
|
|
return Database::delNumeric( $fetch, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LE GROUPE PERSONNEL D'UNE ENTITE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @id_entity<int> UID de l'entité (user/machine)
|
|
|
|
|
* @class<int> Classe du groupe (0:user ; 1:machine)
|
|
|
|
|
*
|
|
|
|
|
* @return cluster<Array> Renvoie le groupe correspondant
|
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function getPersonal($id_warehouse, $id_entity, $class){
|
|
|
|
|
// On ecrit la requete
|
|
|
|
|
$request = Database::getPDO()->prepare("SELECT c.*
|
|
|
|
|
FROM cluster as c
|
|
|
|
|
WHERE c.id_warehouse = :id_warehouse
|
|
|
|
|
AND c.personal is not null
|
|
|
|
|
AND c.id_entity = :id_entity
|
|
|
|
|
AND c.class = :class");
|
|
|
|
|
|
|
|
|
|
// On execute la requete
|
|
|
|
|
$request->execute([
|
|
|
|
|
':id_warehouse' => $id_warehouse,
|
|
|
|
|
':id_entity' => $id_entity,
|
|
|
|
|
':class' => $class
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$fetch = $request->fetch();
|
|
|
|
|
|
|
|
|
|
// Si aucun résultat
|
|
|
|
|
if( $fetch == false )
|
|
|
|
|
return false;
|
2016-07-09 10:44:06 +00:00
|
|
|
|
|
|
|
|
|
// On retourne en supprimant les indices numeriques
|
|
|
|
|
return Database::delNumeric( $fetch, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
2016-02-14 14:53:59 +00:00
|
|
|
|
/* RENVOIE LES MEMBRES D'UN GROUPE DONNE
|
|
|
|
|
*
|
2016-07-09 10:44:06 +00:00
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-14 14:53:59 +00:00
|
|
|
|
* @id_cluster<int> UID du groupe en question
|
|
|
|
|
*
|
|
|
|
|
* @return members<Array> Retourne la liste des membres du groupe
|
|
|
|
|
*
|
|
|
|
|
*/
|
2016-07-09 10:44:06 +00:00
|
|
|
|
public static function getMembers($id_warehouse, $id_cluster){
|
2016-02-14 14:53:59 +00:00
|
|
|
|
/* [1] On recupere la liste des associations
|
|
|
|
|
=========================================================*/
|
2016-07-09 10:44:06 +00:00
|
|
|
|
$get_members = Database::getPDO()->prepare("SELECT id_entity as id_member, c.class
|
|
|
|
|
FROM cluster_merge as cm, cluster as c
|
|
|
|
|
WHERE cm.id_cluster = c.id_cluster
|
|
|
|
|
AND c.id_cluster = :id_cluster
|
|
|
|
|
AND c.id_warehouse = :id_warehouse
|
2016-07-10 10:06:41 +00:00
|
|
|
|
AND c.personal is null
|
2016-02-14 14:53:59 +00:00
|
|
|
|
ORDER BY id_cluster_merge");
|
2016-07-09 10:44:06 +00:00
|
|
|
|
$get_members->execute([
|
|
|
|
|
':id_warehouse' => $id_warehouse,
|
|
|
|
|
':id_cluster' => $id_cluster
|
|
|
|
|
]);
|
2016-02-14 14:53:59 +00:00
|
|
|
|
|
|
|
|
|
$members = Database::delNumeric( $get_members->fetchAll() );
|
|
|
|
|
|
|
|
|
|
/* [2] On formatte recupere les entites
|
|
|
|
|
=========================================================*/
|
|
|
|
|
foreach($members as $i=>$member){
|
|
|
|
|
|
|
|
|
|
/* (1) On recupere les informations utilisateur */
|
|
|
|
|
if( $member['class'] == self::USER_CLASS ){
|
2016-07-09 10:44:06 +00:00
|
|
|
|
$get_user = userRepo::getById( $id_warehouse, $member['id_member'] );
|
2016-02-14 14:53:59 +00:00
|
|
|
|
|
|
|
|
|
// Si on a bien recu les informations, on les ajoute
|
2016-07-09 10:44:06 +00:00
|
|
|
|
if( $get_user !== false ){
|
|
|
|
|
$members[$i] = [
|
|
|
|
|
'id_member' => $get_user['id_user'],
|
|
|
|
|
'name' => $get_user['username'],
|
|
|
|
|
'class' => self::USER_CLASS
|
|
|
|
|
];
|
|
|
|
|
}
|
2016-02-14 14:53:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On recupere les informations machine */
|
|
|
|
|
}elseif( $member['class'] == self::MACHINE_CLASS ){
|
2016-07-09 10:44:06 +00:00
|
|
|
|
$get_machine = machineRepo::getById( $id_warehouse, $member['id_member'] );
|
2016-02-14 14:53:59 +00:00
|
|
|
|
|
|
|
|
|
// Si on a bien recu les informations, on les ajoute
|
2016-07-09 10:44:06 +00:00
|
|
|
|
if( $get_machine !== false ){
|
|
|
|
|
$members[$i] = [
|
|
|
|
|
'id_member' => $get_machine['id_machine'],
|
|
|
|
|
'name' => $get_machine['name'],
|
|
|
|
|
'class' => self::MACHINE_CLASS
|
|
|
|
|
];
|
|
|
|
|
}
|
2016-02-14 14:53:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* [2] On verifie que le groupe n'existe plus
|
|
|
|
|
=========================================================*/
|
|
|
|
|
return $members;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
/* RENVOIE UNE LISTE DE GROUPES EN FONCTION D'UN MOT CLE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @keyword<String> Element de recherche
|
|
|
|
|
*
|
|
|
|
|
* @return clusters<Array> Retourne les groupes trouves
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function search($id_warehouse, $keyword){
|
|
|
|
|
// On recupere les donnees
|
|
|
|
|
$searchclusters = Database::getPDO()->prepare("SELECT * FROM cluster
|
|
|
|
|
WHERE id_warehouse = :id_warehouse
|
|
|
|
|
AND name LIKE '%".$keyword."%'
|
|
|
|
|
AND personal is null");
|
|
|
|
|
|
|
|
|
|
$searchclusters->execute([
|
|
|
|
|
':id_warehouse' => $id_warehouse
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return Database::delNumeric( $searchclusters->fetchAll() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 14:53:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
/* SUPPRIME UN GROUPE DONNE
|
|
|
|
|
*
|
2016-07-06 10:24:04 +00:00
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-14 11:37:19 +00:00
|
|
|
|
* @id_cluster<int> UID du groupe en question
|
|
|
|
|
*
|
|
|
|
|
* @return status<Boolean> Retourne si oui ou non le groupe a bien ete supprime
|
|
|
|
|
*
|
|
|
|
|
*/
|
2016-07-06 10:24:04 +00:00
|
|
|
|
public static function delete($id_warehouse, $id_cluster){
|
2016-02-14 11:37:19 +00:00
|
|
|
|
/* [1] On redige/execute la requete
|
|
|
|
|
=========================================================*/
|
2016-07-06 10:24:04 +00:00
|
|
|
|
$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
|
|
|
|
|
]);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On verifie que le groupe n'existe plus
|
|
|
|
|
=========================================================*/
|
|
|
|
|
return ( self::getById($id_group) === false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-02 16:35:34 +00:00
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-07-02 16:35:34 +00:00
|
|
|
|
?>
|