Gestion des groupes 'personnels'

This commit is contained in:
xdrm-brackets 2016-07-10 12:06:41 +02:00
parent 4d5b8700bf
commit 9434e6cced
3 changed files with 35 additions and 28 deletions

View File

@ -39,7 +39,8 @@
$create_group = new Repo('cluster/create', [
$_SESSION['WAREHOUSE']['id'],
$name,
clusterRepo::MACHINE_CLASS
clusterRepo::MACHINE_CLASS,
$id_machine
]);
$id_group = $create_group->answer();
@ -49,17 +50,17 @@
/* [3] Association au groupe
=========================================================*/
$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
if( $id_assoc === false )
return ['ModuleError' => ManagerError::ModuleError];
// $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
// if( $id_assoc === false )
// return ['ModuleError' => ManagerError::ModuleError];
/* [4] Gestion du retour

View File

@ -55,7 +55,8 @@
$create_cluster = new Repo('cluster/create', [
$_SESSION['WAREHOUSE']['id'],
$username,
clusterRepo::USER_CLASS
clusterRepo::USER_CLASS,
$id_user
]);
$id_cluster = $create_cluster->answer();
@ -68,17 +69,17 @@
/* [4] Association au groupe
=========================================================*/
$assoc_goup = new Repo('cluster/link', [
$_SESSION['WAREHOUSE']['id'],
$id_cluster,
$id_user,
clusterRepo::USER_CLASS
]);
$assoc_err = $assoc_goup->answer();
// Si une erreur est retournee, on retourne une erreur
if( $assoc_err != ManagerError::Success )
return ['ModuleError' => $assoc_err];
// $assoc_goup = new Repo('cluster/link', [
// $_SESSION['WAREHOUSE']['id'],
// $id_cluster,
// $id_user,
// clusterRepo::USER_CLASS
// ]);
// $assoc_err = $assoc_goup->answer();
//
// // Si une erreur est retournee, on retourne une erreur
// if( $assoc_err != ManagerError::Success )
// return ['ModuleError' => $assoc_err];

View File

@ -17,12 +17,14 @@
*
* @id_warehouse<int> UID de l'entrepot
* @name<String> Nom du groupe
* @class<int> Type d'entités du groupe
* @owner<int> Si défini -> UID de l'entité qui a ce groupe comme groupe PERSONNEL
*
* @return id_user<int> Renvoie l'UID du groupe cree
* Renvoie FALSE si une erreur occure
*
*/
public static function create($id_warehouse, $name, $class){
public static function create($id_warehouse, $name, $class, $owner=null){
/* [1] Verification de l'unicite de name
=========================================================*/
$check_unique = ( self::getByName($id_warehouse, $name) === false );
@ -34,12 +36,13 @@
/* [2] Creation du groupe
=========================================================*/
$insert_user = Database::getPDO()->prepare("INSERT INTO cluster(id_cluster, id_warehouse, name, class)
VALUES(DEFAULT, :id_warehouse, :name, :class)");
$insert_user = Database::getPDO()->prepare("INSERT INTO cluster(id_cluster, id_warehouse, name, class, personal)
VALUES(DEFAULT, :id_warehouse, :name, :class, :personal)");
$insert_user->execute([
':id_warehouse' => $id_warehouse,
':name' => $name,
':class' => $class
':class' => $class,
':personal' => $owner
]);
/* [3] On retourne l'id_group ou FALSE si erreur
@ -247,6 +250,7 @@
$request = Database::getPDO()->prepare("SELECT *
FROM cluster as c
WHERE c.id_warehouse = :id_warehouse
AND c.personal is null
ORDER BY c.name ASC");
// On execute la requete
@ -357,6 +361,7 @@
WHERE cm.id_cluster = c.id_cluster
AND c.id_cluster = :id_cluster
AND c.id_warehouse = :id_warehouse
AND c.personal is null
ORDER BY id_cluster_merge");
$get_members->execute([
':id_warehouse' => $id_warehouse,