mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-22 01:16:26 +02:00
start add support for phone status + improve edit of phone for hidden phones
This commit is contained in:
parent
f9e64aee65
commit
38d350dfc2
19 changed files with 357 additions and 6 deletions
|
@ -236,6 +236,19 @@ namespace controllers\internals;
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a phone status.
|
||||
*
|
||||
* @param int $id : Phone id
|
||||
* @param string $status : The new status of the phone
|
||||
*
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function update_status(int $id, string $status) : bool
|
||||
{
|
||||
return (bool) $this->get_model()->update($id, ['status' => $status]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model for the Controller.
|
||||
*/
|
||||
|
|
|
@ -710,7 +710,7 @@ namespace controllers\publics;
|
|||
$priority = $_POST['priority'] ?? $phone['priority'];
|
||||
$priority = max(((int) $priority), 0);
|
||||
$adapter = $_POST['adapter'] ?? $phone['adapter'];
|
||||
$adapter_data = !empty($_POST['adapter_data']) ? $_POST['adapter_data'] : json_decode($phone['adapter_data']);
|
||||
$adapter_data = !empty($_POST['adapter_data']) ? $_POST['adapter_data'] : json_decode($phone['adapter_data'], true);
|
||||
$adapter_data = is_array($adapter_data) ? $adapter_data : [$adapter_data];
|
||||
$limits = $_POST['limits'] ?? $limits;
|
||||
$limits = is_array($limits) ? $limits : [$limits];
|
||||
|
@ -890,4 +890,44 @@ namespace controllers\publics;
|
|||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger re-checking of a phone status
|
||||
*
|
||||
* @param int $id : Id of phone to re-check status
|
||||
*/
|
||||
public function post_update_phone_status ($id)
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
|
||||
$phone = $this->internal_phone->get_for_user($this->user['id'], $id);
|
||||
if (!$phone)
|
||||
{
|
||||
$return['error'] = self::ERROR_CODES['CANNOT_UPDATE'];
|
||||
$return['message'] = self::ERROR_MESSAGES['CANNOT_UPDATE'];
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
//Check adapter is working correctly with thoses names and data
|
||||
$adapter_classname = $phone['adapter'];
|
||||
if (!call_user_func([$adapter_classname, 'meta_support_phone_status']))
|
||||
{
|
||||
$return['error'] = self::ERROR_CODES['CANNOT_UPDATE'];
|
||||
$return['message'] = self::ERROR_MESSAGES['CANNOT_UPDATE'];
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
$adapter_instance = new $adapter_classname($phone['adapter_data']);
|
||||
$new_status = $adapter_instance->check_phone_status();
|
||||
|
||||
$status_update = $this->internal_phone->update_status($id, $new_status);
|
||||
$return['response'] = $new_status;
|
||||
$this->auto_http_code(true);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,6 +88,11 @@ class Phone extends \descartes\Controller
|
|||
{
|
||||
$phone['callback_end_call'] = \descartes\Router::url('Callback', 'end_call', ['id_phone' => $phone['id']], ['api_key' => $api_key]);
|
||||
}
|
||||
|
||||
if ($adapter['meta_support_phone_status'])
|
||||
{
|
||||
$phone['support_phone_status'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
@ -425,7 +430,14 @@ class Phone extends \descartes\Controller
|
|||
continue;
|
||||
}
|
||||
|
||||
if ($find_adapter['meta_hidden'])
|
||||
$current_phone = $this->internal_phone->get_for_user($id_user, $id_phone);
|
||||
if (!$current_phone)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// We can only use an hidden adapter if it was already the adapter we was using
|
||||
if ($find_adapter['meta_hidden'] && $adapter != $current_phone['adapter'])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -499,4 +511,44 @@ class Phone extends \descartes\Controller
|
|||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'list'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Re-check phone status
|
||||
* @param array int $_GET['ids'] : ids of phones we want to update status
|
||||
* @param $csrf : CSRF token
|
||||
*/
|
||||
public function update_status ($csrf)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
$ids = $_GET['ids'] ?? [];
|
||||
$id_user = $_SESSION['user']['id'];
|
||||
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
$phone = $this->internal_phone->get_for_user($id_user, $id);
|
||||
|
||||
//Check adapter is working correctly with thoses names and data
|
||||
$adapter_classname = $phone['adapter'];
|
||||
if (!call_user_func([$adapter_classname, 'meta_support_phone_status']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$adapter_instance = new $adapter_classname($phone['adapter_data']);
|
||||
$new_status = $adapter_instance->check_phone_status();
|
||||
|
||||
$status_update = $this->internal_phone->update_status($id, $new_status);
|
||||
}
|
||||
|
||||
\FlashMessage\FlashMessage::push('success', 'Les status des téléphones ont bien été mis à jour.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'list'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue