- [x] [machineDefaut][machineRepo] Gestion des parametres optionnels pour la modification
This commit is contained in:
parent
11991afd0c
commit
a61998717f
|
@ -267,34 +267,50 @@
|
|||
*
|
||||
*/
|
||||
public static function edit($id_machine=null, $code=null, $name=null){
|
||||
/* [1] Normalisation + verification des donnees
|
||||
=========================================================*/
|
||||
$correct_param = Database::check('auto_increment_id', $id_machine);
|
||||
$correct_param = $correct_param && Database::check('machine.code', $code);
|
||||
$correct_param = $correct_param && Database::check('machine.name', $name);
|
||||
|
||||
// Si les parametres ne sont pas corrects, on retourne une erreur
|
||||
if( !$correct_param )
|
||||
return array('ModuleError' => ManagerError::ParamError);
|
||||
|
||||
|
||||
/* [2] On verifie l'existence de la machine
|
||||
=========================================================*/
|
||||
$machine_exists = new Repo('machine/getById', array($id_machine));
|
||||
$machine_exists = $machine_exists->answer();
|
||||
|
||||
// Si on a recupere aucun utilisateur, on retourne une erreur
|
||||
if( !is_array($machine_exists) )
|
||||
// Si @id_machine n'est pas au bon format, on retourne une erreur
|
||||
if( !Database::check('auto_increment_id', $id_machine) )
|
||||
return array('ModuleError' => ManagerError::ModuleError);
|
||||
|
||||
|
||||
/* [1] On verifie l'existence de la machine
|
||||
=========================================================*/
|
||||
$machine_exists = new Repo('machine/getById', array($id_machine));
|
||||
$machine_data = $machine_exists->answer();
|
||||
|
||||
// Si on a recupere aucune machine, on retourne une erreur
|
||||
if( !is_array($machine_data) )
|
||||
return array('ModuleError' => ManagerError::ModuleError);
|
||||
|
||||
|
||||
|
||||
|
||||
/* [2] Normalisation + verification des donnees
|
||||
=========================================================*/
|
||||
|
||||
/* (1) Verification des parametres (si correct et different)*/
|
||||
$correct_param = array(
|
||||
'code' => Database::check('machine.code', $code ) && $machine_data['code'] != $code,
|
||||
'name' => Database::check('machine.name', $name ) && $machine_data['name'] != $name
|
||||
);
|
||||
|
||||
/* (2) Gestion des parametres optionnels */
|
||||
$opt_data = array(
|
||||
'code' => ($correct_param['code']) ? $code : $machine_data['code'],
|
||||
'name' => ($correct_param['name']) ? $name : $machine_data['name']
|
||||
);
|
||||
|
||||
|
||||
/* [3] Modification de la machine
|
||||
=========================================================*/
|
||||
$request = new Repo('machine/edit', array($id_machine, $code, $name));
|
||||
$answer = $request->answer();
|
||||
$request = new Repo('machine/edit', array(
|
||||
$id_machine,
|
||||
$opt_data['code'],
|
||||
$opt_data['name']
|
||||
));
|
||||
|
||||
|
||||
return array(
|
||||
'status' => $answer
|
||||
'status' => $request->answer()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@
|
|||
/* [1] On verifie l'existence de l'utilisateur
|
||||
=========================================================*/
|
||||
$user_exists = new Repo('user/getById', array($id_user));
|
||||
$user_data = $user_data->answer();
|
||||
$user_data = $user_exists->answer();
|
||||
|
||||
// Si on a recupere aucun utilisateur, on retourne une erreur
|
||||
if( !is_array($user_data) )
|
||||
|
@ -337,19 +337,19 @@
|
|||
'firstname' => Database::check('user.firstname', $firstname ) && $user_data['firstname'] != $firstname,
|
||||
'lastname' => Database::check('user.lastname', $lastname ) && $user_data['lastname'] != $lastname,
|
||||
'mail' => Database::check('user.mail', $mail ) && $user_data['mail'] != $mail,
|
||||
'password' => Database::check('user.password', $password_hash ) && $user_data['password'] != $password,
|
||||
'password' => Database::check('user.password', $password_hash ) && $user_data['password'] != $password_hash,
|
||||
'status' => Database::check('user.status', $status ) && $user_data['status'] != $status
|
||||
);
|
||||
|
||||
/* (2) Gestion des parametres optionnels */
|
||||
$opt_data = array(
|
||||
'code' => ($correct_param['code']) ? $code : $user_data['code'],
|
||||
'username' => ($correct_param['username']) ? $username : $user_data['username'],
|
||||
'code' => ($correct_param['code']) ? $code : $user_data['code'],
|
||||
'username' => ($correct_param['username']) ? $username : $user_data['username'],
|
||||
'firstname' => ($correct_param['firstname']) ? $firstname : $user_data['firstname'],
|
||||
'lastname' => ($correct_param['lastname']) ? $lastname : $user_data['lastname'],
|
||||
'mail' => ($correct_param['mail']) ? $mail : $user_data['mail'],
|
||||
'password' => ($correct_param['password']) ? $password : $user_data['password'],
|
||||
'status' => ($correct_param['status']) ? $status : $user_data['status'],
|
||||
'lastname' => ($correct_param['lastname']) ? $lastname : $user_data['lastname'],
|
||||
'mail' => ($correct_param['mail']) ? $mail : $user_data['mail'],
|
||||
'password' => ($correct_param['password']) ? $password : $user_data['password'],
|
||||
'status' => ($correct_param['status']) ? $status : $user_data['status'],
|
||||
);
|
||||
|
||||
|
||||
|
@ -364,14 +364,13 @@
|
|||
$opt_data['firstname'],
|
||||
$opt_data['lastname'],
|
||||
$opt_data['mail'],
|
||||
$opt_data['password_hash'],
|
||||
$opt_data['password'],
|
||||
$opt_data['status'])
|
||||
);
|
||||
|
||||
$answer = $request->answer();
|
||||
|
||||
return array(
|
||||
'status' => $answer
|
||||
'status' => $request->answer()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -251,7 +251,7 @@
|
|||
* @return status<Boolean> Renvoie si oui ou non tout s'est bien passe
|
||||
*
|
||||
*/
|
||||
public static function edit($id_machine, $code, $name){
|
||||
public static function edit($id_machine=null, $code=null, $name=null){
|
||||
/* [1] Verification de l'unicite de code+name (si differents)
|
||||
=========================================================*/
|
||||
// On recupere les machine ayant le meme code ou name (si existent)
|
||||
|
|
2
todo.md
2
todo.md
|
@ -7,7 +7,6 @@
|
|||
############
|
||||
# EN COURS #
|
||||
############
|
||||
- [ ] [machineDefaut][machineRepo] Gestion des parametres optionnels pour la modification
|
||||
|
||||
|
||||
- [ ] [view/js/machines] Recherche instantanee
|
||||
|
@ -18,6 +17,7 @@
|
|||
########
|
||||
# FAIT #
|
||||
########
|
||||
- [x] [machineDefaut][machineRepo] Gestion des parametres optionnels pour la modification
|
||||
- [x] [userDefault][userRepo] Gestion des parametres optionnels pour la modification
|
||||
- [x] [machines.js][machineDefault][machineRepo] Gestion de la nouvelle modification (avec recherche)
|
||||
- [x] [machineDefault] Implementer la modification
|
||||
|
|
|
@ -360,6 +360,7 @@ if( section.edit.element != null ){
|
|||
};
|
||||
|
||||
api.send(request, function(answer){
|
||||
console.log( answer );
|
||||
if( answer.ModuleError == 0 && answer.status == true ) // Tout s'est bien deroule
|
||||
console.log('Utilisateur modifie!');
|
||||
else // Erreur
|
||||
|
|
Loading…
Reference in New Issue