Add default settings generation on new user creation
This commit is contained in:
parent
2671c464a4
commit
d8839a57d0
|
@ -75,4 +75,22 @@ namespace controllers\internals;
|
|||
|
||||
return (bool) $this->get_model()->insert($setting);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate and insert default settings for a user
|
||||
* @param int $id_user : user id
|
||||
* @return bool
|
||||
*/
|
||||
public function create_defaults_for_user(int $id_user)
|
||||
{
|
||||
$all_success = true;
|
||||
foreach (USER_DEFAULT_SETTINGS as $name => $value)
|
||||
{
|
||||
$success = $this->create($id_user, $name, $value);
|
||||
$all_success = ($all_success && $success);
|
||||
}
|
||||
|
||||
return $all_success;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace controllers\internals;
|
|||
{
|
||||
$this->model_user = new \models\User($bdd);
|
||||
$this->internal_event = new \controllers\internals\Event($bdd);
|
||||
$this->internal_setting = new \controllers\internals\Setting($bdd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,13 +180,21 @@ namespace controllers\internals;
|
|||
'transfer' => $transfer,
|
||||
];
|
||||
|
||||
$result = $this->model_user->insert($user);
|
||||
$new_user_id = $this->model_user->insert($user);
|
||||
|
||||
if (!$result)
|
||||
if (!$new_user_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
$success = $this->internal_setting->create_defaults_for_user($new_user_id);
|
||||
|
||||
if (!$success)
|
||||
{
|
||||
$this->delete($new_user_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $new_user_id;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue