188 lines
3.8 KiB
PHP
188 lines
3.8 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace manager\repo;
|
||
|
use \manager\Database;
|
||
|
use \manager\repo\cluster as clusterRepo;
|
||
|
|
||
|
class machine{
|
||
|
|
||
|
/* CREATION D'UNE MACHINE
|
||
|
*
|
||
|
* @name<String> Nom du groupe
|
||
|
*
|
||
|
* @return id_user<int> Renvoie l'UID du groupe cree
|
||
|
* Renvoie FALSE si une erreur occure
|
||
|
*
|
||
|
*/
|
||
|
public static function create($name){
|
||
|
/* [1] Verification de l'unicite de name
|
||
|
=========================================================*/
|
||
|
$check_unique = ( self::getByName($name) === false );
|
||
|
|
||
|
// Si un groupe a deja ce nom, on renvoie une erreur
|
||
|
if( !$check_unique )
|
||
|
return false;
|
||
|
|
||
|
|
||
|
/* [2] Creation du groupe
|
||
|
=========================================================*/
|
||
|
$insert_user = Database::getPDO()->prepare("INSERT INTO cluster(id_cluster, name)
|
||
|
VALUES(DEFAULT, :name)");
|
||
|
$insert_user->execute(array(
|
||
|
':name' => $name
|
||
|
));
|
||
|
|
||
|
/* [3] On retourne l'id_group ou FALSE si erreur
|
||
|
=========================================================*/
|
||
|
$check_group = self::getByName($name);
|
||
|
|
||
|
// Si n'existe pas on retourne FALSE
|
||
|
if( $check_group === false )
|
||
|
return false;
|
||
|
|
||
|
// Sinon, on retourne son id
|
||
|
return $check_group['id_cluster'];
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/* 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 );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/* RENVOIE LA MACHINE DE NOM DONNE
|
||
|
*
|
||
|
* @name<String> Nom du groupe en question
|
||
|
*
|
||
|
* @return groupe<Array> Renvoie le groupe de nom donne si existe
|
||
|
* @return error<Boolean> Retourne FALSE si aucun resultat
|
||
|
*
|
||
|
*/
|
||
|
public static function getByName($name){
|
||
|
// On ecrit la requete
|
||
|
$request = Database::getPDO()->prepare("SELECT * FROM cluster
|
||
|
WHERE name = :name");
|
||
|
|
||
|
|
||
|
// On execute la requete
|
||
|
$request->execute(array(
|
||
|
':name' => $name
|
||
|
));
|
||
|
|
||
|
// On recupere 1 seul groupe
|
||
|
$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 );
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/* 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 );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
?>
|