Repo 'warehouse' terminé, mais aucun test pour l'instant

This commit is contained in:
xdrm-brackets 2016-07-04 14:39:27 +02:00
parent 2db4b62428
commit 81d84d833f
2 changed files with 77 additions and 36 deletions

View File

@ -56,6 +56,49 @@
/* 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 */
$new_token = sessionManager::secure_sha1( uniqid() );
/* (2) On applique le nouveau token */
$update_token = Database::getPDO()->prepare("UPDATE warehouse
SET token = :token
WHERE id_warehouse = :id_warehouse");
$update_token->execute(array(
':token' => $new_token,
':id_warehouse' => $id_warehouse
));
/* [3] On renvoie le token
=========================================================*/
return $new_token;
}
/* MODIFICATION D'UN ENTREPOT
*
@ -81,40 +124,25 @@
/* [2] Modification de l'utilisateur
=========================================================*/
$edit_user = Database::getPDO()->prepare("UPDATE user
SET code = :code,
username = :username,
firstname = :firstname,
lastname = :lastname,
mail = :mail,
password = :password,
status = :status
WHERE id_user = :id_user");
$edit_user->execute(array(
':code' => $code,
':username' => $username,
':firstname' => $firstname,
':lastname' => $lastname,
':mail' => $mail,
':password' => $password,
':status' => $status,
':id_user' => $id_user
$edit_warehouse = Database::getPDO()->prepare("UPDATE warehouse
SET name = :name,
password = :password
WHERE id_warehouse = :id_warehouse");
$edit_warehouse->execute(array(
':name' => $name,
':password' => $password,
':id_warehouse' => $id_warehouse
));
/* [3] On retourne si tout a ete modifie, si erreur
=========================================================*/
$check_user = self::getById($id_user);
$check_warehouse = self::getById($id_warehouse);
$checker = $check_user['id_user'] == $id_user;
$checker = $checker && $check_user['code'] == $code;
$checker = $checker && $check_user['username'] == $username;
$checker = $checker && $check_user['firstname'] == $firstname;
$checker = $checker && $check_user['lastname'] == $lastname;
$checker = $checker && $check_user['mail'] == $mail;
$checker = $checker && $check_user['password'] == $password;
$checker = $checker && $check_user['status'] == $status;
$checker = $check_warehouse['id_warehouse'] == $id_warehouse;
$checker = $checker && $check_warehouse['name'] == $name;
$checker = $checker && $check_warehouse['password'] == $password;
// On retourne l'etat de la modification
return $checker;
@ -127,25 +155,25 @@
/* SUPPRIME UN UTILISATEUR DONNE
/* SUPPRIME UN ENTREPOT DONNE
*
* @id_user<int> UID de l'utilisateur en question
* @id_warehouse<int> UID de l'entrepot en question
*
* @return status<Boolean> Retourne si oui ou non l'utilisateur a bien ete supprime
* @return status<Boolean> Retourne si oui ou non l'entrepot a bien ete supprime
*
*/
public static function delete($id_user){
public static function delete($id_warehouse){
/* [1] On redige/execute la requete
=========================================================*/
$delete_user = Database::getPDO()->prepare("DELETE FROM user WHERE id_user = :id_user");
$delete_user->execute(array(
':id_user' => $id_user
$delete_warehouse = Database::getPDO()->prepare("DELETE FROM warehouse WHERE id_warehouse = :id_warehouse");
$delete_warehouse->execute(array(
':id_warehouse' => $id_warehouse
));
/* [2] On verifie que l'utilisateur n'existe plus
=========================================================*/
return ( self::getById($id_user) === false );
return ( self::getById($id_warehouse) === false );
}

View File

@ -311,5 +311,18 @@
function createWarehouse(){
$insert = new Repo('warehouse/create', array( 'FifthWarehouse', 'MyPassword' ) );
var_dump( $insert->answer() );
$getAll = new Repo('warehouse/getAll');
}createWarehouse();
?>