2016-07-04 10:51:33 +00:00
|
|
|
<?php
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
namespace database\repo;
|
2016-11-05 13:57:35 +00:00
|
|
|
use \database\core\DatabaseDriver;
|
2017-09-23 17:05:54 +00:00
|
|
|
use \database\core\Repo;
|
2016-07-04 10:51:33 +00:00
|
|
|
use \manager\sessionManager;
|
2016-10-18 14:03:03 +00:00
|
|
|
use \orm\core\Table;
|
|
|
|
use \orm\core\Rows;
|
2016-07-04 10:51:33 +00:00
|
|
|
|
|
|
|
class warehouse extends parentRepo{
|
|
|
|
|
|
|
|
protected static function table_name(){ static $table_name = 'warehouse'; return $table_name; }
|
|
|
|
|
2016-07-04 13:45:29 +00:00
|
|
|
/* CREATION D'UN ENTREPOT
|
2016-07-04 10:51:33 +00:00
|
|
|
*
|
|
|
|
* @name<String> Identifiant de l'entrepot
|
|
|
|
* @password<String> Mot de passe de l'entrepot
|
|
|
|
*
|
|
|
|
* @return id_warehouse<int> Renvoie l'UID de l'entrepot cree
|
|
|
|
* Renvoie FALSE si une erreur occure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function create($name, $password){
|
2016-07-23 16:06:39 +00:00
|
|
|
/* [1] On rédige/exécute la requête
|
2016-07-04 10:51:33 +00:00
|
|
|
=========================================================*/
|
2016-07-23 16:06:39 +00:00
|
|
|
$created = Table::get('warehouse')
|
|
|
|
->insert([
|
2016-07-24 17:18:55 +00:00
|
|
|
'id_warehouse' => Rows::INSERT_DEFAULT,
|
2016-07-23 16:06:39 +00:00
|
|
|
'name' => $name,
|
2017-10-12 12:29:52 +00:00
|
|
|
'password' => \secure_hash( $password, $name ),
|
|
|
|
'token' => \secure_hash( uniqid(), $name.'-*-'.$name )
|
2016-07-23 16:06:39 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Si name déja pris, erreur
|
|
|
|
if( !$created )
|
2016-07-04 10:51:33 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* [3] On retourne l'id_warehouse ou FALSE si erreur
|
|
|
|
=========================================================*/
|
|
|
|
$check_warehouse = self::getByName($name);
|
|
|
|
|
|
|
|
// Si n'existe pas on retourne FALSE
|
2016-07-23 16:06:39 +00:00
|
|
|
if( $check_warehouse === false )
|
2016-07-04 10:51:33 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Sinon, on retourne son id
|
2016-07-23 16:06:39 +00:00
|
|
|
return $check_warehouse['id_warehouse'];
|
2016-07-04 10:51:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-04 12:39:27 +00:00
|
|
|
/* MISE A JOUR DU TOKEN D'UN ENTREPOT
|
|
|
|
*
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
*
|
|
|
|
* @return new_token<String> Renvoie le nouveau token
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function updateToken($id_warehouse=null){
|
|
|
|
/* [1] On vérifie que l'entrepot existe
|
|
|
|
=========================================================*/
|
|
|
|
if( self::getById($id_warehouse) === false )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On met à jour le token
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) On crée un nouveau token */
|
2016-07-07 15:59:31 +00:00
|
|
|
$new_token = sessionManager::secure_hash( uniqid() );
|
2016-07-04 12:39:27 +00:00
|
|
|
|
2016-07-23 16:06:39 +00:00
|
|
|
$updated = Table::get('warehouse')
|
|
|
|
->whereId($id_warehouse)
|
|
|
|
->edit([ 'token' => $new_token ]);
|
2016-07-04 12:39:27 +00:00
|
|
|
|
|
|
|
/* [3] On renvoie le token
|
|
|
|
=========================================================*/
|
2016-07-23 16:06:39 +00:00
|
|
|
return ( $updated ) ? $new_token : false;
|
2016-07-04 12:39:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-04 10:51:33 +00:00
|
|
|
|
2016-07-06 09:32:51 +00:00
|
|
|
/* RETOURNE LA LISTE DES MODULE D'UN ENTREPOT
|
|
|
|
*
|
|
|
|
* @return modules<Array> Liste des modules autorisés pour l'entrepot
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getModules($id_warehouse){
|
|
|
|
/* [1] On récupère les modules
|
|
|
|
=========================================================*/
|
2017-09-23 17:05:54 +00:00
|
|
|
/* (1) Récupération */
|
2017-09-25 13:29:15 +00:00
|
|
|
$mod_req = new Repo('module/getForWarehouse', [$id_warehouse]);
|
2016-07-06 09:32:51 +00:00
|
|
|
|
2017-09-23 17:05:54 +00:00
|
|
|
$answer = $mod_req->answer();
|
|
|
|
|
|
|
|
/* (2) Gestion erreur */
|
|
|
|
if( $answer === false )
|
|
|
|
return []; // no error
|
2016-07-06 09:32:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [2] On formatte les données pour avoir 1 niveau de tableau
|
|
|
|
=========================================================*/
|
2017-09-23 17:05:54 +00:00
|
|
|
$modules = []; // id => name
|
|
|
|
|
|
|
|
foreach($answer as $module)
|
|
|
|
$modules[$module['id_module']] = $module['name'];
|
2016-07-06 09:32:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [3] On retourne la liste
|
|
|
|
=========================================================*/
|
2016-07-23 16:06:39 +00:00
|
|
|
return $modules;
|
2016-07-06 09:32:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-04 10:51:33 +00:00
|
|
|
/* MODIFICATION D'UN ENTREPOT
|
|
|
|
*
|
|
|
|
* @id_warehouse<int> UID de l'entrepot
|
|
|
|
* @name<String> Identifiant de l'entrepot
|
|
|
|
* @password<String> Mot de passe de l'entrepot
|
|
|
|
*
|
|
|
|
* @return status<Boolean> Renvoie si oui ou non tout s'est bien passe
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function edit($id_warehouse=null, $name=null, $password=null){
|
2016-07-23 16:06:39 +00:00
|
|
|
/* [1] On rédige/exécute la requête
|
2016-07-04 10:51:33 +00:00
|
|
|
=========================================================*/
|
2016-07-23 16:06:39 +00:00
|
|
|
$updated = Table::get('warehouse')
|
|
|
|
->whereId($id_warehouse)
|
|
|
|
->edit([
|
|
|
|
'name' => $name,
|
|
|
|
'password' => sessionManager::secure_hash( $password )
|
|
|
|
]);
|
2016-07-04 10:51:33 +00:00
|
|
|
|
|
|
|
|
2016-07-23 16:06:39 +00:00
|
|
|
/* [2] On retourne le résultat
|
2016-07-04 10:51:33 +00:00
|
|
|
=========================================================*/
|
2016-07-23 16:06:39 +00:00
|
|
|
// FAUX si @name est déja pris et si erreur
|
|
|
|
return $updated;
|
2016-07-04 10:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-04 12:39:27 +00:00
|
|
|
/* SUPPRIME UN ENTREPOT DONNE
|
2016-07-04 10:51:33 +00:00
|
|
|
*
|
2016-07-04 12:39:27 +00:00
|
|
|
* @id_warehouse<int> UID de l'entrepot en question
|
2016-07-04 10:51:33 +00:00
|
|
|
*
|
2016-07-04 12:39:27 +00:00
|
|
|
* @return status<Boolean> Retourne si oui ou non l'entrepot a bien ete supprime
|
2016-07-04 10:51:33 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-07-04 12:39:27 +00:00
|
|
|
public static function delete($id_warehouse){
|
2016-07-04 10:51:33 +00:00
|
|
|
/* [1] On redige/execute la requete
|
|
|
|
=========================================================*/
|
2016-07-23 16:06:39 +00:00
|
|
|
$deleted = Table::get('warehouse')
|
|
|
|
->whereId($id_warehouse)
|
|
|
|
->delete();
|
2016-07-04 10:51:33 +00:00
|
|
|
|
|
|
|
|
2016-07-23 16:06:39 +00:00
|
|
|
/* [2] On verifie que l'entrepot n'existe plus
|
2016-07-04 10:51:33 +00:00
|
|
|
=========================================================*/
|
2016-07-23 16:06:39 +00:00
|
|
|
return $deleted;
|
2016-07-04 10:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|