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 /* MODIFICATION D'UN ENTREPOT
* *
@ -81,40 +124,25 @@
/* [2] Modification de l'utilisateur /* [2] Modification de l'utilisateur
=========================================================*/ =========================================================*/
$edit_user = Database::getPDO()->prepare("UPDATE user $edit_warehouse = Database::getPDO()->prepare("UPDATE warehouse
SET code = :code, SET name = :name,
username = :username, password = :password
firstname = :firstname, WHERE id_warehouse = :id_warehouse");
lastname = :lastname, $edit_warehouse->execute(array(
mail = :mail, ':name' => $name,
password = :password, ':password' => $password,
status = :status ':id_warehouse' => $id_warehouse
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
)); ));
/* [3] On retourne si tout a ete modifie, si erreur /* [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 = $check_warehouse['id_warehouse'] == $id_warehouse;
$checker = $checker && $check_user['code'] == $code; $checker = $checker && $check_warehouse['name'] == $name;
$checker = $checker && $check_user['username'] == $username; $checker = $checker && $check_warehouse['password'] == $password;
$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;
// On retourne l'etat de la modification // On retourne l'etat de la modification
return $checker; 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 /* [1] On redige/execute la requete
=========================================================*/ =========================================================*/
$delete_user = Database::getPDO()->prepare("DELETE FROM user WHERE id_user = :id_user"); $delete_warehouse = Database::getPDO()->prepare("DELETE FROM warehouse WHERE id_warehouse = :id_warehouse");
$delete_user->execute(array( $delete_warehouse->execute(array(
':id_user' => $id_user ':id_warehouse' => $id_warehouse
)); ));
/* [2] On verifie que l'utilisateur n'existe plus /* [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();
?> ?>