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){
|
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));
|
$inserted = Table::get('user')->insert([
|
||||||
$check_unique = $check_unique && !is_array(self::getByUsername($id_warehouse, $username));
|
'id_user' => Rows::DEFAULT,
|
||||||
|
'id_warehouse' => $id_warehouse,
|
||||||
// Si un utilisateur a deja ce code ou cet username, on renvoie une erreur
|
'code' => $code,
|
||||||
if( !$check_unique )
|
'username' => $username,
|
||||||
return false;
|
'firstname' => $firstname,
|
||||||
|
'lastname' => $lastname,
|
||||||
|
'mail' => $mail
|
||||||
/* [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
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/* [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);
|
$check_user = self::getByCode($id_warehouse, $code);
|
||||||
|
|
||||||
// Si n'existe pas on retourne FALSE
|
// Si on trouve pas, erreur
|
||||||
if( !$inserted || $check_user === false )
|
if( $check_user === false )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Sinon, on retourne son id
|
// Sinon, on retourne son id
|
||||||
|
@ -193,16 +187,12 @@
|
||||||
public static function delete($id_warehouse, $id_user){
|
public static function delete($id_warehouse, $id_user){
|
||||||
/* [1] On redige/execute la requete
|
/* [1] On redige/execute la requete
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$delete_user = Database::getPDO()->prepare("DELETE FROM user
|
$delete = Table::get('user')
|
||||||
WHERE id_user = :id_user
|
->whereId($id_user)
|
||||||
AND id_warehouse = :id_warehouse");
|
->whereIdWarehouse($id_warehouse);
|
||||||
$delete_user->execute([
|
|
||||||
':id_user' => $id_user,
|
|
||||||
':id_warehouse' => $id_warehouse
|
|
||||||
]);
|
|
||||||
|
|
||||||
// On retourne l'état
|
// On retourne l'état
|
||||||
return ( self::getById($id_warehouse, $id_user) === false );
|
return $delete->delete();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue