Repository 'user' fonctionne avec ORM sauf la méthode 'search' ou il y a des 'WHERE .. OR ...'
This commit is contained in:
parent
5fd130287a
commit
726f328a14
|
@ -23,35 +23,29 @@
|
|||
*
|
||||
*/
|
||||
public static function create($id_warehouse, $code, $username, $firstname, $lastname, $mail){
|
||||
/* [1] Verification de l'unicite de code+username
|
||||
/* [1] On retourne l'id_user ou FALSE si erreur
|
||||
=========================================================*/
|
||||
$check_unique = !is_array(self::getByCode($id_warehouse, $code));
|
||||
$check_unique = $check_unique && !is_array(self::getByUsername($id_warehouse, $username));
|
||||
|
||||
// Si un utilisateur a deja ce code ou cet username, on renvoie une erreur
|
||||
if( !$check_unique )
|
||||
return false;
|
||||
|
||||
|
||||
/* [2] Creation de l'utilisateur
|
||||
=========================================================*/
|
||||
$insert_user = Database::getPDO()->prepare("INSERT INTO user(id_user, id_warehouse, code, username, firstname, lastname, mail)
|
||||
VALUES(DEFAULT, :id_warehouse, :code, :username, :firstname, :lastname, :mail)");
|
||||
$inserted = $insert_user->execute([
|
||||
':id_warehouse' => $id_warehouse,
|
||||
':code' => $code,
|
||||
':username' => $username,
|
||||
':firstname' => $firstname,
|
||||
':lastname' => $lastname,
|
||||
':mail' => $mail
|
||||
$inserted = Table::get('user')->insert([
|
||||
'id_user' => Rows::DEFAULT,
|
||||
'id_warehouse' => $id_warehouse,
|
||||
'code' => $code,
|
||||
'username' => $username,
|
||||
'firstname' => $firstname,
|
||||
'lastname' => $lastname,
|
||||
'mail' => $mail
|
||||
]);
|
||||
|
||||
/* [3] On retourne l'id_user ou FALSE si erreur
|
||||
// Si erreur d'insertion, erreur
|
||||
if( !$inserted )
|
||||
return false; // Si pb d'unicité du code ou username (car sont uniques) ou autre
|
||||
|
||||
|
||||
/* [2] On récupère l'id_user
|
||||
=========================================================*/
|
||||
$check_user = self::getByCode($id_warehouse, $code);
|
||||
|
||||
// Si n'existe pas on retourne FALSE
|
||||
if( !$inserted || $check_user === false )
|
||||
// Si on trouve pas, erreur
|
||||
if( $check_user === false )
|
||||
return false;
|
||||
|
||||
// Sinon, on retourne son id
|
||||
|
@ -193,16 +187,12 @@
|
|||
public static function delete($id_warehouse, $id_user){
|
||||
/* [1] On redige/execute la requete
|
||||
=========================================================*/
|
||||
$delete_user = Database::getPDO()->prepare("DELETE FROM user
|
||||
WHERE id_user = :id_user
|
||||
AND id_warehouse = :id_warehouse");
|
||||
$delete_user->execute([
|
||||
':id_user' => $id_user,
|
||||
':id_warehouse' => $id_warehouse
|
||||
]);
|
||||
$delete = Table::get('user')
|
||||
->whereId($id_user)
|
||||
->whereIdWarehouse($id_warehouse);
|
||||
|
||||
// On retourne l'état
|
||||
return ( self::getById($id_warehouse, $id_user) === false );
|
||||
return $delete->delete();
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue