2016-07-18 10:35:30 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace manager\repo;
|
|
|
|
|
use \manager\Database;
|
|
|
|
|
use \manager\ManagerError;
|
|
|
|
|
use \manager\Repo;
|
2016-07-23 15:34:24 +00:00
|
|
|
|
use \manager\ORM\Table;
|
|
|
|
|
use \manager\ORM\Rows;
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
|
|
|
|
class machine_cluster extends parentRepo{
|
|
|
|
|
|
|
|
|
|
protected static function table_name(){ static $table_name = 'machine_cluster'; return $table_name; }
|
|
|
|
|
|
|
|
|
|
/* CREATION D'UN GROUPE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @name<String> Nom du groupe
|
|
|
|
|
*
|
|
|
|
|
* @return id_cluster<int> Renvoie l'UID du groupe cree
|
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function create($id_warehouse, $name){
|
|
|
|
|
/* [1] Verification de l'unicite de name
|
|
|
|
|
=========================================================*/
|
2016-07-23 15:40:54 +00:00
|
|
|
|
$inserted = Table::get('machine_cluster')
|
|
|
|
|
->insert([
|
|
|
|
|
'id_machine_cluster' => Rows::DEFAULT,
|
|
|
|
|
'id_warehouse' => $id_warehouse,
|
|
|
|
|
'name' => $name
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Si erreur (car name doit être unique)
|
|
|
|
|
if( !$inserted )
|
2016-07-18 10:35:30 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [2] On retourne l'id_group ou FALSE si erreur
|
2016-07-18 10:35:30 +00:00
|
|
|
|
=========================================================*/
|
|
|
|
|
$check_group = self::getByName($id_warehouse, $name);
|
|
|
|
|
|
|
|
|
|
// Si n'existe pas on retourne FALSE
|
|
|
|
|
if( $check_group === false )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Sinon, on retourne son id
|
|
|
|
|
return $check_group['id_machine_cluster'];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ASSOCIATION D'UNE MACHINE A UN GROUPE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @id_machine_cluster<int> UID du groupe
|
|
|
|
|
* @id_machine<int> UID de la machine
|
|
|
|
|
*
|
|
|
|
|
* @return error<int> Renvoie le code 'ManagerError'
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function link($id_warehouse, $id_machine_cluster, $id_machine){
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [1] On vérifie que tout existe
|
2016-07-18 10:35:30 +00:00
|
|
|
|
=========================================================*/
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* (1) On récupère le groupe */
|
|
|
|
|
$clusterR = Table::get('machine_cluster')
|
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
|
->whereId($id_machine_cluster)
|
|
|
|
|
->unique()
|
|
|
|
|
->select('id_machine_cluster');
|
|
|
|
|
$cluster = $clusterR->fetch();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
// Si le groupe n'existe pas
|
|
|
|
|
if( $cluster === false )
|
2016-07-18 10:35:30 +00:00
|
|
|
|
return ManagerError::NoMatchFound;
|
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* (2) On récupère l'utilisateur */
|
|
|
|
|
$machineR = Table::get('machine')
|
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
|
->whereId($id_machine)
|
|
|
|
|
->unique()
|
|
|
|
|
->select('id_machine');
|
|
|
|
|
$machine = $machineR->fetch();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
// Si l'utilisateur n'existe pas
|
|
|
|
|
if( $machine === false )
|
2016-07-18 10:35:30 +00:00
|
|
|
|
return ManagerError::NoMatchFound;
|
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* (3) On vérifie qu'il n'y a pas déja d'appartenance */
|
|
|
|
|
$cluster_mergeR = Table::get('machine_cluster_merge')
|
|
|
|
|
->select('id_machine_cluster_merge')
|
|
|
|
|
->join('id_machine_cluster', $clusterR)
|
|
|
|
|
->join('id_machine', $machineR)
|
|
|
|
|
->unique();
|
|
|
|
|
$cluster_merge_exists = $cluster_mergeR->fetch();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
// Si la relation existe déja, on ne fait rien
|
|
|
|
|
if( $cluster_merge_exists !== false )
|
2016-07-18 10:35:30 +00:00
|
|
|
|
return ManagerError::Success;
|
|
|
|
|
|
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
|
|
|
|
|
/* [2] On crée la relation
|
2016-07-18 10:35:30 +00:00
|
|
|
|
=========================================================*/
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* (1) On insère la relation */
|
|
|
|
|
$inserted = Table::get('machine_cluster_merge')
|
|
|
|
|
->insert([
|
|
|
|
|
'id_machine_cluster_merge' => Rows::DEFAULT,
|
|
|
|
|
'id_machine_cluster' => $id_machine_cluster,
|
|
|
|
|
'id_machine' => $id_machine
|
|
|
|
|
]);
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
|
|
|
|
|
/* (2) Si erreur, on la retourne */
|
|
|
|
|
if( !$inserted )
|
2016-07-18 10:35:30 +00:00
|
|
|
|
return ManagerError::RepoError;
|
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* (3) On vérifie quand même que l'entrée existe */
|
|
|
|
|
$cluster_merge_inserted = $cluster_mergeR->fetch();
|
|
|
|
|
|
|
|
|
|
/* (4) Sinon, on renvoie que tout s'est bien passé */
|
|
|
|
|
return is_array($cluster_merge_inserted) ? ManagerError::Success : ManagerError::RepoError;
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* SUPPRIME UNE ASSOCIATION D'UNE MACHINE A UN GROUPE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @id_machine_cluster<int> UID du groupe
|
|
|
|
|
* @id_machine<int> UID de la machine
|
|
|
|
|
*
|
|
|
|
|
* @return error<int> Renvoie le code 'ManagerError'
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function unlink($id_warehouse, $id_machine_cluster, $id_machine){
|
|
|
|
|
/* [1] On récupère l'UID du lien
|
|
|
|
|
=========================================================*/
|
|
|
|
|
/* (1) On récupère le lien */
|
|
|
|
|
$get_merge_id = self::getMerge($id_warehouse, $id_machine_cluster, $id_machine);
|
|
|
|
|
|
|
|
|
|
/* (2) Si on ne trouve rien */
|
2016-07-24 13:35:00 +00:00
|
|
|
|
if( $get_merge_id === false )
|
2016-07-18 10:35:30 +00:00
|
|
|
|
return ManagerError::NoMatchFound;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On supprime le lien
|
|
|
|
|
=========================================================*/
|
2016-07-23 15:40:54 +00:00
|
|
|
|
$deleted = Table::get('machine_cluster_merge')
|
|
|
|
|
->whereId($get_merge_id['id_machine_cluster_merge'])
|
|
|
|
|
->delete();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
// Si erreur
|
|
|
|
|
if( !$deleted )
|
|
|
|
|
return ManagerError::RepoError;
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
|
|
|
|
/* [2] On verifie que l'association n'existe plus
|
|
|
|
|
=========================================================*/
|
|
|
|
|
if( self::getMerge($id_warehouse, $id_machine_cluster, $id_machine) !== false )
|
2016-07-24 13:35:00 +00:00
|
|
|
|
return ManagerError::RepoError;
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ManagerError::Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE L'ID D'UNE ASSOCIATION D'UNE MACHINE A UN GROUPE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @id_machine_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 getMerge($id_warehouse, $id_machine_cluster, $id_machine){
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [1] On rédige/exécute la requête
|
|
|
|
|
=========================================================*/
|
|
|
|
|
$cluster_merge = Table::get('machine_cluster_merge')
|
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
2016-07-24 13:35:00 +00:00
|
|
|
|
->whereIdMachineCluster($id_machine_cluster)
|
|
|
|
|
->whereIdMachine($id_machine)
|
2016-07-23 15:40:54 +00:00
|
|
|
|
->select('*')
|
|
|
|
|
->unique()
|
|
|
|
|
->fetch();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [2] On retourne le résultat (FALSE si rien trouvé)
|
|
|
|
|
=========================================================*/
|
|
|
|
|
return $cluster_merge;
|
2016-07-18 10:35:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LA LISTE DES GROUPES D'UN ENTREPOT
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
*
|
|
|
|
|
* @return machine_clusters<Array> Renvoie la liste des groupes
|
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function getAll($id_warehouse){
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [1] On rédige/exécute la requête
|
|
|
|
|
=========================================================*/
|
|
|
|
|
$machine_clusters = Table::get('machine_cluster')
|
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
|
->select('*');
|
|
|
|
|
|
|
|
|
|
//TODO: ORDER BY c.name ASC
|
|
|
|
|
|
|
|
|
|
/* [2] On retourne le résultat
|
|
|
|
|
=========================================================*/
|
|
|
|
|
return $machine_clusters->fetch();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE UN GROUPE SPECIFIQUE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @id<int> UID du groupe
|
|
|
|
|
*
|
|
|
|
|
* @return machine_cluster<Array> Renvoie le groupe correspondant
|
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function getById($id_warehouse, $id){
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [1] On rédige/exécute la requête
|
|
|
|
|
=========================================================*/
|
|
|
|
|
$machine_cluster = Table::get('machine_cluster')
|
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
|
->whereId($id)
|
|
|
|
|
->select('*')
|
|
|
|
|
->unique();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [2] On retourne le résultat
|
|
|
|
|
=========================================================*/
|
|
|
|
|
return $machine_cluster->fetch();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE UN GROUPE SPECIFIQUE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @name<String> Nom du groupe
|
|
|
|
|
*
|
|
|
|
|
* @return machine_cluster<Array> Renvoie le groupe correspondant
|
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function getByName($id_warehouse, $name){
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [1] On rédige/exécute la requête
|
|
|
|
|
=========================================================*/
|
|
|
|
|
$machine_cluster = Table::get('machine_cluster')
|
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
|
->whereName($name)
|
|
|
|
|
->select('*')
|
|
|
|
|
->unique();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [2] On retourne le résultat
|
|
|
|
|
=========================================================*/
|
|
|
|
|
return $machine_cluster->fetch();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LES MACHINES D'UN GROUPE DONNE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @id_machine_cluster<int> UID du groupe en question
|
|
|
|
|
*
|
|
|
|
|
* @return members<Array> Retourne la liste des machines du groupe
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function getMembers($id_warehouse, $id_machine_cluster){
|
|
|
|
|
/* [1] On recupere la liste des associations
|
|
|
|
|
=========================================================*/
|
2016-07-23 15:40:54 +00:00
|
|
|
|
$machine_cluster = Table::get('machine_cluster')
|
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
|
->whereId($id_machine_cluster);
|
|
|
|
|
|
|
|
|
|
$machine = Table::get('machine')->select('*');
|
|
|
|
|
|
|
|
|
|
$machine_cluster_merge = Table::get('machine_cluster_merge')
|
|
|
|
|
->join('id_machine_cluster', $machine_cluster)
|
|
|
|
|
->join('id_machine', $machine);
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On verifie que le groupe n'existe plus
|
|
|
|
|
=========================================================*/
|
2016-07-23 15:40:54 +00:00
|
|
|
|
return $machine_cluster_merge->fetch();
|
2016-07-18 10:35:30 +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 machine_clusters<Array> Retourne les groupes trouves
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function search($id_warehouse, $keyword){
|
2016-07-23 15:34:24 +00:00
|
|
|
|
/* [1] On rédige/exécute la requête
|
|
|
|
|
=========================================================*/
|
|
|
|
|
$search = Table::get('machine_cluster')
|
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
|
->whereName(["%$keyword%", Rows::COND_LIKE])
|
|
|
|
|
->select('*');
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
2016-07-23 15:34:24 +00:00
|
|
|
|
/* [2] On retourne le résultat
|
|
|
|
|
=========================================================*/
|
|
|
|
|
return $search->fetch();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-20 17:41:43 +00:00
|
|
|
|
|
|
|
|
|
/* MODIFIE LE NOM D'UN GROUPE DONNE
|
|
|
|
|
*
|
|
|
|
|
* @id_machine_cluster<int> UID du gorupe
|
|
|
|
|
* @name<String> Nouveau nom du groupe
|
|
|
|
|
*
|
|
|
|
|
* @return status<Boolean> TRUE si tout s'est bien passé, sinon FALSE
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function edit($id_warehouse, $id_machine_cluster, $name){
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [1] On redige/execute la requete
|
2016-07-20 17:41:43 +00:00
|
|
|
|
=========================================================*/
|
2016-07-23 15:40:54 +00:00
|
|
|
|
$edited = Table::get('machine_cluster')
|
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
|
->whereId($id_machine_cluster)
|
|
|
|
|
->edit([ 'name' => $name ]);
|
2016-07-20 17:41:43 +00:00
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [2] On retourne le résultat
|
|
|
|
|
=========================================================*/
|
2016-07-20 17:41:43 +00:00
|
|
|
|
return $edited;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-18 10:35:30 +00:00
|
|
|
|
/* SUPPRIME UN GROUPE DONNE
|
|
|
|
|
*
|
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
|
* @id_machine_cluster<int> UID du groupe en question
|
|
|
|
|
*
|
|
|
|
|
* @return status<Boolean> Retourne si oui ou non le groupe a bien ete supprime
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function delete($id_warehouse, $id_machine_cluster){
|
|
|
|
|
/* [1] On redige/execute la requete
|
|
|
|
|
=========================================================*/
|
2016-07-23 15:40:54 +00:00
|
|
|
|
$deleted = Table::get('machine_cluster')
|
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
|
->whereId($id_machine_cluster)
|
|
|
|
|
->delete();
|
2016-07-18 10:35:30 +00:00
|
|
|
|
|
2016-07-23 15:40:54 +00:00
|
|
|
|
/* [2] On retourne le résultat
|
2016-07-18 10:35:30 +00:00
|
|
|
|
=========================================================*/
|
2016-07-23 15:40:54 +00:00
|
|
|
|
return $deleted;
|
2016-07-18 10:35:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|