mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-21 17:06:28 +02:00
Update phone to use name instead of number and update sended to use phone id instead of origin
This commit is contained in:
parent
62c7f69395
commit
d5be760843
12 changed files with 91 additions and 93 deletions
|
@ -28,45 +28,45 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a phone by his number.
|
||||
* Return a phone by his name
|
||||
*
|
||||
* @param string $number : Phone number
|
||||
* @param string $name : Phone name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_by_number(string $number)
|
||||
public function get_by_name(string $name)
|
||||
{
|
||||
return $this->get_model()->get_by_number($number);
|
||||
return $this->get_model()->get_by_name($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a phone for a user by a number.
|
||||
* Return a phone for a user by a name
|
||||
*
|
||||
* @param int $id_user : user id
|
||||
* @param string $number : Phone number
|
||||
* @param string $name : Phone name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_by_number_and_user(int $id_user, string $number)
|
||||
public function get_by_name_and_user(int $id_user, string $name)
|
||||
{
|
||||
return $this->get_model()->get_by_number_and_user($id_user, $number);
|
||||
return $this->get_model()->get_by_name_and_user($id_user, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a phone.
|
||||
*
|
||||
* @param int $id_user : User to insert phone for
|
||||
* @param string $number : The number of the phone
|
||||
* @param string $name : The name of the phone
|
||||
* @param string $adapter : The adapter to use the phone
|
||||
* @param string json $adapter_datas : A JSON string representing adapter's datas (for example credentials for an api)
|
||||
*
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function create(int $id_user, string $number, string $adapter, string $adapter_datas): bool
|
||||
public function create(int $id_user, string $name, string $adapter, string $adapter_datas): bool
|
||||
{
|
||||
$phone = [
|
||||
'id_user' => $id_user,
|
||||
'number' => $number,
|
||||
'name' => $name,
|
||||
'adapter' => $adapter,
|
||||
'adapter_datas' => $adapter_datas,
|
||||
];
|
||||
|
@ -79,17 +79,17 @@ namespace controllers\internals;
|
|||
*
|
||||
* @param int $id_user : User to insert phone for
|
||||
* @param int $id : Phone id
|
||||
* @param string $number : The number of the phone
|
||||
* @param string $name : The name of the phone
|
||||
* @param string $adapter : The adapter to use the phone
|
||||
* @param array $adapter_datas : An array of the datas of the adapter (for example credentials for an api)
|
||||
*
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function update_for_user(int $id_user, int $id, string $number, string $adapter, array $adapter_datas): bool
|
||||
public function update_for_user(int $id_user, int $id, string $name, string $adapter, array $adapter_datas): bool
|
||||
{
|
||||
$phone = [
|
||||
'id_user' => $id_user,
|
||||
'number' => $number,
|
||||
'name' => $name,
|
||||
'adapter' => $adapter,
|
||||
'adapter_datas' => json_encode($adapter_datas),
|
||||
];
|
||||
|
|
|
@ -19,9 +19,9 @@ namespace controllers\internals;
|
|||
* Create a sended.
|
||||
*
|
||||
* @param int $id_user : Id of user to create sended message for
|
||||
* @param int $id_phone : Id of the number the message was send with
|
||||
* @param $at : Reception date
|
||||
* @param $text : Text of the message
|
||||
* @param string $origin : Number of the sender
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param string $uid : Uid of the sms on the adapter service used
|
||||
* @param string $adapter : Name of the adapter service used to send the message
|
||||
|
@ -30,10 +30,11 @@ namespace controllers\internals;
|
|||
*
|
||||
* @return bool : false on error, new sended id else
|
||||
*/
|
||||
public function create(int $id_user, $at, string $text, string $origin, string $destination, string $uid, string $adapter, bool $flash = false, ?string $status = 'unknown'): bool
|
||||
public function create(int $id_user, int $id_phone, $at, string $text, string $destination, string $uid, string $adapter, bool $flash = false, ?string $status = 'unknown'): bool
|
||||
{
|
||||
$sended = [
|
||||
'id_user' => $id_user,
|
||||
'id_phone' => $id_phone,
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
|
@ -47,38 +48,6 @@ namespace controllers\internals;
|
|||
return (bool) $this->get_model()->insert($sended);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a sended for a user.
|
||||
*
|
||||
* @param int $id_user : user id
|
||||
* @param int $id_sended : Sended id
|
||||
* @param $at : Reception date
|
||||
* @param $text : Text of the message
|
||||
* @param string $origin : Number of the sender
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param string $uid : Uid of the sms on the adapter service used
|
||||
* @param string $adapter : Name of the adapter service used to send the message
|
||||
* @param bool $flash : Is the sms a flash
|
||||
* @param ?string $status : Status of a the sms. By default null -> unknown
|
||||
*
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function update_for_user(int $id_user, int $id_sended, $at, string $text, string $origin, string $destination, string $uid, string $adapter, bool $flash = false, ?string $status = null): bool
|
||||
{
|
||||
$sended = [
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
'destination' => $destination,
|
||||
'uid' => $uid,
|
||||
'adapter' => $adapter,
|
||||
'flash' => $flash,
|
||||
'status' => $status,
|
||||
];
|
||||
|
||||
return (bool) $this->get_model()->update_for_user($id_user, $id_sended, $sended);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a sended status for a user.
|
||||
*
|
||||
|
|
|
@ -101,7 +101,7 @@ class Phone extends \descartes\Controller
|
|||
* Create a new phone.
|
||||
*
|
||||
* @param $csrf : CSRF token
|
||||
* @param string $_POST['number'] : Phone number
|
||||
* @param string $_POST['name'] : Phone name
|
||||
* @param string $_POST['adapter'] : Phone adapter
|
||||
* @param array $_POST['adapter_datas'] : Phone adapter datas
|
||||
*/
|
||||
|
@ -115,29 +115,21 @@ class Phone extends \descartes\Controller
|
|||
}
|
||||
|
||||
$id_user = $_SESSION['user']['id'];
|
||||
$number = $_POST['number'] ?? false;
|
||||
$name = $_POST['name'] ?? false;
|
||||
$adapter = $_POST['adapter'] ?? false;
|
||||
$adapter_datas = !empty($_POST['adapter_datas']) ? $_POST['adapter_datas'] : [];
|
||||
|
||||
if (!$number || !$adapter)
|
||||
if (!$name || !$adapter)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Des champs obligatoires sont manquants.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
$number = \controllers\internals\Tool::parse_phone($number);
|
||||
if (!$number)
|
||||
$name_exist = $this->internal_phone->get_by_name($name);
|
||||
if ($name_exist)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Numéro de téléphone incorrect.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
$number_exist = $this->internal_phone->get_by_number($number);
|
||||
if ($number_exist)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Ce numéro de téléphone est déjà utilisé.');
|
||||
\FlashMessage\FlashMessage::push('danger', 'Ce nom est déjà utilisé pour un autre téléphone.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
@ -181,9 +173,9 @@ class Phone extends \descartes\Controller
|
|||
|
||||
$adapter_datas = json_encode($adapter_datas);
|
||||
|
||||
//Check adapter is working correctly with thoses numbers and datas
|
||||
//Check adapter is working correctly with thoses names and datas
|
||||
$adapter_classname = $find_adapter['meta_classname'];
|
||||
$adapter_instance = new $adapter_classname($number, $adapter_datas);
|
||||
$adapter_instance = new $adapter_classname($name, $adapter_datas);
|
||||
$adapter_working = $adapter_instance->test();
|
||||
|
||||
if (!$adapter_working)
|
||||
|
@ -193,7 +185,7 @@ class Phone extends \descartes\Controller
|
|||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
$success = $this->internal_phone->create($id_user, $number, $adapter, $adapter_datas);
|
||||
$success = $this->internal_phone->create($id_user, $name, $adapter, $adapter_datas);
|
||||
if (!$success)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce téléphone.');
|
||||
|
|
|
@ -44,6 +44,23 @@ namespace controllers\publics;
|
|||
$page = (int) $page;
|
||||
$limit = 25;
|
||||
$sendeds = $this->internal_sended->list_for_user($_SESSION['user']['id'], $limit, $page);
|
||||
|
||||
foreach ($sendeds as &$sended)
|
||||
{
|
||||
if ($sended['id_phone'] === null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $sended['id_phone']);
|
||||
if (!$phone)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$sended['phone_name'] = $phone['name'];
|
||||
}
|
||||
|
||||
$this->render('sended/list', ['sendeds' => $sendeds, 'page' => $page, 'limit' => $limit, 'nb_results' => \count($sendeds)]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue