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-07-23 14:36:58 +00:00
|
|
|
use \manager\ORM\Table;
|
|
|
|
use \manager\ORM\Rows;
|
2016-07-17 08:27:59 +00:00
|
|
|
use \manager\Checker;
|
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
|
|
|
* @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-09 12:13:08 +00:00
|
|
|
public static function create($id_warehouse, $name){
|
2016-07-23 14:36:58 +00:00
|
|
|
/* [1] Creation de la machine
|
2016-02-14 11:37:19 +00:00
|
|
|
=========================================================*/
|
2016-07-23 14:36:58 +00:00
|
|
|
$inserted = Table::get('machine')->insert([
|
|
|
|
'id_machine' => Rows::DEFAULT,
|
|
|
|
'id_warehouse' => $id_warehouse,
|
|
|
|
'name' => $name,
|
|
|
|
'token' => sessionManager::secure_hash( uniqid() )
|
|
|
|
]);
|
2016-02-14 11:37:19 +00:00
|
|
|
|
2016-07-23 14:36:58 +00:00
|
|
|
// Si erreur (car name doit être unique)
|
|
|
|
if( !$inserted )
|
2016-02-14 11:37:19 +00:00
|
|
|
return false;
|
|
|
|
|
2016-07-23 14:36:58 +00:00
|
|
|
/* [2] On retourne l'id_machine ou FALSE si erreur
|
2016-02-14 11:37:19 +00:00
|
|
|
=========================================================*/
|
2016-07-09 12:13:08 +00:00
|
|
|
$check_machine = self::getByName($id_warehouse, $name);
|
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-23 14:36:58 +00:00
|
|
|
$search = Table::get('machine')
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
->whereName(["%$keyword%", Rows::COND_LIKE])
|
|
|
|
->select('id_machine')
|
|
|
|
->select('name');
|
2016-02-16 13:32:33 +00:00
|
|
|
|
2016-07-23 14:36:58 +00:00
|
|
|
return $search->fetch();
|
2016-02-16 13:32:33 +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
|
|
|
|
*
|
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-23 14:36:58 +00:00
|
|
|
$cluster = Table::get('machine_cluster')
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
->select('*');
|
|
|
|
$cluster_merge = Table::get('machine_cluster_merge')
|
|
|
|
->whereIdMachine($id_machine)
|
|
|
|
->join('id_machine_cluster', $cluster);
|
2016-02-14 13:16:47 +00:00
|
|
|
|
|
|
|
/* [2] On retourne la liste des groupes
|
|
|
|
=========================================================*/
|
2016-07-23 14:36:58 +00:00
|
|
|
return $cluster_merge->fetch();
|
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
|
|
|
|
* @name<String> Identifiant l'utilisateur
|
|
|
|
*
|
|
|
|
* @return status<Boolean> Renvoie si oui ou non tout s'est bien passe
|
|
|
|
*
|
|
|
|
*/
|
2016-07-09 12:13:08 +00:00
|
|
|
public static function edit($id_warehouse, $id_machine=null, $name=null){
|
2016-07-23 14:36:58 +00:00
|
|
|
/* [1] Modification de la machine
|
2016-02-16 14:04:48 +00:00
|
|
|
=========================================================*/
|
|
|
|
|
2016-07-23 14:36:58 +00:00
|
|
|
$edited = Table::get('machine')
|
|
|
|
->whereId($id_machine)
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
->edit([ 'name' => $name ]);
|
2016-02-16 14:04:48 +00:00
|
|
|
|
|
|
|
// On retourne l'etat de la modification
|
2016-07-23 14:36:58 +00:00
|
|
|
return $edited;
|
2016-02-16 14:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-23 14:36:58 +00:00
|
|
|
$deleted = Table::get('machine')
|
|
|
|
->whereId($id_machine)
|
2016-07-23 22:03:02 +00:00
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
->delete();
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
2016-07-23 14:36:58 +00:00
|
|
|
/* [2] On verifie que la machine est bien supprimée
|
2016-02-14 11:37:19 +00:00
|
|
|
=========================================================*/
|
2016-07-23 22:03:02 +00:00
|
|
|
return $deleted;
|
2016-02-14 11:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
=========================================================*/
|
2016-07-23 14:36:58 +00:00
|
|
|
$machine = Table::get('machine')
|
|
|
|
->whereId($id_machine)
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
->select(['id_machine', 'name'])
|
|
|
|
->unique();
|
2016-07-06 09:56:17 +00:00
|
|
|
|
2016-07-23 14:36:58 +00:00
|
|
|
return $machine->fetch();
|
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
|
|
|
|
=========================================================*/
|
2016-07-23 14:36:58 +00:00
|
|
|
$machine = Table::get('machine')
|
|
|
|
->whereName($name)
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
->select(['id_machine', 'name'])
|
|
|
|
->unique();
|
2016-07-06 09:56:17 +00:00
|
|
|
|
2016-07-23 14:36:58 +00:00
|
|
|
return $machine->fetch();
|
2016-07-06 09:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-09 10:44:06 +00:00
|
|
|
/* RETOURNE UNE MACHINE SPECIFIQUE
|
|
|
|
*
|
|
|
|
* @id_warehouse<id> UID de l'entrepot
|
|
|
|
* @token<String> Token de la machine
|
|
|
|
*
|
|
|
|
* @return machine<Array> Données de la machine
|
|
|
|
* FALSE si aucun résultat
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getByToken($id_warehouse, $token){
|
|
|
|
/* [1] On rédige/execute la requête
|
|
|
|
=========================================================*/
|
2016-07-23 14:36:58 +00:00
|
|
|
$machine = Table::get('machine')
|
|
|
|
->whereToken($token)
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
|
|
|
->select(['id_machine', 'name'])
|
|
|
|
->unique();
|
2016-07-09 10:44:06 +00:00
|
|
|
|
2016-07-23 14:36:58 +00:00
|
|
|
return $machine->fetch();
|
2016-07-09 10:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
=========================================================*/
|
2016-07-23 14:36:58 +00:00
|
|
|
$machine = Table::get('machine')
|
|
|
|
->whereIdWarehouse($id_warehouse)
|
2016-07-23 15:34:24 +00:00
|
|
|
->select(['id_machine', 'name']);
|
2016-07-06 09:56:17 +00:00
|
|
|
|
2016-07-23 14:36:58 +00:00
|
|
|
return $machine->fetch();
|
2016-07-06 09:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-07 15:59:31 +00:00
|
|
|
/* VERIFIE MET A JOUR LE TOKEN DE SYNCHRONISATION
|
|
|
|
*
|
2016-07-17 08:27:59 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
* @token<String> Token de synchronisation
|
|
|
|
* @newToken<String> Nouveau token de synchronisation (optionnel, uniquement quand on arrive à la fin du cycle de la hashChain)
|
2016-07-07 15:59:31 +00:00
|
|
|
*
|
|
|
|
* @return status<Boolean> VRAI si le token est correct, sinon FALSE
|
|
|
|
*
|
|
|
|
*/
|
2016-07-17 08:27:59 +00:00
|
|
|
public static function checkToken($id_warehouse, $token, $newToken=null){
|
2016-07-07 15:59:31 +00:00
|
|
|
/* [1] On vérifie le token
|
|
|
|
=========================================================*/
|
|
|
|
$hash = sessionManager::secure_hash($token);
|
|
|
|
|
2016-07-09 10:44:06 +00:00
|
|
|
$byToken = self::getByToken($id_warehouse, $hash);
|
2016-07-07 15:59:31 +00:00
|
|
|
|
|
|
|
// Si aucun résultat, erreur
|
|
|
|
if( count($byToken) < 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On met à jour le token
|
|
|
|
=========================================================*/
|
2016-07-23 14:36:58 +00:00
|
|
|
$updated = Table::get('machine')
|
|
|
|
->whereId($id_machine)
|
|
|
|
->edit([
|
|
|
|
'token' => Checker::run('hash', $newToken) ? $newToken : $token,
|
|
|
|
'id_machine' => $byToken[0]['id_machine']
|
|
|
|
]);
|
2016-07-07 15:59:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [3] On retourne que tout s'est bien déroulé
|
|
|
|
=========================================================*/
|
2016-07-23 14:36:58 +00:00
|
|
|
return $updated;
|
2016-07-07 15:59:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 11:37:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
?>
|