2016-02-14 11:37:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager\repo;
|
|
|
|
use \manager\Database;
|
|
|
|
use \manager\repo\cluster as clusterRepo;
|
|
|
|
|
|
|
|
class machine{
|
|
|
|
|
|
|
|
/* CREATION D'UNE MACHINE
|
|
|
|
*
|
2016-02-14 13:16:47 +00:00
|
|
|
* @code<String> Code de la machine
|
|
|
|
* @name<String> Nom de la machine
|
2016-02-14 11:37:19 +00:00
|
|
|
*
|
2016-02-14 13:16:47 +00:00
|
|
|
* @return id_machine<int> Renvoie l'UID de la machine cree
|
2016-02-14 11:37:19 +00:00
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
*
|
|
|
|
*/
|
2016-02-14 13:16:47 +00:00
|
|
|
public static function create($code, $name){
|
|
|
|
/* [1] Verification de l'unicite de code+name
|
2016-02-14 11:37:19 +00:00
|
|
|
=========================================================*/
|
2016-02-14 13:16:47 +00:00
|
|
|
$check_unique = ( self::getByCode($code) === false );
|
|
|
|
$check_unique = $check_unique && ( self::getByName($name) === false );
|
2016-02-14 11:37:19 +00:00
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
// Si une machine a deja ce code/nom, on renvoie une erreur
|
2016-02-14 11:37:19 +00:00
|
|
|
if( !$check_unique )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
/* [2] Creation de la machine
|
2016-02-14 11:37:19 +00:00
|
|
|
=========================================================*/
|
2016-02-14 13:16:47 +00:00
|
|
|
$insert_machine = Database::getPDO()->prepare("INSERT INTO machine(id_machine, code, name)
|
|
|
|
VALUES(DEFAULT, :code, :name)");
|
|
|
|
$insert_machine->execute(array(
|
|
|
|
':code' => $code,
|
2016-02-14 11:37:19 +00:00
|
|
|
':name' => $name
|
|
|
|
));
|
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
/* [3] On retourne l'id_machine ou FALSE si erreur
|
2016-02-14 11:37:19 +00:00
|
|
|
=========================================================*/
|
2016-02-14 13:16:47 +00:00
|
|
|
$check_machine = self::getByCode($code);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
// Si n'existe pas on retourne FALSE
|
2016-02-14 13:16:47 +00:00
|
|
|
if( $check_machine === false )
|
2016-02-14 11:37:19 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Sinon, on retourne son id
|
2016-02-14 13:16:47 +00:00
|
|
|
return $check_machine['id_machine'];
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LA LISTE DE TOUTES LES MACHINES
|
|
|
|
*
|
|
|
|
* @return machine<Array> Liste des machines de la BDD
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getAll(){
|
|
|
|
// On ecrit la requete
|
|
|
|
$request = Database::getPDO()->query("SELECT * FROM machine ORDER BY id_machine");
|
|
|
|
|
|
|
|
// On recupere le resultat
|
|
|
|
$answer = $request->fetchAll();
|
|
|
|
|
|
|
|
// On retourne en supprimant les indices numeriques
|
|
|
|
return Database::delNumeric( $answer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LA MACHINE D'ID DONNE
|
|
|
|
*
|
|
|
|
* @id<int> Id de la machine en question
|
|
|
|
*
|
|
|
|
* @return machine<Array> Renvoie la machine d'id donne si existe
|
|
|
|
* @return error<Boolean> Retourne FALSE si aucun resultat
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getById($id){
|
|
|
|
// On ecrit la requete
|
|
|
|
$request = Database::getPDO()->prepare("SELECT * FROM machine
|
|
|
|
WHERE id_machine = :id");
|
|
|
|
|
|
|
|
// On execute la requete
|
|
|
|
$request->execute(array(
|
|
|
|
':id' => $id
|
|
|
|
));
|
|
|
|
|
|
|
|
// On recupere 1 seule machine
|
|
|
|
$answer = $request->fetch();
|
|
|
|
|
|
|
|
// Gestion d'erreur -> aucun resultat
|
|
|
|
if( $answer === false )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// On retourne en supprimant les indices numeriques
|
|
|
|
return Database::delNumeric( $answer, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
/* RENVOIE LA MACHINE DE CODE DONNE
|
|
|
|
*
|
|
|
|
* @code<String> Code de la machine en question
|
|
|
|
*
|
|
|
|
* @return machine<Array> Renvoie la machine de code donne si existe
|
|
|
|
* @return error<Boolean> Retourne FALSE si aucun resultat
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getByCode($code){
|
|
|
|
// On ecrit la requete
|
|
|
|
$request = Database::getPDO()->prepare("SELECT * FROM machine
|
|
|
|
WHERE code = :code");
|
|
|
|
|
|
|
|
|
|
|
|
// On execute la requete
|
|
|
|
$request->execute(array(
|
|
|
|
':code' => $code
|
|
|
|
));
|
|
|
|
|
|
|
|
// On recupere 1 seule machine
|
|
|
|
$answer = $request->fetch();
|
|
|
|
|
|
|
|
// Gestion d'erreur -> aucun resultat
|
|
|
|
if( $answer === false )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// On retourne en supprimant les indices numeriques
|
|
|
|
return Database::delNumeric( $answer, true );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
/* RENVOIE LA MACHINE DE NOM DONNE
|
|
|
|
*
|
2016-02-14 13:16:47 +00:00
|
|
|
* @name<String> Nom de la machine en question
|
2016-02-14 11:37:19 +00:00
|
|
|
*
|
2016-02-14 13:16:47 +00:00
|
|
|
* @return machine<Array> Renvoie la machine de nom donne si existe
|
2016-02-14 11:37:19 +00:00
|
|
|
* @return error<Boolean> Retourne FALSE si aucun resultat
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getByName($name){
|
|
|
|
// On ecrit la requete
|
2016-02-14 13:16:47 +00:00
|
|
|
$request = Database::getPDO()->prepare("SELECT * FROM machine
|
2016-02-14 11:37:19 +00:00
|
|
|
WHERE name = :name");
|
|
|
|
|
|
|
|
|
|
|
|
// On execute la requete
|
|
|
|
$request->execute(array(
|
|
|
|
':name' => $name
|
|
|
|
));
|
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
// On recupere 1 seule machine
|
2016-02-14 11:37:19 +00:00
|
|
|
$answer = $request->fetch();
|
|
|
|
|
|
|
|
// Gestion d'erreur -> aucun resultat
|
|
|
|
if( $answer === false )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// On retourne en supprimant les indices numeriques
|
|
|
|
return Database::delNumeric( $answer, true );
|
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* RENVOIE LES GROUPES AUQUEL APPARTIENT UNE MACHINE DONNEE
|
|
|
|
*
|
|
|
|
* @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){
|
|
|
|
/* [1] On redige/execute la requete
|
|
|
|
=========================================================*/
|
|
|
|
$get_clusters = Database::getPDO()->prepare("SELECT c.* FROM cluster as c, cluster_merge as cm
|
|
|
|
WHERE cm.id_cluster = c.id_cluster
|
|
|
|
AND cm.id_entity = :id_machine
|
|
|
|
ORDER BY c.id_cluster");
|
|
|
|
$get_clusters->execute(array(
|
|
|
|
':id_machine' => $id_machine
|
|
|
|
));
|
|
|
|
|
|
|
|
/* [2] On retourne la liste des groupes
|
|
|
|
=========================================================*/
|
|
|
|
return Database::delNumeric( $get_clusters->fetchAll() );
|
2016-02-14 11:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* SUPPRIME UNE MACHINE DONNE
|
|
|
|
*
|
|
|
|
* @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){
|
|
|
|
/* [1] On redige/execute la requete
|
|
|
|
=========================================================*/
|
|
|
|
$delete_machine = Database::getPDO()->prepare("DELETE FROM machine WHERE id_machine = :id_machine");
|
|
|
|
$delete_machine->execute(array(
|
|
|
|
':id_machine' => $id_machine
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On verifie que la machine n'existe plus
|
|
|
|
=========================================================*/
|
|
|
|
return ( self::getById($id_machine) === false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|