style validation fix

This commit is contained in:
osaajani 2021-06-17 00:51:33 +02:00
parent f1d47a25ed
commit 017c7fee53
42 changed files with 526 additions and 497 deletions

View File

@ -84,22 +84,22 @@ interface AdapterInterface
public static function meta_support_status_change(): bool; public static function meta_support_status_change(): bool;
/** /**
* Does the implemented service support mms reception * Does the implemented service support mms reception.
*/ */
public static function meta_support_mms_reception(): bool; public static function meta_support_mms_reception(): bool;
/** /**
* Does the implemented service support mms sending * Does the implemented service support mms sending.
*/ */
public static function meta_support_mms_sending(): bool; public static function meta_support_mms_sending(): bool;
/** /**
* Does the implemented service support inbound call callback * Does the implemented service support inbound call callback.
*/ */
public static function meta_support_inbound_call_callback(): bool; public static function meta_support_inbound_call_callback(): bool;
/** /**
* Does the implemented service support end call callback * Does the implemented service support end call callback.
*/ */
public static function meta_support_end_call_callback(): bool; public static function meta_support_end_call_callback(): bool;
@ -118,23 +118,23 @@ interface AdapterInterface
* array 'uid' => Uid of the sms created on success * array 'uid' => Uid of the sms created on success
* ] * ]
*/ */
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array; public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array;
/** /**
* Method called to read SMSs of the number. * Method called to read SMSs of the number.
* *
* @return array : [ * @return array : [
* bool 'error' => false if no error, true else * bool 'error' => false if no error, true else
* ?string 'error_message' => null if no error, else error message * ?string 'error_message' => null if no error, else error message
* array 'smss' => Array of the sms reads [[ * array 'smss' => Array of the sms reads [[
* (optional) bool 'mms' => default to false, true if mms * (optional) bool 'mms' => default to false, true if mms
* (optional) array 'medias' => default to [], list of array representing medias to link to sms, with [ * (optional) array 'medias' => default to [], list of array representing medias to link to sms, with [
* 'filepath' => local file copy of the media, * 'filepath' => local file copy of the media,
* 'extension' (optional) => extension of the media, * 'extension' (optional) => extension of the media,
* 'mimetype' (optional) => mimetype of the media * 'mimetype' (optional) => mimetype of the media
* ] * ]
* ], ...] * ], ...]
* ] * ]
*/ */
public function read(): array; public function read(): array;
@ -157,50 +157,49 @@ interface AdapterInterface
* Method called on reception of a sms notification. * Method called on reception of a sms notification.
* *
* @return array : [ * @return array : [
* bool 'error' => false on success, true on error * bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else * ?string 'error_message' => null on success, error message else
* array 'sms' => array [ * array 'sms' => array [
* string 'at' : Recepetion date format Y-m-d H:i:s, * string 'at' : Recepetion date format Y-m-d H:i:s,
* string 'text' : SMS body, * string 'text' : SMS body,
* string 'origin' : SMS sender, * string 'origin' : SMS sender,
* (optional) array 'medias' => default to [], list of array representing medias to link to sms, with [ * (optional) array 'medias' => default to [], list of array representing medias to link to sms, with [
* 'filepath' => local file copy of the media, * 'filepath' => local file copy of the media,
* 'extension' (optional) => extension of the media, * 'extension' (optional) => extension of the media,
* 'mimetype' (optional) => mimetype of the media * 'mimetype' (optional) => mimetype of the media
* ] * ]
* ] * ]
* ] * ]
*/ */
public static function reception_callback(): array; public static function reception_callback(): array;
/** /**
* Method called on reception of an inbound_call notification * Method called on reception of an inbound_call notification.
* *
* @return array : [ * @return array : [
* bool 'error' => false on success, true on error * bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else * ?string 'error_message' => null on success, error message else
* array 'call' => array [ * array 'call' => array [
* string 'uid' : Uid of the call on the adapter plateform * string 'uid' : Uid of the call on the adapter plateform
* string 'start' : Start of the call date format Y-m-d H:i:s, * string 'start' : Start of the call date format Y-m-d H:i:s,
* ?string 'end' : End of the call date format Y-m-d H:i:s. If no known end, NULL * ?string 'end' : End of the call date format Y-m-d H:i:s. If no known end, NULL
* string 'origin' : Emitter phone call number. International format. * string 'origin' : Emitter phone call number. International format.
* ] * ]
* ] * ]
*/ */
public function inbound_call_callback(): array; public function inbound_call_callback(): array;
/** /**
* Method called on reception of a end call notification * Method called on reception of a end call notification.
* *
* @return array : [ * @return array : [
* bool 'error' => false on success, true on error * bool 'error' => false on success, true on error
* ?string 'error_message' => null on success, error message else * ?string 'error_message' => null on success, error message else
* array 'call' => array [ * array 'call' => array [
* string 'uid' : Uid of the call on the adapter plateform. Used to find the raspisms local call to update. * string 'uid' : Uid of the call on the adapter plateform. Used to find the raspisms local call to update.
* string 'end' : End of the call date format Y-m-d H:i:s. * string 'end' : End of the call date format Y-m-d H:i:s.
* ] * ]
* ] * ]
*/ */
public function end_call_callback(): array; public function end_call_callback(): array;
} }

View File

@ -127,7 +127,7 @@ namespace adapters;
} }
/** /**
* Does the implemented service support mms reception * Does the implemented service support mms reception.
*/ */
public static function meta_support_mms_reception(): bool public static function meta_support_mms_reception(): bool
{ {
@ -135,7 +135,7 @@ namespace adapters;
} }
/** /**
* Does the implemented service support mms sending * Does the implemented service support mms sending.
*/ */
public static function meta_support_mms_sending(): bool public static function meta_support_mms_sending(): bool
{ {
@ -152,7 +152,7 @@ namespace adapters;
return false; return false;
} }
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{ {
$response = [ $response = [
'error' => false, 'error' => false,

View File

@ -137,7 +137,7 @@ namespace adapters;
} }
/** /**
* Does the implemented service support mms reception * Does the implemented service support mms reception.
*/ */
public static function meta_support_mms_reception(): bool public static function meta_support_mms_reception(): bool
{ {
@ -145,7 +145,7 @@ namespace adapters;
} }
/** /**
* Does the implemented service support mms sending * Does the implemented service support mms sending.
*/ */
public static function meta_support_mms_sending(): bool public static function meta_support_mms_sending(): bool
{ {
@ -162,7 +162,7 @@ namespace adapters;
return false; return false;
} }
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{ {
$response = [ $response = [
'error' => false, 'error' => false,

View File

@ -174,7 +174,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
} }
/** /**
* Does the implemented service support mms reception * Does the implemented service support mms reception.
*/ */
public static function meta_support_mms_reception(): bool public static function meta_support_mms_reception(): bool
{ {
@ -182,7 +182,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
} }
/** /**
* Does the implemented service support mms sending * Does the implemented service support mms sending.
*/ */
public static function meta_support_mms_sending(): bool public static function meta_support_mms_sending(): bool
{ {
@ -199,7 +199,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
return false; return false;
} }
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{ {
$response = [ $response = [
'error' => false, 'error' => false,

View File

@ -179,7 +179,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
} }
/** /**
* Does the implemented service support mms reception * Does the implemented service support mms reception.
*/ */
public static function meta_support_mms_reception(): bool public static function meta_support_mms_reception(): bool
{ {
@ -187,7 +187,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
} }
/** /**
* Does the implemented service support mms sending * Does the implemented service support mms sending.
*/ */
public static function meta_support_mms_sending(): bool public static function meta_support_mms_sending(): bool
{ {
@ -204,7 +204,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
return false; return false;
} }
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{ {
$response = [ $response = [
'error' => false, 'error' => false,

View File

@ -171,7 +171,7 @@ namespace adapters;
} }
/** /**
* Does the implemented service support mms reception * Does the implemented service support mms reception.
*/ */
public static function meta_support_mms_reception(): bool public static function meta_support_mms_reception(): bool
{ {
@ -179,7 +179,7 @@ namespace adapters;
} }
/** /**
* Does the implemented service support mms sending * Does the implemented service support mms sending.
*/ */
public static function meta_support_mms_sending(): bool public static function meta_support_mms_sending(): bool
{ {
@ -196,7 +196,7 @@ namespace adapters;
return false; return false;
} }
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{ {
$response = [ $response = [
'error' => false, 'error' => false,

View File

@ -182,7 +182,7 @@ namespace adapters;
} }
/** /**
* Does the implemented service support mms reception * Does the implemented service support mms reception.
*/ */
public static function meta_support_mms_reception(): bool public static function meta_support_mms_reception(): bool
{ {
@ -190,7 +190,7 @@ namespace adapters;
} }
/** /**
* Does the implemented service support mms sending * Does the implemented service support mms sending.
*/ */
public static function meta_support_mms_sending(): bool public static function meta_support_mms_sending(): bool
{ {
@ -207,7 +207,7 @@ namespace adapters;
return false; return false;
} }
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{ {
$response = [ $response = [
'error' => false, 'error' => false,

View File

@ -132,7 +132,7 @@ namespace adapters;
} }
/** /**
* Does the implemented service support mms reception * Does the implemented service support mms reception.
*/ */
public static function meta_support_mms_reception(): bool public static function meta_support_mms_reception(): bool
{ {
@ -140,7 +140,7 @@ namespace adapters;
} }
/** /**
* Does the implemented service support mms sending * Does the implemented service support mms sending.
*/ */
public static function meta_support_mms_sending(): bool public static function meta_support_mms_sending(): bool
{ {
@ -157,7 +157,7 @@ namespace adapters;
return true; return true;
} }
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{ {
$response = [ $response = [
'error' => false, 'error' => false,
@ -194,7 +194,7 @@ namespace adapters;
* "mms" : true, * "mms" : true,
* "origin" : "+33612345678", * "origin" : "+33612345678",
* "text" : "SMS Text" * "text" : "SMS Text"
* } * }.
*/ */
public function read(): array public function read(): array
{ {

View File

@ -176,7 +176,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
} }
/** /**
* Does the implemented service support mms reception * Does the implemented service support mms reception.
*/ */
public static function meta_support_mms_reception(): bool public static function meta_support_mms_reception(): bool
{ {
@ -184,7 +184,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
} }
/** /**
* Does the implemented service support mms sending * Does the implemented service support mms sending.
*/ */
public static function meta_support_mms_sending(): bool public static function meta_support_mms_sending(): bool
{ {
@ -201,7 +201,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
return false; return false;
} }
public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []) : array public function send(string $destination, string $text, bool $flash = false, bool $mms = false, array $medias = []): array
{ {
$response = [ $response = [
'error' => false, 'error' => false,

View File

@ -118,7 +118,7 @@ namespace controllers\internals;
} }
/** /**
* List all adapters for a meta value * List all adapters for a meta value.
* *
* @param $search_name : Name of the meta * @param $search_name : Name of the meta
* @param $search_value : Value of the meta * @param $search_value : Value of the meta
@ -128,7 +128,9 @@ namespace controllers\internals;
public function list_adapters_with_meta_equal($search_name, $search_value) public function list_adapters_with_meta_equal($search_name, $search_value)
{ {
$adapters = $this->list_adapters(); $adapters = $this->list_adapters();
return array_filter($adapters, function($metas) use ($search_name, $search_value) {
return array_filter($adapters, function ($metas) use ($search_name, $search_value)
{
$match = false; $match = false;
foreach ($metas as $name => $value) foreach ($metas as $name => $value)
{ {

View File

@ -18,11 +18,11 @@ namespace controllers\internals;
/** /**
* Create a call. * Create a call.
* *
* @param int $id_user : Id of the user * @param int $id_user : Id of the user
* @param int $id_phone : Id of the phone that emitted (outbound) or received (inbound) the call * @param int $id_phone : Id of the phone that emitted (outbound) or received (inbound) the call
* @param string $uid : Uid of the phone call * @param string $uid : Uid of the phone call
* @param string $direction : Direction of the call, \models\Call::DIRECTION_INBOUND | \models\Call::DIRECTION_OUTBOUND * @param string $direction : Direction of the call, \models\Call::DIRECTION_INBOUND | \models\Call::DIRECTION_OUTBOUND
* @param string $start : Date of the call beginning * @param string $start : Date of the call beginning
* @param ?string $end : Date of the call end * @param ?string $end : Date of the call end
* @param ?string $origin : Origin of the call or null if outbound * @param ?string $origin : Origin of the call or null if outbound
* @param ?string $destination : Destination of the call or null if inbound * @param ?string $destination : Destination of the call or null if inbound
@ -49,15 +49,23 @@ namespace controllers\internals;
switch ($direction) switch ($direction)
{ {
case \models\Call::DIRECTION_OUTBOUND : case \models\Call::DIRECTION_OUTBOUND:
if (null === $destination) { return false; } if (null === $destination)
{
return false;
}
break; break;
case \models\Call::DIRECTION_INBOUND : case \models\Call::DIRECTION_INBOUND:
if (null === $origin) { return false; } if (null === $origin)
{
return false;
}
break; break;
default : default:
return false; return false;
} }
@ -90,14 +98,13 @@ namespace controllers\internals;
return $new_call_id; return $new_call_id;
} }
/** /**
* End a call * End a call.
* *
* @param int $id_user : Id of the user to end call for * @param int $id_user : Id of the user to end call for
* @param int $id_phone : If of the phone to end call for * @param int $id_phone : If of the phone to end call for
* @param string $uid : Uid of the call to end * @param string $uid : Uid of the call to end
* @param string $end : End date of the call, format Y-m-d H:i:s * @param string $end : End date of the call, format Y-m-d H:i:s
* *
* @return bool : False if cannot end phone call, true else * @return bool : False if cannot end phone call, true else
*/ */

View File

@ -109,7 +109,6 @@ namespace controllers\internals;
'admin' => $admin, 'admin' => $admin,
'api_key' => $api_key, 'api_key' => $api_key,
'status' => $status, 'status' => $status,
]; ];
$success = $internal_user->update($user['id'], $user); $success = $internal_user->update($user['id'], $user);
@ -161,9 +160,8 @@ namespace controllers\internals;
exit($success ? 0 : 1); exit($success ? 0 : 1);
} }
/** /**
* Delete medias that are no longer usefull * Delete medias that are no longer usefull.
*/ */
public function clean_unused_medias() public function clean_unused_medias()
{ {
@ -176,12 +174,12 @@ namespace controllers\internals;
{ {
$success = $internal_media->delete_for_user($media['id_user'], $media['id']); $success = $internal_media->delete_for_user($media['id_user'], $media['id']);
echo ($success === false ? '[KO]' : '[OK]') . ' - ' . $media['path'] . "\n"; echo (false === $success ? '[KO]' : '[OK]') . ' - ' . $media['path'] . "\n";
} }
} }
/** /**
* Do alerting for quota limits * Do alerting for quota limits.
*/ */
public function quota_limit_alerting() public function quota_limit_alerting()
{ {
@ -191,7 +189,7 @@ namespace controllers\internals;
} }
/** /**
* Do quota renewal * Do quota renewal.
*/ */
public function renew_quotas() public function renew_quotas()
{ {

View File

@ -57,18 +57,18 @@ namespace controllers\internals;
} }
/** /**
* Gets events for a type, since a date and eventually until a date (both included) * Gets events for a type, since a date and eventually until a date (both included).
* *
* @param int $id_user : User id * @param int $id_user : User id
* @param string $type : Event type we want * @param string $type : Event type we want
* @param \DateTime $since : Date to get events since * @param \DateTime $since : Date to get events since
* @param ?\DateTime $until (optional) : Date until wich we want events, if not specified no limit * @param ?\DateTime $until (optional) : Date until wich we want events, if not specified no limit
* *
* @return array * @return array
*/ */
public function get_events_by_type_and_date_for_user (int $id_user, string $type, \DateTime $since, ?\DateTime $until = null) public function get_events_by_type_and_date_for_user(int $id_user, string $type, \DateTime $since, ?\DateTime $until = null)
{ {
$this->get_model()->get_events_by_type_and_date_for_user ($id_user, $type, $since, $until); $this->get_model()->get_events_by_type_and_date_for_user($id_user, $type, $since, $until);
} }
/** /**

View File

@ -20,8 +20,8 @@ class Media extends StandardController
/** /**
* Create a media. * Create a media.
* *
* @param int $id_user : Id of the user * @param int $id_user : Id of the user
* @param string $tmpfile_path : Path of the temporary local copy of the media * @param string $tmpfile_path : Path of the temporary local copy of the media
* @param ?string $extension : Extension to use for the media * @param ?string $extension : Extension to use for the media
* *
* @return int : Exception on error, new media id else * @return int : Exception on error, new media id else
@ -39,7 +39,7 @@ class Media extends StandardController
throw new \Exception('File ' . $tmpfile_path . ' is not readable.'); throw new \Exception('File ' . $tmpfile_path . ' is not readable.');
} }
$mimey = new \Mimey\MimeTypes; $mimey = new \Mimey\MimeTypes();
$extension = $extension ?? $mimey->getExtension(mime_content_type($tmpfile_path)); $extension = $extension ?? $mimey->getExtension(mime_content_type($tmpfile_path));
$new_file_name = \controllers\internals\Tool::random_uuid() . '.' . $extension; $new_file_name = \controllers\internals\Tool::random_uuid() . '.' . $extension;
@ -86,16 +86,17 @@ class Media extends StandardController
} }
/** /**
* Upload and create a media * Upload and create a media.
*
* @param int $id_user : Id of the user
* @param array $file : array representing uploaded file, extracted from $_FILES['yourfile']
* *
* @param int $id_user : Id of the user
* @param array $file : array representing uploaded file, extracted from $_FILES['yourfile']
* @return int : Raise exception on error or return new media id on success * @return int : Raise exception on error or return new media id on success
*/ */
public function create_from_uploaded_file_for_user(int $id_user, array $file) public function create_from_uploaded_file_for_user(int $id_user, array $file)
{ {
$upload_result = \controllers\internals\Tool::read_uploaded_file($file); $upload_result = \controllers\internals\Tool::read_uploaded_file($file);
if ($upload_result['success'] !== true) if (true !== $upload_result['success'])
{ {
throw new \Exception($upload_result['content']); throw new \Exception($upload_result['content']);
} }
@ -115,10 +116,11 @@ class Media extends StandardController
} }
/** /**
* Link a media to a scheduled, a received or a sended message * Link a media to a scheduled, a received or a sended message.
* @param int $id_media : Id of the media *
* @param int $id_media : Id of the media
* @param string $resource_type : Type of resource to link the media to ('scheduled', 'received' or 'sended') * @param string $resource_type : Type of resource to link the media to ('scheduled', 'received' or 'sended')
* @param int $resource_id : Id of the resource to link the media to * @param int $resource_id : Id of the resource to link the media to
* *
* @return mixed bool|int : false on error, the new link id else * @return mixed bool|int : false on error, the new link id else
*/ */
@ -128,14 +130,17 @@ class Media extends StandardController
{ {
case 'scheduled': case 'scheduled':
return $this->get_model()->insert_media_scheduled($id_media, $resource_id); return $this->get_model()->insert_media_scheduled($id_media, $resource_id);
break; break;
case 'received': case 'received':
return $this->get_model()->insert_media_received($id_media, $resource_id); return $this->get_model()->insert_media_received($id_media, $resource_id);
break; break;
case 'sended': case 'sended':
return $this->get_model()->insert_media_sended($id_media, $resource_id); return $this->get_model()->insert_media_sended($id_media, $resource_id);
break; break;
default: default:
@ -143,12 +148,12 @@ class Media extends StandardController
} }
} }
/** /**
* Unlink a media of a scheduled, a received or a sended message * Unlink a media of a scheduled, a received or a sended message.
* @param int $id_media : Id of the media *
* @param int $id_media : Id of the media
* @param string $resource_type : Type of resource to unlink the media of ('scheduled', 'received' or 'sended') * @param string $resource_type : Type of resource to unlink the media of ('scheduled', 'received' or 'sended')
* @param int $resource_id : Id of the resource to unlink the media of * @param int $resource_id : Id of the resource to unlink the media of
* *
* @return mixed bool : false on error, true on success * @return mixed bool : false on error, true on success
*/ */
@ -158,14 +163,17 @@ class Media extends StandardController
{ {
case 'scheduled': case 'scheduled':
return $this->get_model()->delete_media_scheduled($id_media, $resource_id); return $this->get_model()->delete_media_scheduled($id_media, $resource_id);
break; break;
case 'received': case 'received':
return $this->get_model()->delete_media_received($id_media, $resource_id); return $this->get_model()->delete_media_received($id_media, $resource_id);
break; break;
case 'sended': case 'sended':
return $this->get_model()->delete_media_sended($id_media, $resource_id); return $this->get_model()->delete_media_sended($id_media, $resource_id);
break; break;
default: default:
@ -174,9 +182,10 @@ class Media extends StandardController
} }
/** /**
* Unlink all medias of a scheduled, a received or a sended message * Unlink all medias of a scheduled, a received or a sended message.
*
* @param string $resource_type : Type of resource to unlink the media of ('scheduled', 'received' or 'sended') * @param string $resource_type : Type of resource to unlink the media of ('scheduled', 'received' or 'sended')
* @param int $resource_id : Id of the resource to unlink the media of * @param int $resource_id : Id of the resource to unlink the media of
* *
* @return mixed bool : false on error, true on success * @return mixed bool : false on error, true on success
*/ */
@ -186,14 +195,17 @@ class Media extends StandardController
{ {
case 'scheduled': case 'scheduled':
return $this->get_model()->delete_all_for_scheduled($resource_id); return $this->get_model()->delete_all_for_scheduled($resource_id);
break; break;
case 'received': case 'received':
return $this->get_model()->delete_all_for_received($resource_id); return $this->get_model()->delete_all_for_received($resource_id);
break; break;
case 'sended': case 'sended':
return $this->get_model()->delete_all_for_sended($resource_id); return $this->get_model()->delete_all_for_sended($resource_id);
break; break;
default: default:
@ -204,9 +216,9 @@ class Media extends StandardController
/** /**
* Update a media for a user. * Update a media for a user.
* *
* @param int $id_user : user id * @param int $id_user : user id
* @param int $id_media : Media id * @param int $id_media : Media id
* @param string $path : Path of the file * @param string $path : Path of the file
* *
* @return bool : false on error, true on success * @return bool : false on error, true on success
*/ */
@ -289,7 +301,8 @@ class Media extends StandardController
} }
/** /**
* Find medias that are not used * Find medias that are not used.
*
* @return array * @return array
*/ */
public function gets_unused() public function gets_unused()

View File

@ -44,13 +44,14 @@ namespace controllers\internals;
} }
/** /**
* Check if a phone support mms * Check if a phone support mms.
* *
* @param int $id : id of the phone to check * @param int $id : id of the phone to check
* @param $type : type of sms support, a const from Phone, MMS_SENDING, MMS_RECEPTION or MMS_BOTH * @param $type : type of sms support, a const from Phone, MMS_SENDING, MMS_RECEPTION or MMS_BOTH
*
* @return bool : true if support, false else * @return bool : true if support, false else
*/ */
public function support_mms (int $id, string $type) public function support_mms(int $id, string $type)
{ {
$phone = $this->get_model()->get($id); $phone = $this->get_model()->get($id);
if (!$phone) if (!$phone)
@ -60,16 +61,19 @@ namespace controllers\internals;
switch ($type) switch ($type)
{ {
case self::MMS_SENDING : case self::MMS_SENDING:
return $phone['adapter']::meta_support_mms_sending(); return $phone['adapter']::meta_support_mms_sending();
break; break;
case self::MMS_RECEPTION : case self::MMS_RECEPTION:
return $phone['adapter']::meta_support_mms_reception(); return $phone['adapter']::meta_support_mms_reception();
break; break;
case self::MMS_BOTH : case self::MMS_BOTH:
return $phone['adapter']::meta_support_mms_sending() && $phone['adapter']::meta_support_mms_reception(); return $phone['adapter']::meta_support_mms_sending() && $phone['adapter']::meta_support_mms_reception();
break; break;
default: default:
@ -78,13 +82,14 @@ namespace controllers\internals;
} }
/** /**
* Get all phones supporting mms for a user * Get all phones supporting mms for a user.
* *
* @param int $id_user : id of the user * @param int $id_user : id of the user
* @param $type : type of sms support, a const from Phone, MMS_SENDING, MMS_RECEPTION or MMS_BOTH * @param $type : type of sms support, a const from Phone, MMS_SENDING, MMS_RECEPTION or MMS_BOTH
*
* @return array : array of phones supporting mms * @return array : array of phones supporting mms
*/ */
public function gets_phone_supporting_mms_for_user (int $id_user, string $type) public function gets_phone_supporting_mms_for_user(int $id_user, string $type)
{ {
$phones = $this->get_model()->gets_for_user($id_user); $phones = $this->get_model()->gets_for_user($id_user);

View File

@ -18,15 +18,15 @@ class Quota extends StandardController
/** /**
* Create a new quota. * Create a new quota.
* *
* @param int $id_user : User id * @param int $id_user : User id
* @param int $credit : Credit for this quota * @param int $credit : Credit for this quota
* @param int $additional : Additionals credits * @param int $additional : Additionals credits
* @param bool $report_unused : Should unused credits be re-credited * @param bool $report_unused : Should unused credits be re-credited
* @param bool $report_unused_additional : Should unused additional credits be re-credited * @param bool $report_unused_additional : Should unused additional credits be re-credited
* @param bool $auto_renew : Should the quota be automatically renewed after expiration_date * @param bool $auto_renew : Should the quota be automatically renewed after expiration_date
* @param string $renew_interval : Period to use for setting new expiration_date on renewal (format ISO_8601#Durations) * @param string $renew_interval : Period to use for setting new expiration_date on renewal (format ISO_8601#Durations)
* @param \DateTime $start_date : Starting date for the quota * @param \DateTime $start_date : Starting date for the quota
* @param \DateTime $expiration_date : Ending date for the quota * @param \DateTime $expiration_date : Ending date for the quota
* *
* @return mixed bool|int : False if cannot create quota, id of the new quota else * @return mixed bool|int : False if cannot create quota, id of the new quota else
*/ */
@ -50,10 +50,9 @@ class Quota extends StandardController
/** /**
* Update a quota. * Update a quota.
* *
* * @param int $id_user : User id
* @param int $id_user : User id * @param int $id_quota : Quota to update id
* @param int $id_quota : Quota to update id * @param array $quota : Fields to update whith new values
* @param array $quota : Fields to update whith new values
* *
* @return int : number of updated lines * @return int : number of updated lines
*/ */
@ -63,24 +62,29 @@ class Quota extends StandardController
} }
/** /**
* Check if we have enough credit * Check if we have enough credit.
*
* @param int $id_user : User id * @param int $id_user : User id
* @param int $needed : Number of credits we need * @param int $needed : Number of credits we need
*
* @return bool : true if we have enough credit, false else * @return bool : true if we have enough credit, false else
*/ */
public function has_enough_credit(int $id_user, int $needed) public function has_enough_credit(int $id_user, int $needed)
{ {
$remaining_credit = $this->get_model()->get_remaining_credit($id_user, new \DateTime()); $remaining_credit = $this->get_model()->get_remaining_credit($id_user, new \DateTime());
return $remaining_credit >= $needed; return $remaining_credit >= $needed;
} }
/** /**
* Consume some credit * Consume some credit.
* @param int $id_user : User id *
* @param int $id_user : User id
* @param int $quantity : Number of credits to consume * @param int $quantity : Number of credits to consume
*
* @return bool : True on success, false else * @return bool : True on success, false else
*/ */
public function consume_credit (int $id_user, int $quantity) public function consume_credit(int $id_user, int $quantity)
{ {
$result = $this->get_model()->consume_credit($id_user, $quantity); $result = $this->get_model()->consume_credit($id_user, $quantity);
@ -92,62 +96,65 @@ class Quota extends StandardController
} }
/** /**
* Get quota usage percentage * Get quota usage percentage.
*
* @param int $id_user : User id * @param int $id_user : User id
*
* @return float : percentage of quota used * @return float : percentage of quota used
*/ */
public function get_usage_percentage (int $id_user) public function get_usage_percentage(int $id_user)
{ {
return $this->get_model()->get_usage_percentage($id_user, new \DateTime()); return $this->get_model()->get_usage_percentage($id_user, new \DateTime());
} }
/** /**
* Compute how many credit a message represent * Compute how many credit a message represent
* this function count 160 chars per SMS if it can be send as GSM 03.38 encoding and 70 chars per SMS if it can only be send as UTF8 * this function count 160 chars per SMS if it can be send as GSM 03.38 encoding and 70 chars per SMS if it can only be send as UTF8.
*
* @param string $text : Message to send * @param string $text : Message to send
*
* @return int : Number of credit to send this message * @return int : Number of credit to send this message
*/ */
public static function compute_credits_for_message ($text) public static function compute_credits_for_message($text)
{ {
//Gsm 03.38 charset to detect if message is compatible or must use utf8 //Gsm 03.38 charset to detect if message is compatible or must use utf8
$gsm0338 = array( $gsm0338 = [
'@','Δ',' ','0','¡','P','¿','p', '@', 'Δ', ' ', '0', '¡', 'P', '¿', 'p',
'£','_','!','1','A','Q','a','q', '£', '_', '!', '1', 'A', 'Q', 'a', 'q',
'$','Φ','"','2','B','R','b','r', '$', 'Φ', '"', '2', 'B', 'R', 'b', 'r',
'¥','Γ','#','3','C','S','c','s', '¥', 'Γ', '#', '3', 'C', 'S', 'c', 's',
'è','Λ','¤','4','D','T','d','t', 'è', 'Λ', '¤', '4', 'D', 'T', 'd', 't',
'é','Ω','%','5','E','U','e','u', 'é', 'Ω', '%', '5', 'E', 'U', 'e', 'u',
'ù','Π','&','6','F','V','f','v', 'ù', 'Π', '&', '6', 'F', 'V', 'f', 'v',
'ì','Ψ','\'','7','G','W','g','w', 'ì', 'Ψ', '\'', '7', 'G', 'W', 'g', 'w',
'ò','Σ','(','8','H','X','h','x', 'ò', 'Σ', '(', '8', 'H', 'X', 'h', 'x',
'Ç','Θ',')','9','I','Y','i','y', 'Ç', 'Θ', ')', '9', 'I', 'Y', 'i', 'y',
"\n",'Ξ','*',':','J','Z','j','z', "\n", 'Ξ', '*', ':', 'J', 'Z', 'j', 'z',
'Ø',"\x1B",'+',';','K','Ä','k','ä', 'Ø', "\x1B", '+', ';', 'K', 'Ä', 'k', 'ä',
'ø','Æ',',','<','L','Ö','l','ö', 'ø', 'Æ', ',', '<', 'L', 'Ö', 'l', 'ö',
"\r",'æ','-','=','M','Ñ','m','ñ', "\r", 'æ', '-', '=', 'M', 'Ñ', 'm', 'ñ',
'Å','ß','.','>','N','Ü','n','ü', 'Å', 'ß', '.', '>', 'N', 'Ü', 'n', 'ü',
'å','É','/','?','O','§','o','à' 'å', 'É', '/', '?', 'O', '§', 'o', 'à',
); ];
$is_gsm0338 = true; $is_gsm0338 = true;
$len = mb_strlen($text); $len = mb_strlen($text);
for ($i = 0; $i < $len; $i++) for ($i = 0; $i < $len; ++$i)
{ {
if (!in_array(mb_substr($text, $i, 1), $gsm0338)) if (!in_array(mb_substr($text, $i, 1), $gsm0338))
{ {
$is_gsm0338 = false; $is_gsm0338 = false;
break; break;
} }
} }
return ($is_gsm0338 ? ceil($len / 160) : ceil($len / 70)); return $is_gsm0338 ? ceil($len / 160) : ceil($len / 70);
} }
/** /**
* Do email alerting for quotas limit close and quotas limit reached * Do email alerting for quotas limit close and quotas limit reached.
*/ */
public function alerting_for_limit_close_and_reached() public function alerting_for_limit_close_and_reached()
{ {
@ -173,11 +180,12 @@ class Quota extends StandardController
if (!$success) if (!$success)
{ {
echo "Cannot enqueue alert for quota limit close for quota : " . $quota['id'] . "\n"; echo 'Cannot enqueue alert for quota limit close for quota : ' . $quota['id'] . "\n";
continue; continue;
} }
echo "Enqueue alert for quota limit close for quota : " . $quota['id'] . "\n"; echo 'Enqueue alert for quota limit close for quota : ' . $quota['id'] . "\n";
$internal_event->create($quota['id_user'], 'QUOTA_LIMIT_CLOSE', round($quota_percentage * 100, 2) . '% of SMS quota limit reached.'); $internal_event->create($quota['id_user'], 'QUOTA_LIMIT_CLOSE', round($quota_percentage * 100, 2) . '% of SMS quota limit reached.');
} }
@ -197,19 +205,20 @@ class Quota extends StandardController
if (!$success) if (!$success)
{ {
echo "Cannot enqueue alert for quota limit reached for quota : " . $quota['id'] . "\n"; echo 'Cannot enqueue alert for quota limit reached for quota : ' . $quota['id'] . "\n";
continue; continue;
} }
echo "Enqueue alert for quota limit reached for quota : " . $quota['id'] . "\n"; echo 'Enqueue alert for quota limit reached for quota : ' . $quota['id'] . "\n";
$internal_event->create($quota['id_user'], 'QUOTA_LIMIT_REACHED', 'Reached SMS quota limit.'); $internal_event->create($quota['id_user'], 'QUOTA_LIMIT_REACHED', 'Reached SMS quota limit.');
} }
} }
/** /**
* Do quota renewing * Do quota renewing.
*/ */
public function renew_quotas () public function renew_quotas()
{ {
$internal_user = new User($this->bdd); $internal_user = new User($this->bdd);
$internal_event = new Event($this->bdd); $internal_event = new Event($this->bdd);
@ -254,11 +263,12 @@ class Quota extends StandardController
if (!$success) if (!$success)
{ {
echo "Cannot update quota : " . $quota['id'] . "\n"; echo 'Cannot update quota : ' . $quota['id'] . "\n";
continue; continue;
} }
echo "Update quota : " . $quota['id'] . "\n"; echo 'Update quota : ' . $quota['id'] . "\n";
$internal_event->create($quota['id_user'], 'QUOTA_RENEWAL', 'Renew quota and report ' . $report . ' credits.'); $internal_event->create($quota['id_user'], 'QUOTA_RENEWAL', 'Renew quota and report ' . $report . ' credits.');
} }
} }

View File

@ -36,11 +36,11 @@ namespace controllers\internals;
* @param int $id_phone : Id of the number the message was send with * @param int $id_phone : Id of the number the message was send with
* @param $at : Reception date * @param $at : Reception date
* @param $text : Text of the message * @param $text : Text of the message
* @param string $origin : Number of the sender * @param string $origin : Number of the sender
* @param string $status : Status of the received message * @param string $status : Status of the received message
* @param bool $command : Is the sms a command * @param bool $command : Is the sms a command
* @param bool $mms : Is the sms a mms * @param bool $mms : Is the sms a mms
* @param array $media_ids : Ids of the medias to link to received * @param array $media_ids : Ids of the medias to link to received
* *
* @return mixed : false on error, new received id else * @return mixed : false on error, new received id else
*/ */
@ -64,6 +64,7 @@ namespace controllers\internals;
if (!$id_received) if (!$id_received)
{ {
$this->bdd->rollBack(); $this->bdd->rollBack();
return false; return false;
} }
@ -75,6 +76,7 @@ namespace controllers\internals;
if (!$id_media_received) if (!$id_media_received)
{ {
$this->bdd->rollBack(); $this->bdd->rollBack();
return false; return false;
} }
} }
@ -167,6 +169,7 @@ namespace controllers\internals;
* @param int $id_user : User id * @param int $id_user : User id
* @param string $since : Date we want messages since format Y-m-d H:i:s * @param string $since : Date we want messages since format Y-m-d H:i:s
* @param string $origin : Number who sent the message * @param string $origin : Number who sent the message
*
* @return array * @return array
*/ */
public function gets_since_date_by_origin_and_user(int $id_user, string $since, string $origin) public function gets_since_date_by_origin_and_user(int $id_user, string $since, string $origin)
@ -256,11 +259,11 @@ namespace controllers\internals;
* @param string $origin : Number of the sender * @param string $origin : Number of the sender
* @param ?string $at : Message reception date, if null use current date * @param ?string $at : Message reception date, if null use current date
* @param string $status : Status of a the sms. By default \models\Received::STATUS_UNREAD * @param string $status : Status of a the sms. By default \models\Received::STATUS_UNREAD
* @param bool $mms : Is the sms a mms * @param bool $mms : Is the sms a mms
* @param array $medias : Empty array if no medias, or medias to create and link to the received message. Format : [[ * @param array $medias : Empty array if no medias, or medias to create and link to the received message. Format : [[
* string 'filepath' => local path to a readable copy of the media, * string 'filepath' => local path to a readable copy of the media,
* ?string 'extension' => extension to use for the file or null * ?string 'extension' => extension to use for the file or null
* ], ...] * ], ...]
* *
* @return array : [ * @return array : [
* bool 'error' => false if success, true else * bool 'error' => false if success, true else
@ -301,6 +304,7 @@ namespace controllers\internals;
catch (\Throwable $t) catch (\Throwable $t)
{ {
$return['error_message'] = $t->getMessage(); $return['error_message'] = $t->getMessage();
continue; //Better loose the media than the message continue; //Better loose the media than the message
} }
} }

View File

@ -43,7 +43,7 @@ namespace controllers\internals;
'mms' => $mms, 'mms' => $mms,
]; ];
if ($text === '') if ('' === $text)
{ {
return false; return false;
} }
@ -66,6 +66,7 @@ namespace controllers\internals;
if (!$id_scheduled) if (!$id_scheduled)
{ {
$this->bdd->rollBack(); $this->bdd->rollBack();
return false; return false;
} }
@ -76,11 +77,11 @@ namespace controllers\internals;
if (!$id_media_scheduled) if (!$id_media_scheduled)
{ {
$this->bdd->rollBack(); $this->bdd->rollBack();
return false; return false;
} }
} }
foreach ($numbers as $number) foreach ($numbers as $number)
{ {
$this->get_model()->insert_scheduled_number($id_scheduled, $number); $this->get_model()->insert_scheduled_number($id_scheduled, $number);
@ -193,6 +194,7 @@ namespace controllers\internals;
if (!$id_media_scheduled) if (!$id_media_scheduled)
{ {
$this->bdd->rollBack(); $this->bdd->rollBack();
return false; return false;
} }
} }

