fix style

This commit is contained in:
osaajani 2021-01-14 03:32:17 +01:00
parent cc233f726a
commit aac464704e
34 changed files with 147 additions and 107 deletions

View File

@ -355,6 +355,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
$status = \models\Sended::STATUS_DELIVERED; $status = \models\Sended::STATUS_DELIVERED;
break; break;
case 'NOT_ALLOWED': case 'NOT_ALLOWED':
case 'INVALID_DESTINATION_ADDRESS': case 'INVALID_DESTINATION_ADDRESS':
case 'OUT_OF_DATE': case 'OUT_OF_DATE':
@ -363,6 +364,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
$status = \models\Sended::STATUS_FAILED; $status = \models\Sended::STATUS_FAILED;
break; break;
default: default:
$status = \models\Sended::STATUS_UNKNOWN; $status = \models\Sended::STATUS_UNKNOWN;

View File

@ -355,6 +355,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
$status = \models\Sended::STATUS_DELIVERED; $status = \models\Sended::STATUS_DELIVERED;
break; break;
case 'NOT_ALLOWED': case 'NOT_ALLOWED':
case 'INVALID_DESTINATION_ADDRESS': case 'INVALID_DESTINATION_ADDRESS':
case 'OUT_OF_DATE': case 'OUT_OF_DATE':
@ -363,6 +364,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
$status = \models\Sended::STATUS_FAILED; $status = \models\Sended::STATUS_FAILED;
break; break;
default: default:
$status = \models\Sended::STATUS_UNKNOWN; $status = \models\Sended::STATUS_UNKNOWN;

View File

@ -347,11 +347,13 @@ namespace adapters;
$status = \models\Sended::STATUS_DELIVERED; $status = \models\Sended::STATUS_DELIVERED;
break; break;
case 2: case 2:
case 16: case 16:
$status = \models\Sended::STATUS_FAILED; $status = \models\Sended::STATUS_FAILED;
break; break;
default: default:
$status = \models\Sended::STATUS_UNKNOWN; $status = \models\Sended::STATUS_UNKNOWN;

View File

@ -346,11 +346,13 @@ namespace adapters;
$status = \models\Sended::STATUS_DELIVERED; $status = \models\Sended::STATUS_DELIVERED;
break; break;
case 2: case 2:
case 16: case 16:
$status = \models\Sended::STATUS_FAILED; $status = \models\Sended::STATUS_FAILED;
break; break;
default: default:
$status = \models\Sended::STATUS_UNKNOWN; $status = \models\Sended::STATUS_UNKNOWN;

View File

@ -257,10 +257,12 @@ namespace adapters;
$return['status'] = \models\Sended::STATUS_DELIVERED; $return['status'] = \models\Sended::STATUS_DELIVERED;
break; break;
case \models\Sended::STATUS_FAILED: case \models\Sended::STATUS_FAILED:
$return['status'] = \models\Sended::STATUS_FAILED; $return['status'] = \models\Sended::STATUS_FAILED;
break; break;
default: default:
$return['status'] = \models\Sended::STATUS_UNKNOWN; $return['status'] = \models\Sended::STATUS_UNKNOWN;

View File

@ -325,10 +325,12 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
$status = \models\Sended::STATUS_DELIVERED; $status = \models\Sended::STATUS_DELIVERED;
break; break;
case 'failed': case 'failed':
$status = \models\Sended::STATUS_FAILED; $status = \models\Sended::STATUS_FAILED;
break; break;
default: default:
$status = \models\Sended::STATUS_UNKNOWN; $status = \models\Sended::STATUS_UNKNOWN;

View File

@ -114,11 +114,11 @@ namespace controllers\internals;
{ {
$contact['datas'] = json_decode($contact['datas']); $contact['datas'] = json_decode($contact['datas']);
$contact = (object) $contact; $contact = (object) $contact;
//Add metas of contact by adding contact without datas //Add metas of contact by adding contact without datas
$metas = clone $contact; $metas = clone $contact;
unset($metas->datas); $metas->datas = null;
unset($metas->id_user); $metas->id_user = null;
$datas = ['contact' => $contact->datas, 'contact_metas' => $metas]; $datas = ['contact' => $contact->datas, 'contact_metas' => $metas];
$is_valid = $ruler->evaluate_condition($condition, $datas); $is_valid = $ruler->evaluate_condition($condition, $datas);

View File

@ -68,9 +68,10 @@ namespace controllers\internals;
} }
/** /**
* Check if a user exists based on email * Check if a user exists based on email.
*
* @param string $email : User email
* *
* @param string $email : User email
* @return exit code 1 on false, 0 else * @return exit code 1 on false, 0 else
*/ */
public function user_exists(string $email) public function user_exists(string $email)
@ -79,6 +80,7 @@ namespace controllers\internals;
$internal_user = new \controllers\internals\User($bdd); $internal_user = new \controllers\internals\User($bdd);
$user = $internal_user->get_by_email($email); $user = $internal_user->get_by_email($email);
exit($user ? 0 : 1); exit($user ? 0 : 1);
} }
@ -105,18 +107,20 @@ namespace controllers\internals;
$api_key = $api_key ?? $internal_user->generate_random_api_key(); $api_key = $api_key ?? $internal_user->generate_random_api_key();
$success = $internal_user->update($user['id'], $email, $password, $admin, $api_key, $status, $encrypt_password); $success = $internal_user->update($user['id'], $email, $password, $admin, $api_key, $status, $encrypt_password);
echo json_encode(['id' => $user['id']]); echo json_encode(['id' => $user['id']]);
exit($success ? 0 : 1); exit($success ? 0 : 1);
} }
$new_user_id = $internal_user->create($email, $password, $admin, $api_key, $status, $encrypt_password); $new_user_id = $internal_user->create($email, $password, $admin, $api_key, $status, $encrypt_password);
echo json_encode(['id' => $new_user_id]); echo json_encode(['id' => $new_user_id]);
exit($new_user_id ? 0 : 1); exit($new_user_id ? 0 : 1);
} }
/** /**
* Update a user status. * Update a user status.
* *
* @param string $id : User id * @param string $id : User id
* @param string $status : User status, default \models\User::STATUS_ACTIVE * @param string $status : User status, default \models\User::STATUS_ACTIVE
*/ */
public function update_user_status(string $id, string $status) public function update_user_status(string $id, string $status)
@ -131,14 +135,14 @@ namespace controllers\internals;
} }
$success = $internal_user->update_status($user['id'], $status); $success = $internal_user->update_status($user['id'], $status);
exit($success ? 0 : 1); exit($success ? 0 : 1);
} }
/** /**
* Delete a user * Delete a user.
* *
* @param string $id : User id * @param string $id : User id
*/ */
public function delete_user(string $id) public function delete_user(string $id)
{ {
@ -146,6 +150,7 @@ namespace controllers\internals;
$internal_user = new \controllers\internals\User($bdd); $internal_user = new \controllers\internals\User($bdd);
$success = $internal_user->delete($id); $success = $internal_user->delete($id);
exit($success ? 0 : 1); exit($success ? 0 : 1);
} }
} }

View File

@ -60,7 +60,7 @@ namespace controllers\internals;
* @param string $adapter : The adapter to use 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) * @param string json $adapter_datas : A JSON string representing adapter's datas (for example credentials for an api)
* *
* @return int|bool : false on error, new id on success * @return bool|int : false on error, new id on success
*/ */
public function create(int $id_user, string $name, string $adapter, string $adapter_datas) public function create(int $id_user, string $name, string $adapter, string $adapter_datas)
{ {

View File

@ -244,7 +244,7 @@ namespace controllers\internals;
if (!isset($users_phones[$scheduled['id_user']])) if (!isset($users_phones[$scheduled['id_user']]))
{ {
$phones = $internal_phone->gets_for_user($scheduled['id_user']); $phones = $internal_phone->gets_for_user($scheduled['id_user']);
$users_phones[$scheduled['id_user']] = $phones ? $phones : []; $users_phones[$scheduled['id_user']] = $phones ?: [];
} }
$phone_to_use = null; $phone_to_use = null;
@ -335,14 +335,12 @@ namespace controllers\internals;
if ((int) ($users_settings[$scheduled['id_user']]['templating'] ?? false)) if ((int) ($users_settings[$scheduled['id_user']]['templating'] ?? false))
{ {
$contact['datas'] = json_decode($contact['datas'], true); $contact['datas'] = json_decode($contact['datas'], true);
//Add metas of contact by adding contact without datas //Add metas of contact by adding contact without datas
$metas = $contact; $metas = $contact;
unset($metas['datas']); unset($metas['datas'], $metas['id_user']);
unset($metas['id_user']);
$datas = ['contact' => $contact['datas'], 'contact_metas' => $metas];
$datas = ['contact' => $contact['datas'], 'contact_metas' => $metas];
$render = $internal_templating->render($scheduled['text'], $datas); $render = $internal_templating->render($scheduled['text'], $datas);

View File

@ -97,26 +97,32 @@ namespace controllers\internals;
$logo = 'fa-user'; $logo = 'fa-user';
break; break;
case 'CONTACT_ADD': case 'CONTACT_ADD':
$logo = 'fa-user'; $logo = 'fa-user';
break; break;
case 'GROUP_ADD': case 'GROUP_ADD':
$logo = 'fa-group'; $logo = 'fa-group';
break; break;
case 'CONDITIONAL_GROUP_ADD': case 'CONDITIONAL_GROUP_ADD':
$logo = 'fa-bullseye'; $logo = 'fa-bullseye';
break; break;
case 'SCHEDULED_ADD': case 'SCHEDULED_ADD':
$logo = 'fa-calendar'; $logo = 'fa-calendar';
break; break;
case 'COMMAND_ADD': case 'COMMAND_ADD':
$logo = 'fa-terminal'; $logo = 'fa-terminal';
break; break;
default: default:
$logo = 'fa-question'; $logo = 'fa-question';
} }
@ -169,7 +175,8 @@ namespace controllers\internals;
if (!isset($_SESSION['connect']) || !$_SESSION['connect']) if (!isset($_SESSION['connect']) || !$_SESSION['connect'])
{ {
header('Location: /'); header('Location: /');
die();
exit();
} }
} }
@ -217,26 +224,32 @@ namespace controllers\internals;
$result['content'] = 'Impossible de télécharger le fichier car il dépasse les ' . ini_get('upload_max_filesize') / (1000 * 1000) . ' Mégaoctets.'; $result['content'] = 'Impossible de télécharger le fichier car il dépasse les ' . ini_get('upload_max_filesize') / (1000 * 1000) . ' Mégaoctets.';
break; break;
case UPLOAD_ERR_FORM_SIZE: case UPLOAD_ERR_FORM_SIZE:
$result['content'] = 'Le fichier dépasse la limite de taille.'; $result['content'] = 'Le fichier dépasse la limite de taille.';
break; break;
case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_PARTIAL:
$result['content'] = 'L\'envoi du fichier a été interrompu.'; $result['content'] = 'L\'envoi du fichier a été interrompu.';
break; break;
case UPLOAD_ERR_NO_FILE: case UPLOAD_ERR_NO_FILE:
$result['content'] = 'Aucun fichier n\'a été envoyé.'; $result['content'] = 'Aucun fichier n\'a été envoyé.';
break; break;
case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_NO_TMP_DIR:
$result['content'] = 'Le serveur ne dispose pas de fichier temporaire permettant l\'envoi de fichiers.'; $result['content'] = 'Le serveur ne dispose pas de fichier temporaire permettant l\'envoi de fichiers.';
break; break;
case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_CANT_WRITE:
$result['content'] = 'Impossible d\'envoyer le fichier car il n\'y a plus de place sur le serveur.'; $result['content'] = 'Impossible d\'envoyer le fichier car il n\'y a plus de place sur le serveur.';
break; break;
case UPLOAD_ERR_EXTENSION: case UPLOAD_ERR_EXTENSION:
$result['content'] = 'Le serveur a interrompu l\'envoi du fichier.'; $result['content'] = 'Le serveur a interrompu l\'envoi du fichier.';
@ -284,26 +297,32 @@ namespace controllers\internals;
$result['content'] = 'Impossible de télécharger le fichier car il dépasse les ' . ini_get('upload_max_filesize') / (1000 * 1000) . ' Mégaoctets.'; $result['content'] = 'Impossible de télécharger le fichier car il dépasse les ' . ini_get('upload_max_filesize') / (1000 * 1000) . ' Mégaoctets.';
break; break;
case UPLOAD_ERR_FORM_SIZE: case UPLOAD_ERR_FORM_SIZE:
$result['content'] = 'Le fichier dépasse la limite de taille.'; $result['content'] = 'Le fichier dépasse la limite de taille.';
break; break;
case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_PARTIAL:
$result['content'] = 'L\'envoi du fichier a été interrompu.'; $result['content'] = 'L\'envoi du fichier a été interrompu.';
break; break;
case UPLOAD_ERR_NO_FILE: case UPLOAD_ERR_NO_FILE:
$result['content'] = 'Aucun fichier n\'a été envoyé.'; $result['content'] = 'Aucun fichier n\'a été envoyé.';
break; break;
case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_NO_TMP_DIR:
$result['content'] = 'Le serveur ne dispose pas de fichier temporaire permettant l\'envoi de fichiers.'; $result['content'] = 'Le serveur ne dispose pas de fichier temporaire permettant l\'envoi de fichiers.';
break; break;
case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_CANT_WRITE:
$result['content'] = 'Impossible d\'envoyer le fichier car il n\'y a plus de place sur le serveur.'; $result['content'] = 'Impossible d\'envoyer le fichier car il n\'y a plus de place sur le serveur.';
break; break;
case UPLOAD_ERR_EXTENSION: case UPLOAD_ERR_EXTENSION:
$result['content'] = 'Le serveur a interrompu l\'envoi du fichier.'; $result['content'] = 'Le serveur a interrompu l\'envoi du fichier.';

View File

@ -307,18 +307,18 @@ namespace controllers\publics;
} }
/** /**
* Create a new phone * Create a new phone.
* *
* @param string $_POST['name'] : Phone name * @param string $_POST['name'] : Phone name
* @param string $_POST['adapter'] : Phone adapter * @param string $_POST['adapter'] : Phone adapter
* @param array $_POST['adapter_datas'] : Phone adapter datas * @param array $_POST['adapter_datas'] : Phone adapter datas
* *
* @return int : id phone the new phone on success * @return int : id phone the new phone on success
*/ */
public function post_phone() public function post_phone()
{ {
$return = self::DEFAULT_RETURN; $return = self::DEFAULT_RETURN;
$name = $_POST['name'] ?? false; $name = $_POST['name'] ?? false;
$adapter = $_POST['adapter'] ?? false; $adapter = $_POST['adapter'] ?? false;
$adapter_datas = !empty($_POST['adapter_datas']) ? $_POST['adapter_datas'] : []; $adapter_datas = !empty($_POST['adapter_datas']) ? $_POST['adapter_datas'] : [];
@ -331,7 +331,7 @@ namespace controllers\publics;
return $this->json($return); return $this->json($return);
} }
if (!$adapter) if (!$adapter)
{ {
$return['error'] = self::ERROR_CODES['MISSING_PARAMETER']; $return['error'] = self::ERROR_CODES['MISSING_PARAMETER'];
@ -409,7 +409,7 @@ namespace controllers\publics;
continue; continue;
} }
} }
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER']; $return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . ' field ' . $field['name'] . ' is not a valid phone number.'; $return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . ' field ' . $field['name'] . ' is not a valid phone number.';
$this->auto_http_code(false); $this->auto_http_code(false);
@ -434,7 +434,7 @@ namespace controllers\publics;
} }
$phone_id = $this->internal_phone->create($this->user['id'], $name, $adapter, $adapter_datas); $phone_id = $this->internal_phone->create($this->user['id'], $name, $adapter, $adapter_datas);
if ($phone_id === false) if (false === $phone_id)
{ {
$return['error'] = self::ERROR_CODES['CANNOT_CREATE']; $return['error'] = self::ERROR_CODES['CANNOT_CREATE'];
$return['message'] = self::ERROR_MESSAGES['CANNOT_CREATE']; $return['message'] = self::ERROR_MESSAGES['CANNOT_CREATE'];
@ -445,10 +445,10 @@ namespace controllers\publics;
$return['response'] = $phone_id; $return['response'] = $phone_id;
$this->auto_http_code(true); $this->auto_http_code(true);
return $this->json($return); return $this->json($return);
} }
/** /**
* Delete a phone. * Delete a phone.
* *

View File

@ -52,6 +52,7 @@ use Monolog\Logger;
http_response_code(401); http_response_code(401);
echo json_encode(['error' => 'Invalid API key. You must provide a valid GET or POST api_key param.']); echo json_encode(['error' => 'Invalid API key. You must provide a valid GET or POST api_key param.']);
$this->logger->error('Callback call failed with invalid api key : ' . $api_key); $this->logger->error('Callback call failed with invalid api key : ' . $api_key);
exit(1); exit(1);
} }

View File

@ -44,9 +44,9 @@ namespace controllers\publics;
{ {
$this->render('command/list'); $this->render('command/list');
} }
/** /**
* Return commands as json * Return commands as json.
*/ */
public function list_json() public function list_json()
{ {

View File

@ -48,9 +48,9 @@ namespace controllers\publics;
{ {
$this->render('conditional_group/list'); $this->render('conditional_group/list');
} }
/** /**
* Return conditionnals groups as json * Return conditionnals groups as json.
*/ */
public function list_json() public function list_json()
{ {

View File

@ -42,9 +42,9 @@ namespace controllers\publics;
{ {
return $this->render('contact/list'); return $this->render('contact/list');
} }
/** /**
* Return contacts as json * Return contacts as json.
*/ */
public function list_json() public function list_json()
{ {
@ -288,16 +288,19 @@ namespace controllers\publics;
//Try to import file //Try to import file
$invalid_type = false; $invalid_type = false;
switch ($read_file['mime_type']) switch ($read_file['mime_type'])
{ {
case 'text/csv': case 'text/csv':
$result = $this->internal_contact->import_csv($id_user, $read_file['content']); $result = $this->internal_contact->import_csv($id_user, $read_file['content']);
break; break;
case 'application/json': case 'application/json':
$result = $this->internal_contact->import_json($id_user, $read_file['content']); $result = $this->internal_contact->import_json($id_user, $read_file['content']);
break; break;
default: default:
$invalid_type = true; $invalid_type = true;
} }
@ -338,16 +341,19 @@ namespace controllers\publics;
//Try to export contacts //Try to export contacts
$invalid_type = false; $invalid_type = false;
switch ($format) switch ($format)
{ {
case 'csv': case 'csv':
$result = $this->internal_contact->export_csv($id_user); $result = $this->internal_contact->export_csv($id_user);
break; break;
case 'json': case 'json':
$result = $this->internal_contact->export_json($id_user); $result = $this->internal_contact->export_json($id_user);
break; break;
default: default:
$invalid_type = true; $invalid_type = true;
} }

View File

@ -48,9 +48,9 @@ namespace controllers\publics;
{ {
$this->render('discussion/list'); $this->render('discussion/list');
} }
/** /**
* Return discussions as json * Return discussions as json.
*/ */
public function list_json() public function list_json()
{ {

View File

@ -44,7 +44,7 @@ namespace controllers\publics;
} }
/** /**
* Return events as json * Return events as json.
*/ */
public function list_json() public function list_json()
{ {
@ -74,7 +74,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Event', 'list')); return $this->redirect(\descartes\Router::url('Event', 'list'));
} }
if (!\controllers\internals\Tool::is_admin()) if (!\controllers\internals\Tool::is_admin())
{ {
\FlashMessage\FlashMessage::push('danger', 'Vous devez être administrateur pour supprimer un event !'); \FlashMessage\FlashMessage::push('danger', 'Vous devez être administrateur pour supprimer un event !');

View File

@ -44,10 +44,9 @@ namespace controllers\publics;
{ {
$this->render('group/list'); $this->render('group/list');
} }
/** /**
* Return groups as json * Return groups as json.
*/ */
public function list_json() public function list_json()
{ {

View File

@ -73,7 +73,7 @@ class Phone extends \descartes\Controller
} }
/** /**
* Return phones as json with additionnals datas about callbacks * Return phones as json with additionnals datas about callbacks.
*/ */
public function list_json() public function list_json()
{ {

View File

@ -43,9 +43,9 @@ namespace controllers\publics;
{ {
$this->render('received/list', ['is_unread' => false]); $this->render('received/list', ['is_unread' => false]);
} }
/** /**
* Return received as json * Return received as json.
*/ */
public function list_json() public function list_json()
{ {
@ -66,9 +66,9 @@ namespace controllers\publics;
{ {
$this->render('received/list', ['is_unread' => true]); $this->render('received/list', ['is_unread' => true]);
} }
/** /**
* Return unred received as json * Return unred received as json.
*/ */
public function list_unread_json() public function list_unread_json()
{ {
@ -83,15 +83,15 @@ namespace controllers\publics;
} }
/** /**
* Mark messages as * Mark messages as.
* *
* @param string $status : New status of the message, read or unread * @param string $status : New status of the message, read or unread
* @param array int $_GET['ids'] : Ids of receiveds to delete * @param array int $_GET['ids'] : Ids of receiveds to delete
* @param mixed $csrf * @param mixed $csrf
* *
* @return boolean; * @return boolean;
*/ */
public function mark_as ($status, $csrf) public function mark_as($status, $csrf)
{ {
if (!$this->verify_csrf($csrf)) if (!$this->verify_csrf($csrf))
{ {
@ -99,15 +99,15 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Received', 'list')); return $this->redirect(\descartes\Router::url('Received', 'list'));
} }
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
foreach ($ids as $id) foreach ($ids as $id)
{ {
if ($status === \models\Received::STATUS_UNREAD) if (\models\Received::STATUS_UNREAD === $status)
{ {
$this->internal_received->mark_as_unread_for_user($_SESSION['user']['id'], $id); $this->internal_received->mark_as_unread_for_user($_SESSION['user']['id'], $id);
} }
elseif ($status === \models\Received::STATUS_READ) elseif (\models\Received::STATUS_READ === $status)
{ {
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $id); $this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $id);
} }

View File

@ -49,9 +49,9 @@ namespace controllers\publics;
{ {
$this->render('scheduled/list'); $this->render('scheduled/list');
} }
/** /**
* Return scheduleds as json * Return scheduleds as json.
*/ */
public function list_json() public function list_json()
{ {

View File

@ -46,7 +46,7 @@ namespace controllers\publics;
} }
/** /**
* Return sendeds as json * Return sendeds as json.
*/ */
public function list_json() public function list_json()
{ {
@ -59,7 +59,6 @@ namespace controllers\publics;
header('Content-Type: application/json'); header('Content-Type: application/json');
echo json_encode(['data' => $entities]); echo json_encode(['data' => $entities]);
} }
/** /**
* Cette fonction va supprimer une liste de sendeds. * Cette fonction va supprimer une liste de sendeds.

View File

@ -41,9 +41,9 @@ namespace controllers\publics;
{ {
$this->render('smsstop/list'); $this->render('smsstop/list');
} }
/** /**
* Return smsstops as json * Return smsstops as json.
*/ */
public function list_json() public function list_json()
{ {

View File

@ -70,8 +70,7 @@ namespace controllers\publics;
//Add metas of contact by adding contact without datas //Add metas of contact by adding contact without datas
$metas = $contact; $metas = $contact;
unset($metas['datas']); unset($metas['datas'], $metas['id_user']);
unset($metas['id_user']);
$datas = [ $datas = [
'contact' => $contact['datas'], 'contact' => $contact['datas'],

View File

@ -44,9 +44,9 @@ class User extends \descartes\Controller
{ {
$this->render('user/list'); $this->render('user/list');
} }
/** /**
* Return users as json * Return users as json.
*/ */
public function list_json() public function list_json()
{ {

View File

@ -38,9 +38,9 @@ namespace controllers\publics;
{ {
$this->render('webhook/list'); $this->render('webhook/list');
} }
/** /**
* Return commands as json * Return commands as json.
*/ */
public function list_json() public function list_json()
{ {

View File

@ -125,6 +125,7 @@ abstract class AbstractDaemon
if (-1 === $sid) if (-1 === $sid)
{ //Error { //Error
$this->logger->critical("Cannot make the child process with pid {$pid} independent."); $this->logger->critical("Cannot make the child process with pid {$pid} independent.");
exit(1); exit(1);
} }
@ -138,6 +139,7 @@ abstract class AbstractDaemon
if (!$success) if (!$success)
{ {
$this->logger->critical('Cannot create PID directory : ' . $this->pid_dir); $this->logger->critical('Cannot create PID directory : ' . $this->pid_dir);
exit(2); exit(2);
} }
} }

View File

@ -15,9 +15,9 @@ namespace models;
{ {
/** /**
* Return a list of groups for a user. * Return a list of groups for a user.
* Add a column nb_contacts * Add a column nb_contacts.
* *
* @param int $id_user : user id * @param int $id_user : user id
* @param ?int $limit : Number of entry to return or null * @param ?int $limit : Number of entry to return or null
* @param ?int $offset : Number of entry to ignore or null * @param ?int $offset : Number of entry to ignore or null
* *
@ -30,28 +30,29 @@ namespace models;
FROM `group` as g FROM `group` as g
LEFT JOIN group_contact as gc LEFT JOIN group_contact as gc
ON g.id = gc.id_group ON g.id = gc.id_group
WHERE id_user = :id_user WHERE id_user = :id_user
GROUP BY g.id GROUP BY g.id
'; ';
if ($limit !== null) if (null !== $limit)
{ {
$limit = (int) $limit; $limit = (int) $limit;
$query .= ' LIMIT ' . $limit; $query .= ' LIMIT ' . $limit;
if ($offset !== null) if (null !== $offset)
{ {
$offset = (int) $offset; $offset = (int) $offset;
$query .= ' OFFSET ' . $offset; $query .= ' OFFSET ' . $offset;
} }
} }
$params = [ $params = [
'id_user' => $id_user, 'id_user' => $id_user,
]; ];
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* Return a group by his name for a user. * Return a group by his name for a user.
* *
@ -102,7 +103,7 @@ namespace models;
public function get_contacts(int $id_group) public function get_contacts(int $id_group)
{ {
$query = ' $query = '
SELECT * SELECT *
FROM `contact` FROM `contact`
WHERE id IN (SELECT id_contact FROM `group_contact` WHERE id_group = :id_group) WHERE id IN (SELECT id_contact FROM `group_contact` WHERE id_group = :id_group)
'; ';

View File

@ -26,7 +26,7 @@ namespace models;
*/ */
public function get_for_user(int $id_user, int $id) public function get_for_user(int $id_user, int $id)
{ {
$query = ' $query = '
SELECT * FROM `' . $this->get_table_name() . '` SELECT * FROM `' . $this->get_table_name() . '`
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user) WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
AND id = :id AND id = :id
@ -51,7 +51,7 @@ namespace models;
*/ */
public function gets_for_user(int $id_user) public function gets_for_user(int $id_user)
{ {
$query = ' $query = '
SELECT * FROM `' . $this->get_table_name() . '` SELECT * FROM `' . $this->get_table_name() . '`
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user) WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
'; ';
@ -73,7 +73,7 @@ namespace models;
*/ */
public function get_for_scheduled_and_user(int $id_user, int $id_scheduled) public function get_for_scheduled_and_user(int $id_user, int $id_scheduled)
{ {
$query = ' $query = '
SELECT * FROM `' . $this->get_table_name() . '` SELECT * FROM `' . $this->get_table_name() . '`
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user) WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
AND id_scheduled = :id_scheduled AND id_scheduled = :id_scheduled
@ -105,7 +105,7 @@ namespace models;
$limit = (int) $limit; $limit = (int) $limit;
$offset = (int) $offset; $offset = (int) $offset;
$query = ' $query = '
SELECT * FROM media SELECT * FROM media
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user) WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
LIMIT ' . $limit . ' OFFSET ' . $offset; LIMIT ' . $limit . ' OFFSET ' . $offset;
@ -127,7 +127,7 @@ namespace models;
*/ */
public function gets_in_for_user(int $id_user, $ids) public function gets_in_for_user(int $id_user, $ids)
{ {
$query = ' $query = '
SELECT * FROM media SELECT * FROM media
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user) WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
AND id '; AND id ';
@ -151,7 +151,7 @@ namespace models;
*/ */
public function delete_for_user(int $id_user, int $id) public function delete_for_user(int $id_user, int $id)
{ {
$query = ' $query = '
DELETE FROM media DELETE FROM media
WHERE id = :id WHERE id = :id
AND id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user) AND id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
@ -172,7 +172,7 @@ namespace models;
*/ */
public function delete_for_scheduled_and_user(int $id_user, int $id_scheduled) public function delete_for_scheduled_and_user(int $id_user, int $id_scheduled)
{ {
$query = ' $query = '
DELETE FROM media DELETE FROM media
WHERE id_scheduled = :id_scheduled WHERE id_scheduled = :id_scheduled
AND id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user) AND id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)

View File

@ -18,12 +18,12 @@ namespace models;
{ {
const STATUS_UNREAD = 'unread'; const STATUS_UNREAD = 'unread';
const STATUS_READ = 'read'; const STATUS_READ = 'read';
/** /**
* Return a list of received messages for a user. * Return a list of received messages for a user.
* Add a column contact_name and phone_name when available * Add a column contact_name and phone_name when available.
* *
* @param int $id_user : user id * @param int $id_user : user id
* @param ?int $limit : Number of entry to return or null * @param ?int $limit : Number of entry to return or null
* @param ?int $offset : Number of entry to ignore or null * @param ?int $offset : Number of entry to ignore or null
* *
@ -42,31 +42,30 @@ namespace models;
WHERE received.id_user = :id_user WHERE received.id_user = :id_user
'; ';
if ($limit !== null) if (null !== $limit)
{ {
$limit = (int) $limit; $limit = (int) $limit;
$query .= ' LIMIT ' . $limit; $query .= ' LIMIT ' . $limit;
if ($offset !== null) if (null !== $offset)
{ {
$offset = (int) $offset; $offset = (int) $offset;
$query .= ' OFFSET ' . $offset; $query .= ' OFFSET ' . $offset;
} }
} }
$params = [ $params = [
'id_user' => $id_user, 'id_user' => $id_user,
]; ];
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* Return a list of unread received messages for a user. * Return a list of unread received messages for a user.
* Add a column contact_name and phone_name when available * Add a column contact_name and phone_name when available.
* *
* @param int $id_user : user id * @param int $id_user : user id
* @param ?int $limit : Number of entry to return or null * @param ?int $limit : Number of entry to return or null
* @param ?int $offset : Number of entry to ignore or null * @param ?int $offset : Number of entry to ignore or null
* *
@ -86,18 +85,18 @@ namespace models;
AND status = :status AND status = :status
'; ';
if ($limit !== null) if (null !== $limit)
{ {
$limit = (int) $limit; $limit = (int) $limit;
$query .= ' LIMIT ' . $limit; $query .= ' LIMIT ' . $limit;
if ($offset !== null) if (null !== $offset)
{ {
$offset = (int) $offset; $offset = (int) $offset;
$query .= ' OFFSET ' . $offset; $query .= ' OFFSET ' . $offset;
} }
} }
$params = [ $params = [
'id_user' => $id_user, 'id_user' => $id_user,
'status' => self::STATUS_UNREAD, 'status' => self::STATUS_UNREAD,
@ -190,7 +189,7 @@ namespace models;
*/ */
public function count_by_day_since_for_user(int $id_user, $date) public function count_by_day_since_for_user(int $id_user, $date)
{ {
$query = " $query = "
SELECT COUNT(id) as nb, DATE_FORMAT(at, '%Y-%m-%d') as at_ymd SELECT COUNT(id) as nb, DATE_FORMAT(at, '%Y-%m-%d') as at_ymd
FROM received FROM received
WHERE at > :date WHERE at > :date
@ -215,7 +214,7 @@ namespace models;
*/ */
public function get_discussions_for_user(int $id_user) public function get_discussions_for_user(int $id_user)
{ {
$query = ' $query = '
SELECT discussions.at, discussions.number, contact.name as contact_name SELECT discussions.at, discussions.number, contact.name as contact_name
FROM ( FROM (
SELECT at, destination as number FROM sended SELECT at, destination as number FROM sended
@ -246,7 +245,7 @@ namespace models;
*/ */
public function get_since_by_date_for_user(int $id_user, $date) public function get_since_by_date_for_user(int $id_user, $date)
{ {
$query = " $query = "
SELECT * SELECT *
FROM received FROM received
WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s') WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s')
@ -272,7 +271,7 @@ namespace models;
*/ */
public function get_since_by_date_for_origin_and_user(int $id_user, $date, string $origin) public function get_since_by_date_for_origin_and_user(int $id_user, $date, string $origin)
{ {
$query = " $query = "
SELECT * SELECT *
FROM received FROM received
WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s') WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s')

View File

@ -19,12 +19,12 @@ namespace models;
const STATUS_UNKNOWN = 'unknown'; const STATUS_UNKNOWN = 'unknown';
const STATUS_DELIVERED = 'delivered'; const STATUS_DELIVERED = 'delivered';
const STATUS_FAILED = 'failed'; const STATUS_FAILED = 'failed';
/** /**
* Return a list of sended messages for a user. * Return a list of sended messages for a user.
* Add a column contact_name and phone_name when available * Add a column contact_name and phone_name when available.
* *
* @param int $id_user : user id * @param int $id_user : user id
* @param ?int $limit : Number of entry to return or null * @param ?int $limit : Number of entry to return or null
* @param ?int $offset : Number of entry to ignore or null * @param ?int $offset : Number of entry to ignore or null
* *
@ -43,18 +43,18 @@ namespace models;
WHERE sended.id_user = :id_user WHERE sended.id_user = :id_user
'; ';
if ($limit !== null) if (null !== $limit)
{ {
$limit = (int) $limit; $limit = (int) $limit;
$query .= ' LIMIT ' . $limit; $query .= ' LIMIT ' . $limit;
if ($offset !== null) if (null !== $offset)
{ {
$offset = (int) $offset; $offset = (int) $offset;
$query .= ' OFFSET ' . $offset; $query .= ' OFFSET ' . $offset;
} }
} }
$params = [ $params = [
'id_user' => $id_user, 'id_user' => $id_user,
]; ];
@ -137,7 +137,7 @@ namespace models;
*/ */
public function count_by_day_since_for_user($id_user, $date) public function count_by_day_since_for_user($id_user, $date)
{ {
$query = " $query = "
SELECT COUNT(id) as nb, DATE_FORMAT(at, '%Y-%m-%d') as at_ymd SELECT COUNT(id) as nb, DATE_FORMAT(at, '%Y-%m-%d') as at_ymd
FROM sended FROM sended
WHERE at > :date WHERE at > :date
@ -163,7 +163,7 @@ namespace models;
*/ */
public function get_since_by_date_for_user($date, $id_user) public function get_since_by_date_for_user($date, $id_user)
{ {
$query = " $query = "
SELECT * SELECT *
FROM sended FROM sended
WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s') WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s')

View File

@ -93,9 +93,9 @@ namespace models;
return []; return [];
} }
$query = ' $query = '
SELECT * FROM `' . $this->get_table_name() . '` SELECT * FROM `' . $this->get_table_name() . '`
WHERE id_user = :id_user WHERE id_user = :id_user
AND id '; AND id ';
$params = []; $params = [];

View File

@ -67,7 +67,7 @@ namespace models;
} }
/** /**
* Delete a user * Delete a user.
* *
* @param int $id : Id de l'utilisateur a supprimer * @param int $id : Id de l'utilisateur a supprimer
* *