add page for calls

This commit is contained in:
osaajani 2021-03-24 00:22:17 +01:00
parent 41c3b3b86e
commit c63f3bebba
9 changed files with 323 additions and 45 deletions

View file

@ -0,0 +1,93 @@
<?php
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace controllers\publics;
/**
* Page des calls.
*/
class Call extends \descartes\Controller
{
private $internal_call;
/**
* Cette fonction est appelée avant toute les autres :
* Elle vérifie que l'utilisateur est bien connecté.
*
* @return void;
*/
public function __construct()
{
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
$this->internal_call = new \controllers\internals\Call($bdd);
\controllers\internals\Tool::verifyconnect();
}
/**
* Page for showing calls list
*/
public function list()
{
$this->render('call/list');
}
/**
* Return calls list as json.
*/
public function list_json()
{
$entities = $this->internal_call->list_for_user($_SESSION['user']['id']);
foreach ($entities as &$entity)
{
switch ($entity['direction'])
{
case \models\Call::DIRECTION_INBOUND :
$entity['origin_formatted'] = \controllers\internals\Tool::phone_link($entity['origin']);
break;
case \models\Call::DIRECTION_OUTBOUND :
$entity['destination_formatted'] = \controllers\internals\Tool::phone_link($entity['destination']);
break;
}
}
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**
* Delete a list of calls
*
* @param array int $_GET['ids'] : Ids of calls to delete
* @param string $csrf : csrf token
*
* @return boolean;
*/
public function delete(string $csrf)
{
if (!$this->verify_csrf($csrf))
{
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Call', 'list'));
}
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
$this->internal_call->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('Call', 'list'));
}
}

View file

@ -33,43 +33,7 @@ class Phone extends \descartes\Controller
*/
public function list()
{
$id_user = $_SESSION['user']['id'];
$api_key = $_SESSION['user']['api_key'];
$phones = $this->internal_phone->list_for_user($id_user);
$adapters = [];
$adapters = $this->internal_adapter->list_adapters();
foreach ($adapters as $key => $adapter)
{
unset($adapters[$key]);
$adapters[$adapter['meta_classname']] = $adapter;
}
foreach ($phones as &$phone)
{
$adapter = $adapters[$phone['adapter']] ?? false;
if (!$adapter)
{
$phone['adapter'] = 'Inconnu';
continue;
}
$phone['adapter'] = $adapter['meta_name'];
if ($adapter['meta_support_reception'])
{
$phone['callback_reception'] = \descartes\Router::url('Callback', 'reception', ['adapter_uid' => $adapter['meta_uid'], 'id_phone' => $phone['id']], ['api_key' => $api_key]);
}
if ($adapter['meta_support_status_change'])
{
$phone['callback_status'] = \descartes\Router::url('Callback', 'update_sended_status', ['adapter_uid' => $adapter['meta_uid']], ['api_key' => $api_key]);
}
}
$this->render('phone/list', ['phones' => $phones]);
$this->render('phone/list');
}
/**
@ -111,6 +75,16 @@ class Phone extends \descartes\Controller
{
$phone['callback_status'] = \descartes\Router::url('Callback', 'update_sended_status', ['adapter_uid' => $adapter['meta_uid']], ['api_key' => $api_key]);
}
if ($adapter['meta_support_inbound_call_callback'])
{
$phone['callback_inbound_call'] = \descartes\Router::url('Callback', 'inbound_call', ['id_phone' => $phone['id']], ['api_key' => $api_key]);
}
if ($adapter['meta_support_end_call_callback'])
{
$phone['callback_end_call'] = \descartes\Router::url('Callback', 'end_call', ['id_phone' => $phone['id']], ['api_key' => $api_key]);
}
}
header('Content-Type: application/json');