View File

@ -27,7 +27,7 @@ namespace controllers\internals;
* @param string $adapter : Name of the adapter service used to send the message * @param string $adapter : Name of the adapter service used to send the message
* @param bool $flash : Is the sms a flash * @param bool $flash : Is the sms a flash
* @param bool $mms : Is the sms a MMS. By default false. * @param bool $mms : Is the sms a MMS. By default false.
* @param array $medias : Array of medias to link to the MMS. * @param array $medias : Array of medias to link to the MMS
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN * @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
* *
* @return mixed : false on error, new sended id else * @return mixed : false on error, new sended id else
@ -54,6 +54,7 @@ namespace controllers\internals;
if (!$id_sended) if (!$id_sended)
{ {
$this->bdd->rollback(); $this->bdd->rollback();
return false; return false;
} }
@ -139,6 +140,7 @@ namespace controllers\internals;
* @param int $id_user : User id * @param int $id_user : User id
* @param string $since : Date we want messages since format Y-m-d H:i:s * @param string $since : Date we want messages since format Y-m-d H:i:s
* @param string $origin : Number who sent the message * @param string $origin : Number who sent the message
*
* @return array * @return array
*/ */
public function gets_since_date_by_destination_and_user(int $id_user, string $since, string $origin) public function gets_since_date_by_destination_and_user(int $id_user, string $since, string $origin)
@ -204,7 +206,7 @@ namespace controllers\internals;
* @param string $destination : Number of the receiver * @param string $destination : Number of the receiver
* @param bool $flash : Is the sms a flash. By default false. * @param bool $flash : Is the sms a flash. By default false.
* @param bool $mms : Is the sms a MMS. By default false. * @param bool $mms : Is the sms a MMS. By default false.
* @param array $medias : Array of medias to link to the MMS. * @param array $medias : Array of medias to link to the MMS
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN * @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
* *
* @return array : [ * @return array : [
@ -230,7 +232,6 @@ namespace controllers\internals;
return $return; return $return;
} }
$at = (new \DateTime())->format('Y-m-d H:i:s'); $at = (new \DateTime())->format('Y-m-d H:i:s');
$media_uris = []; $media_uris = [];
foreach ($medias as $media) foreach ($medias as $media)

View File

@ -168,7 +168,7 @@ namespace controllers\internals;
/** /**
* Check if a sting represent a valid PHP period for creating an interval. * Check if a sting represent a valid PHP period for creating an interval.
* *
* @param string $period : Period string to check * @param string $period : Period string to check
* *
* @return bool : True if valid period, false else * @return bool : True if valid period, false else
*/ */
@ -320,26 +320,27 @@ namespace controllers\internals;
} }
/** /**
* Generate a highly random uuid based on timestamp and strong cryptographic random * Generate a highly random uuid based on timestamp and strong cryptographic random.
* *
* @return string * @return string
*/ */
public static function random_uuid() public static function random_uuid()
{ {
$bytes = random_bytes(16); $bytes = random_bytes(16);
return time() . '-' . bin2hex($bytes); return time() . '-' . bin2hex($bytes);
} }
/** /**
* Create a user data public path * Create a user data public path.
*
* @param int $id_user : The user id * @param int $id_user : The user id
* *
* @return string : The created path * @return string : The created path
*
* @exception Raise exception on error * @exception Raise exception on error
*/ */
public static function create_user_public_path (int $id_user) public static function create_user_public_path(int $id_user)
{ {
$new_dir = PWD_DATA_PUBLIC . '/' . $id_user; $new_dir = PWD_DATA_PUBLIC . '/' . $id_user;
if (file_exists($new_dir)) if (file_exists($new_dir))
@ -354,18 +355,18 @@ namespace controllers\internals;
} }
//We do chmod in two times because else umask fuck mkdir permissions //We do chmod in two times because else umask fuck mkdir permissions
if (!chmod($new_dir, fileperms(PWD_DATA_PUBLIC) & 0777)) //Fileperms return garbage in addition to perms. Perms are only in weak bytes. We must use an octet notation with 0 if (!chmod($new_dir, fileperms(PWD_DATA_PUBLIC) & 0777))
{ { //Fileperms return garbage in addition to perms. Perms are only in weak bytes. We must use an octet notation with 0
throw new \Exception('Cannot give dir ' . $new_dir . ' rights : ' . decoct(fileperms(PWD_DATA_PUBLIC) & 0777)); //Show error in dec throw new \Exception('Cannot give dir ' . $new_dir . ' rights : ' . decoct(fileperms(PWD_DATA_PUBLIC) & 0777)); //Show error in dec
} }
if (posix_getuid() === 0 && !chown($new_dir, fileowner(PWD_DATA_PUBLIC))) //If we are root, try to give the file to a proper user if (0 === posix_getuid() && !chown($new_dir, fileowner(PWD_DATA_PUBLIC)))
{ { //If we are root, try to give the file to a proper user
throw new \Exception('Cannot give dir ' . $new_dir . ' to user : ' . fileowner(PWD_DATA_PUBLIC)); throw new \Exception('Cannot give dir ' . $new_dir . ' to user : ' . fileowner(PWD_DATA_PUBLIC));
} }
if (posix_getuid() === 0 && !chgrp($new_dir, filegroup(PWD_DATA_PUBLIC))) //If we are root, try to give the file to a proper group if (0 === posix_getuid() && !chgrp($new_dir, filegroup(PWD_DATA_PUBLIC)))
{ { //If we are root, try to give the file to a proper group
throw new \Exception('Cannot give dir ' . $new_dir . ' to group : ' . filegroup(PWD_DATA_PUBLIC)); throw new \Exception('Cannot give dir ' . $new_dir . ' to group : ' . filegroup(PWD_DATA_PUBLIC));
} }

View File

@ -32,9 +32,9 @@ namespace controllers\internals;
} }
/** /**
* Return a list of users by their ids * Return a list of users by their ids.
* *
* @param array $ids : ids of entries to find * @param array $ids : ids of entries to find
* *
* @return array * @return array
*/ */
@ -194,8 +194,8 @@ namespace controllers\internals;
/** /**
* Update a user by his id. * Update a user by his id.
* *
* @param mixed $id : User id * @param mixed $id : User id
* @param array $user : Array of fields to update for user * @param array $user : Array of fields to update for user
* @param mixed (?array|bool) $quota : Quota to update for the user, by default null -> no update, if false, remove quota * @param mixed (?array|bool) $quota : Quota to update for the user, by default null -> no update, if false, remove quota
* *
* @return bool : True on success, false on error * @return bool : True on success, false on error
@ -209,12 +209,13 @@ namespace controllers\internals;
$this->model_user->update($id, $user); $this->model_user->update($id, $user);
if ($current_quota && $quota === false) if ($current_quota && false === $quota)
{ {
$success = $internal_quota->delete_for_user($id, $current_quota['id']); $success = $internal_quota->delete_for_user($id, $current_quota['id']);
if (!$success) if (!$success)
{ {
$this->bdd->rollback(); $this->bdd->rollback();
return false; return false;
} }
} }
@ -237,7 +238,6 @@ namespace controllers\internals;
} }
} }
if (!$this->bdd->commit()) if (!$this->bdd->commit())
{ {
return false; return false;
@ -277,7 +277,6 @@ namespace controllers\internals;
return false; return false;
} }
$success = $this->internal_setting->create_defaults_for_user($new_id_user); $success = $this->internal_setting->create_defaults_for_user($new_id_user);
if (!$success) if (!$success)
{ {
@ -286,8 +285,7 @@ namespace controllers\internals;
return false; return false;
} }
if (null !== $quota)
if ($quota !== null)
{ {
$internal_quota = new Quota($this->bdd); $internal_quota = new Quota($this->bdd);
$success = $internal_quota->create($new_id_user, $quota['credit'], $quota['additional'], $quota['report_unused'], $quota['report_unused_additional'], $quota['auto_renew'], $quota['renew_interval'], $quota['start_date'], $quota['expiration_date']); $success = $internal_quota->create($new_id_user, $quota['credit'], $quota['additional'], $quota['report_unused'], $quota['report_unused_additional'], $quota['auto_renew'], $quota['renew_interval'], $quota['start_date'], $quota['expiration_date']);
@ -299,7 +297,6 @@ namespace controllers\internals;
} }
} }
if (!$this->bdd->commit()) if (!$this->bdd->commit())
{ {
return false; return false;

View File

@ -231,16 +231,16 @@ namespace controllers\publics;
//Iterate over files to re-create individual $_FILES array //Iterate over files to re-create individual $_FILES array
$files_arrays = []; $files_arrays = [];
if ($files === false) if (false === $files)
{ {
$files_arrays = []; $files_arrays = [];
} }
elseif (!is_array($files['name'])) //Only one file uploaded elseif (!is_array($files['name']))
{ { //Only one file uploaded
$files_arrays[] = $files; $files_arrays[] = $files;
} }
else //multiple files else
{ { //multiple files
foreach ($files as $property_name => $files_values) foreach ($files as $property_name => $files_values)
{ {
foreach ($files_values as $file_key => $property_value) foreach ($files_values as $file_key => $property_value)

View File

@ -34,7 +34,7 @@ namespace controllers\publics;
} }
/** /**
* Page for showing calls list * Page for showing calls list.
*/ */
public function list() public function list()
{ {
@ -51,12 +51,14 @@ namespace controllers\publics;
{ {
switch ($entity['direction']) switch ($entity['direction'])
{ {
case \models\Call::DIRECTION_INBOUND : case \models\Call::DIRECTION_INBOUND:
$entity['origin_formatted'] = \controllers\internals\Tool::phone_link($entity['origin']); $entity['origin_formatted'] = \controllers\internals\Tool::phone_link($entity['origin']);
break; break;
case \models\Call::DIRECTION_OUTBOUND : case \models\Call::DIRECTION_OUTBOUND:
$entity['destination_formatted'] = \controllers\internals\Tool::phone_link($entity['destination']); $entity['destination_formatted'] = \controllers\internals\Tool::phone_link($entity['destination']);
break; break;
} }
} }
@ -66,10 +68,10 @@ namespace controllers\publics;
} }
/** /**
* Delete a list of calls * Delete a list of calls.
* *
* @param array int $_GET['ids'] : Ids of calls to delete * @param array int $_GET['ids'] : Ids of calls to delete
* @param string $csrf : csrf token * @param string $csrf : csrf token
* *
* @return boolean; * @return boolean;
*/ */

View File

@ -207,12 +207,11 @@ use Monolog\Logger;
return true; return true;
} }
/** /**
* Function call on call reception notification * Function call on call reception notification
* We return nothing, and we let the adapter do his things. * We return nothing, and we let the adapter do his things.
* *
* @param int $id_phone : Phone id * @param int $id_phone : Phone id
* *
* @return bool : true on success, false on error * @return bool : true on success, false on error
*/ */
@ -273,12 +272,11 @@ use Monolog\Logger;
return true; return true;
} }
/** /**
* Function call on end call notification * Function call on end call notification
* We return nothing, and we let the adapter do his things. * We return nothing, and we let the adapter do his things.
* *
* @param int $id_phone : Phone id * @param int $id_phone : Phone id
* *
* @return bool : true on success, false on error * @return bool : true on success, false on error
*/ */

View File

@ -241,7 +241,7 @@ namespace controllers\publics;
if ($how_many_more > 0) if ($how_many_more > 0)
{ {
$result_text .= ", et $how_many_more autres."; $result_text .= ", et {$how_many_more} autres.";
} }
$return['result'] = $result_text; $return['result'] = $result_text;

View File

@ -87,10 +87,10 @@ namespace controllers\publics;
} }
/** /**
* This function will delete a list of contacts depending on a condition * This function will delete a list of contacts depending on a condition.
* *
* @param string $_POST['condition'] : Condition to use to delete contacts * @param string $_POST['condition'] : Condition to use to delete contacts
* @param mixed $csrf * @param mixed $csrf
* *
* @return boolean; * @return boolean;
*/ */
@ -338,11 +338,11 @@ namespace controllers\publics;
break; break;
default: default:
if ($read_file['extension'] === 'csv') if ('csv' === $read_file['extension'])
{ {
$result = $this->internal_contact->import_csv($id_user, $read_file['content']); $result = $this->internal_contact->import_csv($id_user, $read_file['content']);
} }
elseif ($read_file['extension'] === 'json') elseif ('json' === $read_file['extension'])
{ {
$result = $this->internal_contact->import_json($id_user, $read_file['content']); $result = $this->internal_contact->import_json($id_user, $read_file['content']);
} }

View File

@ -62,7 +62,6 @@ namespace controllers\publics;
$nb_sendeds = $this->internal_sended->count_for_user($id_user); $nb_sendeds = $this->internal_sended->count_for_user($id_user);
$nb_receiveds = $this->internal_received->count_for_user($id_user); $nb_receiveds = $this->internal_received->count_for_user($id_user);
//Récupération des 10 derniers Sms envoyés, Sms reçus et evenements enregistrés. Par date. //Récupération des 10 derniers Sms envoyés, Sms reçus et evenements enregistrés. Par date.
$sendeds = $this->internal_sended->get_lasts_by_date_for_user($id_user, 10); $sendeds = $this->internal_sended->get_lasts_by_date_for_user($id_user, 10);
$receiveds = $this->internal_received->get_lasts_by_date_for_user($id_user, 10); $receiveds = $this->internal_received->get_lasts_by_date_for_user($id_user, 10);

View File

@ -125,7 +125,7 @@ namespace controllers\publics;
} }
$message = [ $message = [
'uid' => 'sended-' . $sended['id'], 'uid' => 'sended-' . $sended['id'],
'date' => htmlspecialchars($sended['at']), 'date' => htmlspecialchars($sended['at']),
'text' => htmlspecialchars($sended['text']), 'text' => htmlspecialchars($sended['text']),
'type' => 'sended', 'type' => 'sended',
@ -133,7 +133,6 @@ namespace controllers\publics;
'status' => $sended['status'], 'status' => $sended['status'],
]; ];
$messages[] = $message; $messages[] = $message;
} }
@ -155,7 +154,7 @@ namespace controllers\publics;
} }
$messages[] = [ $messages[] = [
'uid' => 'received-' . $received['id'], 'uid' => 'received-' . $received['id'],
'date' => htmlspecialchars($received['at']), 'date' => htmlspecialchars($received['at']),
'text' => htmlspecialchars($received['text']), 'text' => htmlspecialchars($received['text']),
'type' => 'received', 'type' => 'received',
@ -176,7 +175,7 @@ namespace controllers\publics;
} }
$messages[] = [ $messages[] = [
'uid' => 'scheduled-' . $scheduled['id'], 'uid' => 'scheduled-' . $scheduled['id'],
'date' => htmlspecialchars($scheduled['at']), 'date' => htmlspecialchars($scheduled['at']),
'text' => htmlspecialchars($scheduled['text']), 'text' => htmlspecialchars($scheduled['text']),
'type' => 'inprogress', 'type' => 'inprogress',
@ -210,7 +209,7 @@ namespace controllers\publics;
* @param string $_POST['text'] : Le contenu du Sms * @param string $_POST['text'] : Le contenu du Sms
* @param string $_POST['destination'] : Number to send sms to * @param string $_POST['destination'] : Number to send sms to
* @param string $_POST['id_phone'] : If of phone to send sms with * @param string $_POST['id_phone'] : If of phone to send sms with
* @param array $_FILES['medias'] : Medias to upload and link to sms * @param array $_FILES['medias'] : Medias to upload and link to sms
* *
* @return string : json string Le statut de l'envoi * @return string : json string Le statut de l'envoi
*/ */
@ -259,7 +258,7 @@ namespace controllers\publics;
//Remove empty files input //Remove empty files input
foreach ($files_arrays as $key => $file) foreach ($files_arrays as $key => $file)
{ {
if ($file['error'] === UPLOAD_ERR_NO_FILE) if (UPLOAD_ERR_NO_FILE === $file['error'])
{ {
unset($files_arrays[$key]); unset($files_arrays[$key]);
} }
@ -288,7 +287,6 @@ namespace controllers\publics;
$id_phone = null; $id_phone = null;
} }
//If mms is enable and we have medias uploaded //If mms is enable and we have medias uploaded
$media_ids = []; $media_ids = [];
if ($_SESSION['user']['settings']['mms'] && $files_arrays) if ($_SESSION['user']['settings']['mms'] && $files_arrays)

View File

@ -242,7 +242,7 @@ namespace controllers\publics;
* @param ?array $_POST['contacts'] : Numbers to send the message to * @param ?array $_POST['contacts'] : Numbers to send the message to
* @param ?array $_POST['groups'] : Numbers to send the message to * @param ?array $_POST['groups'] : Numbers to send the message to
* @param ?array $_POST['conditional_groups'] : Numbers to send the message to * @param ?array $_POST['conditional_groups'] : Numbers to send the message to
* @param ?array $_FILES['medias'] : The media to link to a scheduled * @param ?array $_FILES['medias'] : The media to link to a scheduled
*/ */
public function create($csrf) public function create($csrf)
{ {
@ -285,7 +285,7 @@ namespace controllers\publics;
//Remove empty files input //Remove empty files input
foreach ($files_arrays as $key => $file) foreach ($files_arrays as $key => $file)
{ {
if ($file['error'] === UPLOAD_ERR_NO_FILE) if (UPLOAD_ERR_NO_FILE === $file['error'])
{ {
unset($files_arrays[$key]); unset($files_arrays[$key]);
} }
@ -339,6 +339,7 @@ namespace controllers\publics;
catch (\Exception $e) catch (\Exception $e)
{ {
\FlashMessage\FlashMessage::push('danger', 'Impossible d\'upload et d\'enregistrer le fichier ' . $file['name'] . ':' . $e->getMessage()); \FlashMessage\FlashMessage::push('danger', 'Impossible d\'upload et d\'enregistrer le fichier ' . $file['name'] . ':' . $e->getMessage());
return $this->redirect(\descartes\Router::url('Scheduled', 'add')); return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
} }
@ -423,7 +424,7 @@ namespace controllers\publics;
//Remove empty files input //Remove empty files input
foreach ($files_arrays as $key => $file) foreach ($files_arrays as $key => $file)
{ {
if ($file['error'] === UPLOAD_ERR_NO_FILE) if (UPLOAD_ERR_NO_FILE === $file['error'])
{ {
unset($files_arrays[$key]); unset($files_arrays[$key]);
} }
@ -488,7 +489,7 @@ namespace controllers\publics;
$mms = (bool) count($media_ids); $mms = (bool) count($media_ids);
$this->internal_scheduled->update_for_user($id_user, $id_scheduled, $at, $text, $id_phone, $flash, $mms, $numbers, $contacts, $groups, $conditional_groups, $media_ids); $this->internal_scheduled->update_for_user($id_user, $id_scheduled, $at, $text, $id_phone, $flash, $mms, $numbers, $contacts, $groups, $conditional_groups, $media_ids);
$nb_update++; ++$nb_update;
} }
if ($nb_update !== \count($scheduleds)) if ($nb_update !== \count($scheduleds))

View File

@ -39,8 +39,8 @@ namespace controllers\publics;
* *
* @param string $setting_name : Name of the setting to modify * @param string $setting_name : Name of the setting to modify
* @param $csrf : CSRF token * @param $csrf : CSRF token
* @param string $_POST['setting_value'] : Setting's new value * @param string $_POST['setting_value'] : Setting's new value
* @param bool $_POST['allow_no_value'] : Default false, if true then allow $_POST['setting_value'] to dont exists, and treat it as empty string * @param bool $_POST['allow_no_value'] : Default false, if true then allow $_POST['setting_value'] to dont exists, and treat it as empty string
* *
* @return boolean; * @return boolean;
*/ */
@ -57,7 +57,7 @@ namespace controllers\publics;
$allow_no_value = $_POST['allow_no_value'] ?? false; $allow_no_value = $_POST['allow_no_value'] ?? false;
//if no value allowed and no value fund, default to '' //if no value allowed and no value fund, default to ''
if ($allow_no_value && ($setting_value === false)) if ($allow_no_value && (false === $setting_value))
{ {
$setting_value = ''; $setting_value = '';
} }

View File

@ -88,7 +88,6 @@ namespace controllers\publics;
$return['result'] = 'Message vide, il ne sera pas envoyé.'; $return['result'] = 'Message vide, il ne sera pas envoyé.';
} }
//Add credit estimation //Add credit estimation
$return['estimation_credit'] = $this->internal_quota->compute_credits_for_message($return['result']); $return['estimation_credit'] = $this->internal_quota->compute_credits_for_message($return['result']);

View File

@ -80,7 +80,7 @@ class User extends \descartes\Controller
* *
* @param array int $_GET['user_ids'] : User ids * @param array int $_GET['user_ids'] : User ids
* @param mixed $csrf * @param mixed $csrf
* @param int $status : 1 -> active, 0 -> suspended * @param int $status : 1 -> active, 0 -> suspended
* *
* @return boolean; * @return boolean;
*/ */
@ -159,17 +159,17 @@ class User extends \descartes\Controller
* Cette fonction insert un nouveau user. * Cette fonction insert un nouveau user.
* *
* @param $csrf : Le jeton CSRF * @param $csrf : Le jeton CSRF
* @param string $_POST['email'] : User email * @param string $_POST['email'] : User email
* @param optional string $_POST['password'] : User password, (if empty the password is randomly generated) * @param optional string $_POST['password'] : User password, (if empty the password is randomly generated)
* @param optional boolean $_POST['admin'] : If true user is admin * @param optional boolean $_POST['admin'] : If true user is admin
* @param optional boolean $_POST['quota_enable'] : If true create a quota for the user * @param optional boolean $_POST['quota_enable'] : If true create a quota for the user
* @param boolean $_POST['quota_enable'] : If true create a quota for the user * @param bool $_POST['quota_enable'] : If true create a quota for the user
* @param optional int $_POST['quota_credit'] : credit for quota * @param optional int $_POST['quota_credit'] : credit for quota
* @param optional int $_POST['quota_additional'] : additional credit * @param optional int $_POST['quota_additional'] : additional credit
* @param optional string $_POST['quota_start_date'] : quota beginning date * @param optional string $_POST['quota_start_date'] : quota beginning date
* @param optional string $_POST['quota_renewal_interval'] : period to use on renewal to calculate new expiration date. Also use to calculate first expiration date. * @param optional string $_POST['quota_renewal_interval'] : period to use on renewal to calculate new expiration date. Also use to calculate first expiration date.
* @param optional boolean $_POST['quota_auto_renew'] : Should the quota be automatically renewed on expiration * @param optional boolean $_POST['quota_auto_renew'] : Should the quota be automatically renewed on expiration
* @param optional boolean $_POST['quota_report_unused'] : Should unused credit be reported next month * @param optional boolean $_POST['quota_report_unused'] : Should unused credit be reported next month
* @param optional boolean $_POST['quota_report_unused_additional'] : Should unused additional credit be transfered next month * @param optional boolean $_POST['quota_report_unused_additional'] : Should unused additional credit be transfered next month
*/ */
public function create($csrf) public function create($csrf)
@ -194,7 +194,6 @@ class User extends \descartes\Controller
$quota_report_unused = $_POST['quota_report_unused'] ?? false; $quota_report_unused = $_POST['quota_report_unused'] ?? false;
$quota_report_unused_additional = $_POST['quota_report_unused_additional'] ?? false; $quota_report_unused_additional = $_POST['quota_report_unused_additional'] ?? false;
if (!$email) if (!$email)
{ {
\FlashMessage\FlashMessage::push('danger', 'Vous devez au moins fournir une adresse e-mail pour l\'utilisateur.'); \FlashMessage\FlashMessage::push('danger', 'Vous devez au moins fournir une adresse e-mail pour l\'utilisateur.');
@ -209,7 +208,6 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'add')); return $this->redirect(\descartes\Router::url('User', 'add'));
} }
//Forge quota for user if needed //Forge quota for user if needed
$quota = null; $quota = null;
if ($quota_enable) if ($quota_enable)
@ -218,7 +216,7 @@ class User extends \descartes\Controller
$quota['credit'] = (int) $quota_credit; $quota['credit'] = (int) $quota_credit;
$quota['additional'] = (int) $quota_additional; $quota['additional'] = (int) $quota_additional;
if ($quota_start_date === false || !\controllers\internals\Tool::validate_date($quota_start_date, 'Y-m-d H:i:s')) if (false === $quota_start_date || !\controllers\internals\Tool::validate_date($quota_start_date, 'Y-m-d H:i:s'))
{ {
\FlashMessage\FlashMessage::push('danger', 'Vous devez définir une date de début valide pour le quota.'); \FlashMessage\FlashMessage::push('danger', 'Vous devez définir une date de début valide pour le quota.');
@ -226,7 +224,7 @@ class User extends \descartes\Controller
} }
$quota['start_date'] = new \DateTime($quota_start_date); $quota['start_date'] = new \DateTime($quota_start_date);
if ($quota_renew_interval === false || !\controllers\internals\Tool::validate_period($quota_renew_interval)) if (false === $quota_renew_interval || !\controllers\internals\Tool::validate_period($quota_renew_interval))
{ {
\FlashMessage\FlashMessage::push('danger', 'Vous devez définir une durée de quota parmis la liste proposée.'); \FlashMessage\FlashMessage::push('danger', 'Vous devez définir une durée de quota parmis la liste proposée.');
@ -242,7 +240,6 @@ class User extends \descartes\Controller
$quota['report_unused_additional'] = (bool) $quota_report_unused_additional; $quota['report_unused_additional'] = (bool) $quota_report_unused_additional;
} }
$id_user = $this->internal_user->create($email, $password, $admin, null, \models\User::STATUS_ACTIVE, true, $quota); $id_user = $this->internal_user->create($email, $password, $admin, null, \models\User::STATUS_ACTIVE, true, $quota);
if (!$id_user) if (!$id_user)
{ {
@ -251,7 +248,6 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'add')); return $this->redirect(\descartes\Router::url('User', 'add'));
} }
$mailer = new \controllers\internals\Mailer(); $mailer = new \controllers\internals\Mailer();
$email_send = $mailer->enqueue($email, EMAIL_CREATE_USER, ['email' => $email, 'password' => $password]); $email_send = $mailer->enqueue($email, EMAIL_CREATE_USER, ['email' => $email, 'password' => $password]);
if (!$email_send) if (!$email_send)
@ -265,7 +261,7 @@ class User extends \descartes\Controller
} }
/** /**
* Return the edition page for the users * Return the edition page for the users.
* *
* @param int... $ids : users ids * @param int... $ids : users ids
*/ */
@ -295,9 +291,8 @@ class User extends \descartes\Controller
]); ]);
} }
/** /**
* Update a list of users * Update a list of users.
* *
* @param $csrf : Le jeton CSRF * @param $csrf : Le jeton CSRF
* @param array $_POST['users'] : Array of the users and new values, id as key. Quota may also be defined. * @param array $_POST['users'] : Array of the users and new values, id as key. Quota may also be defined.
@ -343,7 +338,6 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'add')); return $this->redirect(\descartes\Router::url('User', 'add'));
} }
//Forge quota for user if needed //Forge quota for user if needed
$quota = false; $quota = false;
if ($quota_enable) if ($quota_enable)
@ -353,7 +347,7 @@ class User extends \descartes\Controller
$quota['consumed'] = (int) $quota_consumed; $quota['consumed'] = (int) $quota_consumed;
$quota['additional'] = (int) $quota_additional; $quota['additional'] = (int) $quota_additional;
if ($quota_start_date === false || !\controllers\internals\Tool::validate_date($quota_start_date, 'Y-m-d H:i:s')) if (false === $quota_start_date || !\controllers\internals\Tool::validate_date($quota_start_date, 'Y-m-d H:i:s'))
{ {
\FlashMessage\FlashMessage::push('danger', 'L\'utilisateur #' . (int) $id_user . ' n\'as pas pu être mis à jour car la date de début du quota associé n\'est pas valide.'); \FlashMessage\FlashMessage::push('danger', 'L\'utilisateur #' . (int) $id_user . ' n\'as pas pu être mis à jour car la date de début du quota associé n\'est pas valide.');
@ -361,7 +355,7 @@ class User extends \descartes\Controller
} }
$quota['start_date'] = new \DateTime($quota_start_date); $quota['start_date'] = new \DateTime($quota_start_date);
if ($quota_renew_interval === false || !\controllers\internals\Tool::validate_period($quota_renew_interval)) if (false === $quota_renew_interval || !\controllers\internals\Tool::validate_period($quota_renew_interval))
{ {
\FlashMessage\FlashMessage::push('danger', 'L\'utilisateur #' . (int) $id_user . ' n\'as pas pu être mis à jour car la durée du quota associé n\'est pas valide.'); \FlashMessage\FlashMessage::push('danger', 'L\'utilisateur #' . (int) $id_user . ' n\'as pas pu être mis à jour car la durée du quota associé n\'est pas valide.');
@ -376,13 +370,11 @@ class User extends \descartes\Controller
$quota['report_unused'] = (bool) $quota_report_unused; $quota['report_unused'] = (bool) $quota_report_unused;
$quota['report_unused_additional'] = (bool) $quota_report_unused_additional; $quota['report_unused_additional'] = (bool) $quota_report_unused_additional;
//Format dates //Format dates
$quota['start_date'] = $quota['start_date']->format('Y-m-d H:i:s'); $quota['start_date'] = $quota['start_date']->format('Y-m-d H:i:s');
$quota['expiration_date'] = $quota['expiration_date']->format('Y-m-d H:i:s'); $quota['expiration_date'] = $quota['expiration_date']->format('Y-m-d H:i:s');
} }
$updated_user = [ $updated_user = [
'email' => $email, 'email' => $email,
'admin' => $admin, 'admin' => $admin,
@ -401,7 +393,7 @@ class User extends \descartes\Controller
continue; continue;
} }
$nb_update++; ++$nb_update;
} }
if ($nb_update != count($users)) if ($nb_update != count($users))

View File

@ -12,7 +12,7 @@
namespace models; namespace models;
/** /**
* Manage bdd operations for calls * Manage bdd operations for calls.
*/ */
class Call extends StandardModel class Call extends StandardModel
{ {
@ -62,11 +62,11 @@ namespace models;
} }
/** /**
* Get a call for a user by his phone and uid * Get a call for a user by his phone and uid.
* *
* @param int $id_user : user id * @param int $id_user : user id
* @param int $id_phone : phone id * @param int $id_phone : phone id
* @param int $uid : call uid * @param int $uid : call uid
* *
* @return array : the call or an empty array * @return array : the call or an empty array
*/ */

