revert unwanted change to publics/User, fix errors phone & Settings

This commit is contained in:
osaajani 2019-11-14 23:09:56 +01:00
parent 6d9b1289fd
commit 18c7cb019d
7 changed files with 47 additions and 11 deletions

View File

@ -25,6 +25,18 @@ namespace controllers\internals;
return $this->model; return $this->model;
} }
/**
* Return a phone by his number
* @param string $number : Phone number
* @return array
*/
public function get_by_number(string $number)
{
return $this->get_model()->get_by_number($number);
}
/** /**
* Return a phone for a user by a number * Return a phone for a user by a number
* @param int $id_user : user id * @param int $id_user : user id
@ -33,7 +45,7 @@ namespace controllers\internals;
*/ */
public function get_by_number_and_user(int $id_user, string $number) public function get_by_number_and_user(int $id_user, string $number)
{ {
return $this->model_phone->get_by_number_and_user($id_user, $number); return $this->get_model()->get_by_number_and_user($id_user, $number);
} }
@ -54,7 +66,7 @@ namespace controllers\internals;
'adapter_datas' => $adapter_datas, 'adapter_datas' => $adapter_datas,
]; ];
return (bool) $this->model_phone->insert($phone); return (bool) $this->get_model()->insert($phone);
} }
@ -76,6 +88,6 @@ namespace controllers\internals;
'adapter_datas' => json_encode($adapter_datas), 'adapter_datas' => json_encode($adapter_datas),
]; ];
return (bool) $this->model_phone->update_for_user($id_user, $id, $phone); return (bool) $this->get_model()->update_for_user($id_user, $id, $phone);
} }
} }

View File

@ -54,7 +54,7 @@ namespace controllers\internals;
*/ */
public function update_for_user (int $id_user, string $name, $value) : bool public function update_for_user (int $id_user, string $name, $value) : bool
{ {
return (bool) $this->get_model()->update($id_user, $name, $value); return (bool) $this->get_model()->update_by_name_for_user($id_user, $name, $value);
} }

View File

@ -37,7 +37,7 @@ class Phone extends \descartes\Controller
{ {
$id_user = $_SESSION['user']['id']; $id_user = $_SESSION['user']['id'];
$page = (int) $page; $page = (int) $page;
$phones = $this->internal_phone->list_for_user($_SESSION['user']['id']$id_user, 25, $page); $phones = $this->internal_phone->list_for_user($id_user, 25, $page);
$adapters = []; $adapters = [];
$adapters_metas = $this->internal_adapter->list_adapters(); $adapters_metas = $this->internal_adapter->list_adapters();
@ -163,7 +163,7 @@ class Phone extends \descartes\Controller
} }
$success = $this->internal_phone->create($_SESSION['user']['id'], $id_user, $number, $adapter, $adapter_datas); $success = $this->internal_phone->create($id_user, $number, $adapter, $adapter_datas);
if (!$success) if (!$success)
{ {
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce téléphone.'); \FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce téléphone.');

View File

@ -60,7 +60,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Setting', 'show')); return $this->redirect(\descartes\Router::url('Setting', 'show'));
} }
$update_setting_result = $this->internal_setting->update_for_user($_SESSION['user']['id'], $_SESSION['user']['id'], $setting_name, $setting_value); $update_setting_result = $this->internal_setting->update_for_user($_SESSION['user']['id'], $setting_name, $setting_value);
if (false === $update_setting_result) if (false === $update_setting_result)
{ {
\FlashMessage\FlashMessage::push('danger', 'Impossible de mettre à jour ce réglage.'); \FlashMessage\FlashMessage::push('danger', 'Impossible de mettre à jour ce réglage.');

View File

@ -40,7 +40,7 @@ class User extends \descartes\Controller
public function list($page = 0) public function list($page = 0)
{ {
$page = (int) $page; $page = (int) $page;
$users = $this->internal_user->list_for_user($_SESSION['user']['id'], 25, $page); $users = $this->internal_user->list(25, $page);
$this->render('user/list', ['users' => $users]); $this->render('user/list', ['users' => $users]);
} }
@ -71,7 +71,7 @@ class User extends \descartes\Controller
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
foreach ($ids as $id) foreach ($ids as $id)
{ {
$this->internal_user->delete_for_user($_SESSION['user']['id'], $id); $this->internal_user->delete($id);
} }
return $this->redirect(\descartes\Router::url('User', 'list')); return $this->redirect(\descartes\Router::url('User', 'list'));
@ -122,7 +122,7 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'add')); return $this->redirect(\descartes\Router::url('User', 'add'));
} }
$user_id = $this->internal_user->create($_SESSION['user']['id'], $email, $password, $admin); $user_id = $this->internal_user->create($email, $password, $admin);
if (!$user_id) if (!$user_id)
{ {
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce user.'); \FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce user.');

View File

@ -30,4 +30,15 @@ namespace models;
{ {
return $this->_select_one('phone', ['number' => $number, 'id_user' => $id_user]); return $this->_select_one('phone', ['number' => $number, 'id_user' => $id_user]);
} }
/**
* Return a phone by his number
* @param string $number : phone number
* @return array
*/
public function get_by_number (string $number)
{
return $this->_select_one('phone', ['number' => $number]);
}
} }

View File

@ -18,4 +18,17 @@ namespace models;
* @return string * @return string
*/ */
protected function get_table_name() : string { return 'setting'; } protected function get_table_name() : string { return 'setting'; }
/**
* Update a setting for a user by his name
* @param int $id_user : user id
* @param string $name : setting name
* @param mixed $value : new value of the setting
* @return int : number of modified settings
*/
public function update_by_name_for_user(int $id_user, string $name, $value)
{
return $this->_update($this->get_table_name(), ['value' => $value], ['id_user' => $id_user, 'name' => $name]);
}
} }