2016-02-14 11:37:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager\repo;
|
|
|
|
use \manager\Database;
|
2016-07-07 15:59:31 +00:00
|
|
|
use \manager\sessionManager;
|
2016-02-14 11:37:19 +00:00
|
|
|
use \manager\repo\cluster as clusterRepo;
|
|
|
|
|
2016-07-04 10:13:35 +00:00
|
|
|
class machine extends parentRepo{
|
|
|
|
|
|
|
|
protected static function table_name(){ static $table_name = 'machine'; return $table_name; }
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
/* CREATION D'UNE MACHINE
|
|
|
|
*
|
2016-07-06 09:56:17 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
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-07-06 09:56:17 +00:00
|
|
|
public static function create($id_warehouse, $code, $name){
|
2016-02-14 13:16:47 +00:00
|
|
|
/* [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-07-05 13:50:24 +00:00
|
|
|
$insert_machine = Database::getPDO()->prepare("INSERT INTO machine(id_machine, id_warehouse, code, name)
|
|
|
|
VALUES(DEFAULT, :id_warehouse, :code, :name)");
|
2016-07-04 13:45:29 +00:00
|
|
|
$insert_machine->execute([
|
2016-07-06 09:56:17 +00:00
|
|
|
':id_warehouse' => $id_warehouse,
|
2016-07-05 13:50:24 +00:00
|
|
|
':code' => $code,
|
|
|
|
':name' => $name
|
2016-07-04 13:45:29 +00:00
|
|
|
]);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 13:32:33 +00:00
|
|
|
/* RENVOIE UNE LISTE DE MACHINE EN FONCTION D'UN MOT CLE
|
|
|
|
*
|
2016-07-06 09:56:17 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-16 13:32:33 +00:00
|
|
|
* @keyword<String> Element de recherche
|
|
|
|
*
|
|
|
|
* @return machines<Array> Retourne les machines trouvees
|
|
|
|
*
|
|
|
|
*/
|
2016-07-06 09:56:17 +00:00
|
|
|
public static function search($id_warehouse, $keyword){
|
2016-02-16 13:32:33 +00:00
|
|
|
// On recupere les donnees
|
2016-07-07 15:59:31 +00:00
|
|
|
$searchmachines = Database::getPDO()->prepare("SELECT id_machine, code, name FROM machine
|
2016-07-05 13:50:24 +00:00
|
|
|
WHERE id_warehouse = :id_warehouse
|
|
|
|
AND ( code LIKE '%".$keyword."%'
|
|
|
|
OR name LIKE '%".$keyword."%'
|
|
|
|
)
|
2016-02-16 13:32:33 +00:00
|
|
|
");
|
|
|
|
|
2016-07-05 13:50:24 +00:00
|
|
|
$searchmachines->execute([
|
2016-07-06 09:56:17 +00:00
|
|
|
':id_warehouse' => $id_warehouse
|
2016-07-05 13:50:24 +00:00
|
|
|
]);
|
|
|
|
|
2016-02-16 13:32:33 +00:00
|
|
|
return Database::delNumeric( $searchmachines->fetchAll() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
2016-02-14 13:16:47 +00:00
|
|
|
/* RENVOIE LES GROUPES AUQUEL APPARTIENT UNE MACHINE DONNEE
|
|
|
|
*
|
2016-07-06 09:56:17 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-14 13:16:47 +00:00
|
|
|
* @id_machine<int> UID de la machine en question
|
|
|
|
*
|
|
|
|
* @return clusters<Array> Retourne la liste des groupes auquel appartient la machine
|
|
|
|
*
|
|
|
|
*/
|
2016-07-06 09:56:17 +00:00
|
|
|
public static function getClusters($id_warehouse, $id_machine){
|
2016-02-14 13:16:47 +00:00
|
|
|
/* [1] On redige/execute la requete
|
|
|
|
=========================================================*/
|
2016-07-06 15:36:26 +00:00
|
|
|
$get_clusters = Database::getPDO()->prepare("SELECT c.id_cluster, c.name
|
2016-07-06 09:56:17 +00:00
|
|
|
FROM cluster as c, cluster_merge as cm, machine as m
|
|
|
|
WHERE cm.id_cluster = c.id_cluster
|
|
|
|
AND cm.id_entity = m.id_machine
|
|
|
|
AND m.id_warehouse = :id_warehouse
|
|
|
|
AND cm.id_entity = :id_machine
|
2016-07-08 15:53:50 +00:00
|
|
|
AND c.class = :class
|
2016-02-14 13:16:47 +00:00
|
|
|
ORDER BY c.id_cluster");
|
2016-07-04 13:45:29 +00:00
|
|
|
$get_clusters->execute([
|
2016-07-06 09:56:17 +00:00
|
|
|
':id_warehouse' => $id_warehouse,
|
|
|
|
':id_machine' => $id_machine,
|
|
|
|
':class' => clusterRepo::MACHINE_CLASS
|
2016-07-04 13:45:29 +00:00
|
|
|
]);
|
2016-02-14 13:16:47 +00:00
|
|
|
|
|
|
|
/* [2] On retourne la liste des groupes
|
|
|
|
=========================================================*/
|
|
|
|
return Database::delNumeric( $get_clusters->fetchAll() );
|
2016-02-14 11:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 14:04:48 +00:00
|
|
|
/* MODIFICATION D'UNE MACHINE DONNEE
|
|
|
|
*
|
2016-07-06 09:56:17 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-16 14:04:48 +00:00
|
|
|
* @id_machine<int> UID de la machine
|
|
|
|
* @code<String> Code RFID de la machine
|
|
|
|
* @name<String> Identifiant l'utilisateur
|
|
|
|
*
|
|
|
|
* @return status<Boolean> Renvoie si oui ou non tout s'est bien passe
|
|
|
|
*
|
|
|
|
*/
|
2016-07-06 09:56:17 +00:00
|
|
|
public static function edit($id_warehouse, $id_machine=null, $code=null, $name=null){
|
2016-02-16 14:04:48 +00:00
|
|
|
/* [1] Verification de l'unicite de code+name (si differents)
|
|
|
|
=========================================================*/
|
|
|
|
// On recupere les machine ayant le meme code ou name (si existent)
|
|
|
|
$getbycode = self::getByCode($code);
|
|
|
|
$getbyname = self::getByName($name);
|
|
|
|
|
|
|
|
$check_unique = is_array($getbycode) && $getbycode['id_machine'] == $id_machine || !is_array($getbycode);
|
|
|
|
$check_unique = $check_unique && is_array($getbyname) && $getbyname['id_machine'] == $id_machine || !is_array($getbyname);
|
|
|
|
|
|
|
|
// Si un utilisateur a deja ce code ou ce name (sauf lui), on renvoie une erreur
|
|
|
|
if( !$check_unique )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* [2] Modification de la machine
|
|
|
|
=========================================================*/
|
|
|
|
$edit_machine = Database::getPDO()->prepare("UPDATE machine
|
|
|
|
SET code = :code,
|
2016-07-03 12:57:25 +00:00
|
|
|
name = :name
|
2016-07-05 13:50:24 +00:00
|
|
|
WHERE id_machine = :id_machine
|
|
|
|
AND id_warehouse = :id_warehouse");
|
2016-07-04 13:45:29 +00:00
|
|
|
$edit_machine->execute([
|
2016-07-05 13:50:24 +00:00
|
|
|
':code' => $code,
|
|
|
|
':name' => $name,
|
|
|
|
':id_machine' => $id_machine,
|
2016-07-06 09:56:17 +00:00
|
|
|
':id_warehouse' => $id_warehouse
|
2016-07-04 13:45:29 +00:00
|
|
|
]);
|
2016-02-16 14:04:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] On retourne si tout a ete modifie, si erreur
|
|
|
|
=========================================================*/
|
|
|
|
$check_machine = self::getById($id_machine);
|
|
|
|
|
|
|
|
$checker = $check_machine['id_machine'] == $id_machine;
|
|
|
|
$checker = $checker && $check_machine['code'] == $code;
|
|
|
|
$checker = $checker && $check_machine['name'] == $name;
|
|
|
|
|
|
|
|
// On retourne l'etat de la modification
|
|
|
|
return $checker;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
/* SUPPRIME UNE MACHINE DONNE
|
|
|
|
*
|
2016-07-06 09:56:17 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
2016-02-14 11:37:19 +00:00
|
|
|
* @id_machine<int> UID de la machine en question
|
|
|
|
*
|
|
|
|
* @return status<Boolean> Retourne si oui ou non la machine a bien ete supprime
|
|
|
|
*
|
|
|
|
*/
|
2016-07-06 09:56:17 +00:00
|
|
|
public static function delete($id_warehouse, $id_machine){
|
2016-02-14 11:37:19 +00:00
|
|
|
/* [1] On redige/execute la requete
|
|
|
|
=========================================================*/
|
2016-07-06 09:56:17 +00:00
|
|
|
$delete_machine = Database::getPDO()->prepare("DELETE FROM machine
|
|
|
|
WHERE id_machine = :id_machine
|
|
|
|
AND id_warehouse = :id_warehouse");
|
2016-07-05 13:50:24 +00:00
|
|
|
$delete_machine->execute([
|
|
|
|
':id_machine' => $id_machine,
|
2016-07-06 09:56:17 +00:00
|
|
|
':id_warehouse' => $id_warehouse
|
2016-07-05 13:50:24 +00:00
|
|
|
]);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [2] On verifie que la machine n'existe plus
|
|
|
|
=========================================================*/
|
|
|
|
return ( self::getById($id_machine) === false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
|
2016-07-06 09:56:17 +00:00
|
|
|
/* RETOURNE UNE MACHINE SPECIFIQUE
|
|
|
|
*
|
|
|
|
* @id_warehouse<id> UID de l'entrepot
|
|
|
|
* @id_machine<id> UID de la machine
|
|
|
|
*
|
|
|
|
* @return machine<Array> Données de la machine
|
|
|
|
* FALSE si aucun résultat
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getById($id_warehouse, $id_machine){
|
|
|
|
/* [1] On rédige/execute la requête
|
|
|
|
=========================================================*/
|
|
|
|
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
|
|
|
|
FROM machine as m
|
|
|
|
WHERE m.id_warehouse = :id_warehouse
|
|
|
|
AND m.id_machine = :id_machine");
|
|
|
|
$get->execute([
|
|
|
|
':id_warehouse' => $id_warehouse,
|
|
|
|
':id_machine' => $id_machine
|
|
|
|
]);
|
|
|
|
|
|
|
|
/* [2] Gestion des données
|
|
|
|
=========================================================*/
|
|
|
|
$found = $get->fetch();
|
|
|
|
|
|
|
|
// Si aucun résultat
|
|
|
|
if( $found === false )
|
|
|
|
return false;
|
|
|
|
|
2016-07-06 10:16:11 +00:00
|
|
|
return Database::delNumeric( $found, true );
|
2016-07-06 09:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RETOURNE UNE MACHINE SPECIFIQUE
|
|
|
|
*
|
|
|
|
* @id_warehouse<id> UID de l'entrepot
|
|
|
|
* @code<String> Code RFID de la machine
|
|
|
|
*
|
|
|
|
* @return machine<Array> Données de la machine
|
|
|
|
* FALSE si aucun résultat
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getByCode($id_warehouse, $code){
|
|
|
|
/* [1] On rédige/execute la requête
|
|
|
|
=========================================================*/
|
|
|
|
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
|
|
|
|
FROM machine as m
|
|
|
|
WHERE m.id_warehouse = :id_warehouse
|
|
|
|
AND m.code = :code");
|
|
|
|
$get->execute([
|
|
|
|
':id_warehouse' => $id_warehouse,
|
|
|
|
':code' => $code
|
|
|
|
]);
|
|
|
|
|
|
|
|
/* [2] Gestion des données
|
|
|
|
=========================================================*/
|
|
|
|
$found = $get->fetch();
|
|
|
|
|
|
|
|
// Si aucun résultat
|
|
|
|
if( $found === false )
|
|
|
|
return false;
|
|
|
|
|
2016-07-06 10:16:11 +00:00
|
|
|
return Database::delNumeric( $found, true );
|
2016-07-06 09:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RETOURNE UNE MACHINE SPECIFIQUE
|
|
|
|
*
|
|
|
|
* @id_warehouse<id> UID de l'entrepot
|
|
|
|
* @name<String> Nom de la machine
|
|
|
|
*
|
|
|
|
* @return machine<Array> Données de la machine
|
|
|
|
* FALSE si aucun résultat
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getByName($id_warehouse, $name){
|
|
|
|
/* [1] On rédige/execute la requête
|
|
|
|
=========================================================*/
|
|
|
|
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
|
|
|
|
FROM machine as m
|
|
|
|
WHERE m.id_warehouse = :id_warehouse
|
|
|
|
AND m.name = :name");
|
|
|
|
$get->execute([
|
|
|
|
':id_warehouse' => $id_warehouse,
|
|
|
|
':name' => $name
|
|
|
|
]);
|
|
|
|
|
|
|
|
/* [2] Gestion des données
|
|
|
|
=========================================================*/
|
|
|
|
$found = $get->fetch();
|
|
|
|
|
|
|
|
// Si aucun résultat
|
|
|
|
if( $found === false )
|
|
|
|
return false;
|
|
|
|
|
2016-07-06 10:16:11 +00:00
|
|
|
return Database::delNumeric( $found, true );
|
2016-07-06 09:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RETOURNE TOUTES LES MACHINES DE L'ENTREPOT
|
|
|
|
*
|
|
|
|
* @id_warehouse<id> UID de l'entrepot
|
|
|
|
*
|
|
|
|
* @return machines<Array> Données des la machine
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getAll($id_warehouse){
|
|
|
|
/* [1] On rédige/execute la requête
|
|
|
|
=========================================================*/
|
|
|
|
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
|
|
|
|
FROM machine as m
|
|
|
|
WHERE m.id_warehouse = :id_warehouse");
|
|
|
|
$get->execute([
|
|
|
|
':id_warehouse' => $id_warehouse
|
|
|
|
]);
|
|
|
|
|
|
|
|
return Database::delNumeric( $get->fetchAll() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-07 15:59:31 +00:00
|
|
|
/* VERIFIE MET A JOUR LE TOKEN DE SYNCHRONISATION
|
|
|
|
*
|
|
|
|
* @token<String> Nouveau token de synchronisation
|
|
|
|
*
|
|
|
|
* @return status<Boolean> VRAI si le token est correct, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function checkToken($token){
|
|
|
|
/* [1] On vérifie le token
|
|
|
|
=========================================================*/
|
|
|
|
$hash = sessionManager::secure_hash($token);
|
|
|
|
|
|
|
|
$byToken = self::getByToken($hash);
|
|
|
|
|
|
|
|
// Si aucun résultat, erreur
|
|
|
|
if( count($byToken) < 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On met à jour le token
|
|
|
|
=========================================================*/
|
|
|
|
$updateToken = Database::getPDO()->prepare("UPDATE machine
|
|
|
|
SET token = :token
|
|
|
|
WHERE id_machine = :id_machine");
|
|
|
|
$updateToken->execute([
|
|
|
|
':token' => $token,
|
|
|
|
':id_machine' => $byToken[0]['id_machine']
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] On retourne que tout s'est bien déroulé
|
|
|
|
=========================================================*/
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
?>
|