View File

@ -27,16 +27,16 @@ namespace models;
} }
/** /**
* Gets events for a type, since a date and eventually until a date (both included) * Gets events for a type, since a date and eventually until a date (both included).
* *
* @param int $id_user : User id * @param int $id_user : User id
* @param string $type : Event type we want * @param string $type : Event type we want
* @param \DateTime $since : Date to get events since * @param \DateTime $since : Date to get events since
* @param ?\DateTime $until (optional) : Date until wich we want events, if not specified no limit * @param ?\DateTime $until (optional) : Date until wich we want events, if not specified no limit
* *
* @return array * @return array
*/ */
public function get_events_by_type_and_date_for_user (int $id_user, string $type, \DateTime $since, ?\DateTime $until = null) public function get_events_by_type_and_date_for_user(int $id_user, string $type, \DateTime $since, ?\DateTime $until = null)
{ {
$where = [ $where = [
'id_user' => $id_user, 'id_user' => $id_user,
@ -44,7 +44,7 @@ namespace models;
'>=at' => $since->format('Y-m-d H:i:s'), '>=at' => $since->format('Y-m-d H:i:s'),
]; ];
if ($until !== null) if (null !== $until)
{ {
$where['<=at'] = $until->format('Y-m-d H:i:s'); $where['<=at'] = $until->format('Y-m-d H:i:s');
} }

View File

@ -89,14 +89,14 @@ namespace models;
} }
/** /**
* Link a media to a scheduled * Link a media to a scheduled.
* *
* @param int $id_media : Media id * @param int $id_media : Media id
* @param int $id_scheduled : Scheduled id * @param int $id_scheduled : Scheduled id
* *
* @return bool | int * @return bool | int
*/ */
public function insert_media_scheduled (int $id_media, int $id_scheduled) public function insert_media_scheduled(int $id_media, int $id_scheduled)
{ {
$entry = [ $entry = [
'id_media' => $id_media, 'id_media' => $id_media,
@ -107,14 +107,14 @@ namespace models;
} }
/** /**
* Link a media to a received * Link a media to a received.
* *
* @param int $id_media : Media id * @param int $id_media : Media id
* @param int $id_received : Scheduled id * @param int $id_received : Scheduled id
* *
* @return bool | int * @return bool | int
*/ */
public function insert_media_received (int $id_media, int $id_received) public function insert_media_received(int $id_media, int $id_received)
{ {
$entry = [ $entry = [
'id_media' => $id_media, 'id_media' => $id_media,
@ -125,14 +125,14 @@ namespace models;
} }
/** /**
* Link a media to a sended * Link a media to a sended.
* *
* @param int $id_media : Media id * @param int $id_media : Media id
* @param int $id_sended : Scheduled id * @param int $id_sended : Scheduled id
* *
* @return bool | int * @return bool | int
*/ */
public function insert_media_sended (int $id_media, int $id_sended) public function insert_media_sended(int $id_media, int $id_sended)
{ {
$entry = [ $entry = [
'id_media' => $id_media, 'id_media' => $id_media,
@ -143,14 +143,14 @@ namespace models;
} }
/** /**
* Unlink a media of a scheduled * Unlink a media of a scheduled.
* *
* @param int $id_media : Media id * @param int $id_media : Media id
* @param int $id_scheduled : Scheduled id * @param int $id_scheduled : Scheduled id
* *
* @return bool | int * @return bool | int
*/ */
public function delete_media_scheduled (int $id_media, int $id_scheduled) public function delete_media_scheduled(int $id_media, int $id_scheduled)
{ {
$where = [ $where = [
'id_media' => $id_media, 'id_media' => $id_media,
@ -161,14 +161,14 @@ namespace models;
} }
/** /**
* Unlink a media of a received * Unlink a media of a received.
* *
* @param int $id_media : Media id * @param int $id_media : Media id
* @param int $id_received : Scheduled id * @param int $id_received : Scheduled id
* *
* @return bool | int * @return bool | int
*/ */
public function delete_media_received (int $id_media, int $id_received) public function delete_media_received(int $id_media, int $id_received)
{ {
$where = [ $where = [
'id_media' => $id_media, 'id_media' => $id_media,
@ -179,14 +179,14 @@ namespace models;
} }
/** /**
* Unlink a media of a sended * Unlink a media of a sended.
* *
* @param int $id_media : Media id * @param int $id_media : Media id
* @param int $id_sended : Scheduled id * @param int $id_sended : Scheduled id
* *
* @return bool | int * @return bool | int
*/ */
public function delete_media_sended (int $id_media, int $id_sended) public function delete_media_sended(int $id_media, int $id_sended)
{ {
$where = [ $where = [
'id_media' => $id_media, 'id_media' => $id_media,
@ -196,15 +196,14 @@ namespace models;
return $this->_delete('media_sended', $where); return $this->_delete('media_sended', $where);
} }
/** /**
* Unlink all medias of a scheduled * Unlink all medias of a scheduled.
* *
* @param int $id_scheduled : Scheduled id * @param int $id_scheduled : Scheduled id
* *
* @return bool | int * @return bool | int
*/ */
public function delete_all_for_scheduled (int $id_scheduled) public function delete_all_for_scheduled(int $id_scheduled)
{ {
$where = [ $where = [
'id_scheduled' => $id_scheduled, 'id_scheduled' => $id_scheduled,
@ -214,13 +213,13 @@ namespace models;
} }
/** /**
* Unlink all medias of a received * Unlink all medias of a received.
* *
* @param int $id_received : Scheduled id * @param int $id_received : Scheduled id
* *
* @return bool | int * @return bool | int
*/ */
public function delete_all_for_received (int $id_received) public function delete_all_for_received(int $id_received)
{ {
$where = [ $where = [
'id_received' => $id_received, 'id_received' => $id_received,
@ -230,13 +229,13 @@ namespace models;
} }
/** /**
* Unlink all medias of a sended * Unlink all medias of a sended.
* *
* @param int $id_sended : Scheduled id * @param int $id_sended : Scheduled id
* *
* @return bool | int * @return bool | int
*/ */
public function delete_all_for_sended (int $id_sended) public function delete_all_for_sended(int $id_sended)
{ {
$where = [ $where = [
'id_sended' => $id_sended, 'id_sended' => $id_sended,
@ -246,10 +245,11 @@ namespace models;
} }
/** /**
* Find all unused medias * Find all unused medias.
*
* @return array * @return array
*/ */
public function gets_unused () public function gets_unused()
{ {
$query = ' $query = '
SELECT `media`.* SELECT `media`.*

View File

@ -27,12 +27,14 @@ namespace models;
/** /**
* Get remaining credit for a date * Get remaining credit for a date
* if no quota for this user return max int * if no quota for this user return max int.
* @param int $id_user : User id *
* @param \DateTime $at : date to get credit at * @param int $id_user : User id
* @param \DateTime $at : date to get credit at
*
* @return int : number of remaining credits * @return int : number of remaining credits
*/ */
public function get_remaining_credit (int $id_user, \DateTime $at): int public function get_remaining_credit(int $id_user, \DateTime $at): int
{ {
$query = ' $query = '
SELECT (credit + additional - consumed) AS remaining_credit SELECT (credit + additional - consumed) AS remaining_credit
@ -48,17 +50,19 @@ namespace models;
$result = $this->_run_query($query, $params); $result = $this->_run_query($query, $params);
return ($result[0]['remaining_credit'] ?? PHP_INT_MAX); return $result[0]['remaining_credit'] ?? PHP_INT_MAX;
} }
/** /**
* Get credit usage percent for a date * Get credit usage percent for a date
* if no quota for this user return 0 * if no quota for this user return 0.
* @param int $id_user : User id *
* @param \DateTime $at : date to get usage percent at * @param int $id_user : User id
* @param \DateTime $at : date to get usage percent at
*
* @return float : percent of used credits * @return float : percent of used credits
*/ */
public function get_usage_percentage (int $id_user, \DateTime $at): float public function get_usage_percentage(int $id_user, \DateTime $at): float
{ {
$query = ' $query = '
SELECT (consumed / (credit + additional)) AS usage_percentage SELECT (consumed / (credit + additional)) AS usage_percentage
@ -78,12 +82,14 @@ namespace models;
} }
/** /**
* Consume some credit for a user * Consume some credit for a user.
* @param int $id_user : User id *
* @param int $id_user : User id
* @param int $quantity : Number of credits to consume * @param int $quantity : Number of credits to consume
*
* @return bool * @return bool
*/ */
public function consume_credit (int $id_user, int $quantity): int public function consume_credit(int $id_user, int $quantity): int
{ {
$query = ' $query = '
UPDATE quota UPDATE quota
@ -98,13 +104,11 @@ namespace models;
return (bool) $this->_run_query($query, $params, \descartes\Model::ROWCOUNT); return (bool) $this->_run_query($query, $params, \descartes\Model::ROWCOUNT);
} }
/** /**
* Get all quotas we need to send an alert for close limit to users they belongs to * Get all quotas we need to send an alert for close limit to users they belongs to
* do not return quotas when user already had an event QUOTA_LIMIT_CLOSE since quota start_date * do not return quotas when user already had an event QUOTA_LIMIT_CLOSE since quota start_date.
* @return array
*/ */
public function get_quotas_for_limit_close() : array public function get_quotas_for_limit_close(): array
{ {
$query = ' $query = '
SELECT quota.* SELECT quota.*
@ -137,10 +141,9 @@ namespace models;
/** /**
* Get all quotas we need to send an alert for limit reached to users they belongs to * Get all quotas we need to send an alert for limit reached to users they belongs to
* do not return quotas when user already had an event QUOTA_LIMIT_REACHED since quota start_date * do not return quotas when user already had an event QUOTA_LIMIT_REACHED since quota start_date.
* @return array
*/ */
public function get_quotas_for_limit_reached() : array public function get_quotas_for_limit_reached(): array
{ {
$query = ' $query = '
SELECT quota.* SELECT quota.*
@ -172,11 +175,11 @@ namespace models;
} }
/** /**
* Get list of quotas to be renewed as to a date * Get list of quotas to be renewed as to a date.
*
* @param \DateTime $at : Date to get quotas to be renewed before * @param \DateTime $at : Date to get quotas to be renewed before
* @return array
*/ */
public function get_quotas_to_be_renewed (\DateTime $at): array public function get_quotas_to_be_renewed(\DateTime $at): array
{ {
$at = $at->format('Y-m-d H:i:s'); $at = $at->format('Y-m-d H:i:s');
$where = [ $where = [

View File

@ -182,9 +182,9 @@ namespace models;
/** /**
* Return sendeds for an origin and a user since a date. * Return sendeds for an origin and a user since a date.
* *
* @param int $id_user : User id * @param int $id_user : User id
* @param string $since : Date we want messages since * @param string $since : Date we want messages since
* @param string $origin : Number who sent the message * @param string $origin : Number who sent the message
* *
* @return array * @return array
*/ */

View File

@ -234,7 +234,6 @@ namespace models;
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* Get messages scheduled after a date for a number and a user. * Get messages scheduled after a date for a number and a user.
* *

View File

@ -113,12 +113,11 @@ namespace models;
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* Return sendeds for an destination and a user since a date. * Return sendeds for an destination and a user since a date.
* *
* @param int $id_user : User id * @param int $id_user : User id
* @param string $since : Date we want messages since * @param string $since : Date we want messages since
* @param string $destination : Number who sent the message * @param string $destination : Number who sent the message
* *
* @return array * @return array

View File

@ -32,7 +32,8 @@ namespace models;
} }
/** /**
* Find user by ids * Find user by ids.
*
* @param array $ids : users ids * @param array $ids : users ids
* *
* @return array * @return array

View File

@ -19,7 +19,6 @@ namespace models;
const TYPE_QUOTA_LEVEL_ALERT = 'quota_level'; const TYPE_QUOTA_LEVEL_ALERT = 'quota_level';
const TYPE_QUOTA_REACHED = 'quota_reached'; const TYPE_QUOTA_REACHED = 'quota_reached';
/** /**
* Find all webhooks for a user and for a type of webhook. * Find all webhooks for a user and for a type of webhook.
* *