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

@ -125,9 +125,9 @@ namespace adapters;
{ {
return false; return false;
} }
/** /**
* 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,24 +135,24 @@ 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
{ {
return false; return false;
} }
public static function meta_support_inbound_call_callback(): bool public static function meta_support_inbound_call_callback(): bool
{ {
return false; return false;
} }
public static function meta_support_end_call_callback(): bool public static function meta_support_end_call_callback(): bool
{ {
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,
@ -230,12 +230,12 @@ namespace adapters;
{ {
return true; return true;
} }
public function inbound_call_callback(): array public function inbound_call_callback(): array
{ {
return []; return [];
} }
public function end_call_callback(): array public function end_call_callback(): array
{ {
return []; return [];

View File

@ -135,9 +135,9 @@ namespace adapters;
{ {
return false; return false;
} }
/** /**
* 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,24 +145,24 @@ 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
{ {
return false; return false;
} }
public static function meta_support_inbound_call_callback(): bool public static function meta_support_inbound_call_callback(): bool
{ {
return false; return false;
} }
public static function meta_support_end_call_callback(): bool public static function meta_support_end_call_callback(): bool
{ {
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,
@ -306,12 +306,12 @@ namespace adapters;
{ {
return []; return [];
} }
public function inbound_call_callback(): array public function inbound_call_callback(): array
{ {
return []; return [];
} }
public function end_call_callback(): array public function end_call_callback(): array
{ {
return []; return [];

View File

@ -172,9 +172,9 @@ class OctopushShortcodeAdapter implements AdapterInterface
{ {
return true; return true;
} }
/** /**
* 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,24 +182,24 @@ 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
{ {
return false; return false;
} }
public static function meta_support_inbound_call_callback(): bool public static function meta_support_inbound_call_callback(): bool
{ {
return false; return false;
} }
public static function meta_support_end_call_callback(): bool public static function meta_support_end_call_callback(): bool
{ {
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,
@ -417,12 +417,12 @@ class OctopushShortcodeAdapter implements AdapterInterface
return $response; return $response;
} }
public function inbound_call_callback(): array public function inbound_call_callback(): array
{ {
return []; return [];
} }
public function end_call_callback(): array public function end_call_callback(): array
{ {
return []; return [];

View File

@ -177,9 +177,9 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
{ {
return true; return true;
} }
/** /**
* 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,24 +187,24 @@ 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
{ {
return false; return false;
} }
public static function meta_support_inbound_call_callback(): bool public static function meta_support_inbound_call_callback(): bool
{ {
return false; return false;
} }
public static function meta_support_end_call_callback(): bool public static function meta_support_end_call_callback(): bool
{ {
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,
@ -417,12 +417,12 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
return $response; return $response;
} }
public function inbound_call_callback(): array public function inbound_call_callback(): array
{ {
return []; return [];
} }
public function end_call_callback(): array public function end_call_callback(): array
{ {
return []; return [];

View File

@ -169,9 +169,9 @@ namespace adapters;
{ {
return false; return false;
} }
/** /**
* 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,24 +179,24 @@ 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
{ {
return false; return false;
} }
public static function meta_support_inbound_call_callback(): bool public static function meta_support_inbound_call_callback(): bool
{ {
return false; return false;
} }
public static function meta_support_end_call_callback(): bool public static function meta_support_end_call_callback(): bool
{ {
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,
@ -369,12 +369,12 @@ namespace adapters;
{ {
return []; return [];
} }
public function inbound_call_callback(): array public function inbound_call_callback(): array
{ {
return []; return [];
} }
public function end_call_callback(): array public function end_call_callback(): array
{ {
return []; return [];

View File

@ -180,9 +180,9 @@ namespace adapters;
{ {
return false; return false;
} }
/** /**
* 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,24 +190,24 @@ 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
{ {
return false; return false;
} }
public static function meta_support_inbound_call_callback(): bool public static function meta_support_inbound_call_callback(): bool
{ {
return false; return false;
} }
public static function meta_support_end_call_callback(): bool public static function meta_support_end_call_callback(): bool
{ {
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,
@ -368,12 +368,12 @@ namespace adapters;
{ {
return []; return [];
} }
public function inbound_call_callback(): array public function inbound_call_callback(): array
{ {
return []; return [];
} }
public function end_call_callback(): array public function end_call_callback(): array
{ {
return []; return [];

View File

@ -130,9 +130,9 @@ namespace adapters;
{ {
return false; return false;
} }
/** /**
* 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,24 +140,24 @@ 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
{ {
return true; return true;
} }
public static function meta_support_inbound_call_callback(): bool public static function meta_support_inbound_call_callback(): bool
{ {
return true; return true;
} }
public static function meta_support_end_call_callback(): bool public static function meta_support_end_call_callback(): bool
{ {
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,8 +194,8 @@ namespace adapters;
* "mms" : true, * "mms" : true,
* "origin" : "+33612345678", * "origin" : "+33612345678",
* "text" : "SMS Text" * "text" : "SMS Text"
* } * }.
*/ */
public function read(): array public function read(): array
{ {
$response = [ $response = [
@ -323,7 +323,7 @@ namespace adapters;
{ {
return []; return [];
} }
public function inbound_call_callback(): array public function inbound_call_callback(): array
{ {
$response = [ $response = [
@ -352,7 +352,7 @@ namespace adapters;
return $response; return $response;
} }
public function end_call_callback(): array public function end_call_callback(): array
{ {
$response = [ $response = [

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,24 +184,24 @@ 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
{ {
return false; return false;
} }
public static function meta_support_inbound_call_callback(): bool public static function meta_support_inbound_call_callback(): bool
{ {
return false; return false;
} }
public static function meta_support_end_call_callback(): bool public static function meta_support_end_call_callback(): bool
{ {
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,
@ -346,12 +346,12 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
{ {
return []; return [];
} }
public function inbound_call_callback(): array public function inbound_call_callback(): array
{ {
return []; return [];
} }
public function end_call_callback(): array public function end_call_callback(): array
{ {
return []; return [];

View File

@ -118,8 +118,8 @@ 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)
break; {
return false;
case \models\Call::DIRECTION_INBOUND : }
if (null === $origin) { return false; }
break; break;
default : case \models\Call::DIRECTION_INBOUND:
if (null === $origin)
{
return false;
}
break;
default:
return false; return false;
} }
@ -75,7 +83,7 @@ namespace controllers\internals;
{ {
return false; return false;
} }
$new_call_id = $this->get_model()->insert($call); $new_call_id = $this->get_model()->insert($call);
if (!$new_call_id) if (!$new_call_id)
{ {
@ -83,21 +91,20 @@ namespace controllers\internals;
} }
$call['id'] = $new_call_id; $call['id'] = $new_call_id;
$internal_webhook = new Webhook($this->bdd); $internal_webhook = new Webhook($this->bdd);
$internal_webhook->trigger($id_user, \models\Webhook::TYPE_INBOUND_CALL, $call); $internal_webhook->trigger($id_user, \models\Webhook::TYPE_INBOUND_CALL, $call);
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
*/ */
@ -125,7 +132,7 @@ namespace controllers\internals;
return (bool) $this->get_model()->update_for_user($id_user, $call['id'], $datas); return (bool) $this->get_model()->update_for_user($id_user, $call['id'], $datas);
} }
/** /**
* Get the model for the Controller. * Get the model for the Controller.
*/ */

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,23 +174,23 @@ 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()
{ {
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8'); $bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
$internal_quota = new \controllers\internals\Quota($bdd); $internal_quota = new \controllers\internals\Quota($bdd);
$internal_quota->alerting_for_limit_close_and_reached(); $internal_quota->alerting_for_limit_close_and_reached();
} }
/** /**
* Do quota renewal * Do quota renewal.
*/ */
public function renew_quotas() public function renew_quotas()
{ {
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8'); $bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');

View File

@ -55,20 +55,20 @@ namespace controllers\internals;
return $this->get_model()->insert($event); return $this->get_model()->insert($event);
} }
/** /**
* 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
@ -33,13 +33,13 @@ class Media extends StandardController
{ {
throw new \Exception('File ' . $tmpfile_path . ' does not exists.'); throw new \Exception('File ' . $tmpfile_path . ' does not exists.');
} }
if (!is_readable($tmpfile_path)) if (!is_readable($tmpfile_path))
{ {
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;
@ -60,7 +60,7 @@ class Media extends StandardController
{ {
throw new \Exception('Cannot give file ' . $new_file_path . ' to user : ' . fileowner($user_path)); throw new \Exception('Cannot give file ' . $new_file_path . ' to user : ' . fileowner($user_path));
} }
if (!chgrp($new_file_path, filegroup($user_path))) if (!chgrp($new_file_path, filegroup($user_path)))
{ {
throw new \Exception('Cannot give file ' . $new_file_path . ' to group : ' . filegroup($user_path)); throw new \Exception('Cannot give file ' . $new_file_path . ' to group : ' . filegroup($user_path));
@ -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 int $id_user : Id of the user
* @param array $file : array representing uploaded file, extracted from $_FILES['yourfile'] * @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']);
} }
@ -110,15 +111,16 @@ class Media extends StandardController
{ {
throw new \Exception('Cannot move uploaded file to : ' . $tmp_file); throw new \Exception('Cannot move uploaded file to : ' . $tmp_file);
} }
return $this->create($id_user, $tmp_file, $upload_result['extension']); return $this->create($id_user, $tmp_file, $upload_result['extension']);
} }
/** /**
* 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,68 +96,71 @@ 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()
{ {
$internal_user = new User($this->bdd); $internal_user = new User($this->bdd);
$internal_event = new Event($this->bdd); $internal_event = new Event($this->bdd);
$quotas_limit_close = $this->get_model()->get_quotas_for_limit_close(); $quotas_limit_close = $this->get_model()->get_quotas_for_limit_close();
$quotas_limit_reached = $this->get_model()->get_quotas_for_limit_reached(); $quotas_limit_reached = $this->get_model()->get_quotas_for_limit_reached();
@ -173,14 +180,15 @@ 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.');
} }
foreach ($quotas_limit_reached as $quota) foreach ($quotas_limit_reached as $quota)
{ {
$user = $internal_user->get($quota['id_user']); $user = $internal_user->get($quota['id_user']);
@ -197,24 +205,25 @@ 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);
$quotas = $this->get_model()->get_quotas_to_be_renewed(new \DateTime()); $quotas = $this->get_model()->get_quotas_to_be_renewed(new \DateTime());
foreach ($quotas as $quota) foreach ($quotas as $quota)
{ {
$user = $internal_user->get($quota['id_user']); $user = $internal_user->get($quota['id_user']);
@ -228,10 +237,10 @@ class Quota extends StandardController
$unused_additional = $unused_credit > 0 ? $quota['additional'] : $quota['additional'] + $unused_credit; $unused_additional = $unused_credit > 0 ? $quota['additional'] : $quota['additional'] + $unused_credit;
$renew_interval = $quota['renew_interval'] ?? 'P0D'; $renew_interval = $quota['renew_interval'] ?? 'P0D';
$new_start_date = new \DateTime($quota['expiration_date']); $new_start_date = new \DateTime($quota['expiration_date']);
$new_expiration_date = clone $new_start_date; $new_expiration_date = clone $new_start_date;
$new_expiration_date->add(new \DateInterval($quota['renew_interval'])); $new_expiration_date->add(new \DateInterval($quota['renew_interval']));
$report = 0; $report = 0;
if ($quota['report_unused'] && $unused_credit > 0) if ($quota['report_unused'] && $unused_credit > 0)
{ {
@ -254,21 +263,22 @@ 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.');
} }
} }
/** /**
* Return the quota for a user if it exists. * Return the quota for a user if it exists.
* *
* @param int $id_user : user id * @param int $id_user : user id
* *
* @return array * @return array
*/ */
public function get_user_quota(int $id_user) public function get_user_quota(int $id_user)
{ {

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
@ -285,7 +288,7 @@ namespace controllers\internals;
$is_command = true; $is_command = true;
$text = $response; $text = $response;
} }
//We create medias to link to the sms //We create medias to link to the sms
$internal_media = new Media($this->bdd); $internal_media = new Media($this->bdd);
$media_ids = []; $media_ids = [];
@ -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;
} }
} }
@ -254,7 +256,7 @@ namespace controllers\internals;
{ {
return $this->get_model()->gets_before_date_for_number_and_user($id_user, $date, $number); return $this->get_model()->gets_before_date_for_number_and_user($id_user, $date, $number);
} }
/** /**
* Get messages scheduled after a date for a number and a user. * Get messages scheduled after a date for a number and a user.
* *
@ -349,7 +351,7 @@ namespace controllers\internals;
$random_phone = $users_phones[$scheduled['id_user']][$rnd_key]; $random_phone = $users_phones[$scheduled['id_user']][$rnd_key];
} }
} }
$message = [ $message = [
'id_user' => $scheduled['id_user'], 'id_user' => $scheduled['id_user'],
'id_scheduled' => $scheduled['id'], 'id_scheduled' => $scheduled['id'],
@ -405,7 +407,7 @@ namespace controllers\internals;
} }
$added_contacts[$contact['id']] = true; $added_contacts[$contact['id']] = true;
if (null === $phone_to_use) if (null === $phone_to_use)
{ {
if ($scheduled['mms'] && count($users_mms_phones)) if ($scheduled['mms'] && count($users_mms_phones))

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
@ -49,14 +49,15 @@ namespace controllers\internals;
//Ensure atomicity //Ensure atomicity
$this->bdd->beginTransaction(); $this->bdd->beginTransaction();
$id_sended = $this->get_model()->insert($sended); $id_sended = $this->get_model()->insert($sended);
if (!$id_sended) if (!$id_sended)
{ {
$this->bdd->rollback(); $this->bdd->rollback();
return false; return false;
} }
//Link medias //Link medias
$internal_media = new Media($this->bdd); $internal_media = new Media($this->bdd);
foreach ($medias as $media) foreach ($medias as $media)
@ -132,13 +133,14 @@ namespace controllers\internals;
{ {
return $this->get_model()->gets_by_destination_and_user($id_user, $origin); return $this->get_model()->gets_by_destination_and_user($id_user, $origin);
} }
/** /**
* Return sendeds for a destination and a user since a date. * Return sendeds for a 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 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

@ -164,11 +164,11 @@ namespace controllers\internals;
return $objectDate && $objectDate->format($format) === $date; return $objectDate && $objectDate->format($format) === $date;
} }
/** /**
* 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
@ -206,15 +206,16 @@ namespace controllers\internals;
$current_quota = $internal_quota->get_user_quota($id); $current_quota = $internal_quota->get_user_quota($id);
$this->bdd->beginTransaction(); $this->bdd->beginTransaction();
$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;
@ -355,9 +352,9 @@ namespace controllers\internals;
} }
$mailer = new Mailer(); $mailer = new Mailer();
$attachments = []; $attachments = [];
foreach ($received['medias'] ?? [] as $media) foreach ($received['medias'] ?? [] as $media)
{ {
$attachments[] = PWD_DATA_PUBLIC . '/' . $media['path']; $attachments[] = PWD_DATA_PUBLIC . '/' . $media['path'];

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)
@ -320,8 +320,8 @@ namespace controllers\publics;
if ($id_phone) if ($id_phone)
{ {
$phone = $this->internal_phone->get_for_user($this->user['id'], $id_phone); $phone = $this->internal_phone->get_for_user($this->user['id'], $id_phone);
} }
if ($id_phone && !$phone) if ($id_phone && !$phone)
{ {
$return = self::DEFAULT_RETURN; $return = self::DEFAULT_RETURN;

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

@ -206,13 +206,12 @@ 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
*/ */
@ -269,16 +268,15 @@ use Monolog\Logger;
} }
$this->logger->info('Callback inbound_call successfully received inbound call : ' . json_encode($call)); $this->logger->info('Callback inbound_call successfully received inbound call : ' . json_encode($call));
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
*/ */
@ -334,7 +332,7 @@ use Monolog\Logger;
} }
$this->logger->info('Callback end call successfully update call : ' . json_encode($call)); $this->logger->info('Callback end call successfully update call : ' . json_encode($call));
return true; return true;
} }
} }

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

@ -85,12 +85,12 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Contact', 'list')); return $this->redirect(\descartes\Router::url('Contact', 'list'));
} }
/** /**
* 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,14 +62,13 @@ 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);
$events = $this->internal_event->get_lasts_by_date_for_user($id_user, 10); $events = $this->internal_event->get_lasts_by_date_for_user($id_user, 10);
//Récupération du nombre de Sms envoyés et reçus depuis 1 mois jours ou depuis le début du quota si il existe //Récupération du nombre de Sms envoyés et reçus depuis 1 mois jours ou depuis le début du quota si il existe
//Création de la date d'il y a 30 jours //Création de la date d'il y a 30 jours
$now = new \DateTime(); $now = new \DateTime();
$one_month = new \DateInterval('P1M'); $one_month = new \DateInterval('P1M');
@ -107,7 +106,7 @@ namespace controllers\publics;
'sendeds' => 0, 'sendeds' => 0,
'receiveds' => 0, 'receiveds' => 0,
]; ];
$date->add($one_day); $date->add($one_day);
} }

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;
} }
@ -143,7 +142,7 @@ namespace controllers\publics;
{ {
$this->internal_received->mark_as_read_for_user($id_user, $received['id']); $this->internal_received->mark_as_read_for_user($id_user, $received['id']);
} }
$medias = []; $medias = [];
if ($received['mms']) if ($received['mms'])
{ {
@ -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
*/ */
@ -237,9 +236,9 @@ namespace controllers\publics;
$destination = $_POST['destination'] ?? false; $destination = $_POST['destination'] ?? false;
$id_phone = $_POST['id_phone'] ?? false; $id_phone = $_POST['id_phone'] ?? false;
$files = $_FILES['medias'] ?? false; $files = $_FILES['medias'] ?? false;
//Iterate over files to re-create individual $_FILES array //Iterate over files to re-create individual $_FILES array
$files_arrays = []; $files_arrays = [];
if ($files && is_array($files['name'])) if ($files && is_array($files['name']))
{ {
foreach ($files as $property_name => $files_values) foreach ($files as $property_name => $files_values)
@ -248,7 +247,7 @@ namespace controllers\publics;
{ {
if (!isset($files_arrays[$file_key])) if (!isset($files_arrays[$file_key]))
{ {
$files_arrays[$file_key] = []; $files_arrays[$file_key] = [];
} }
$files_arrays[$file_key][$property_name] = $property_value; $files_arrays[$file_key][$property_name] = $property_value;
@ -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

@ -75,12 +75,12 @@ class Phone extends \descartes\Controller
{ {
$phone['callback_status'] = \descartes\Router::url('Callback', 'update_sended_status', ['adapter_uid' => $adapter['meta_uid']], ['api_key' => $api_key]); $phone['callback_status'] = \descartes\Router::url('Callback', 'update_sended_status', ['adapter_uid' => $adapter['meta_uid']], ['api_key' => $api_key]);
} }
if ($adapter['meta_support_inbound_call_callback']) if ($adapter['meta_support_inbound_call_callback'])
{ {
$phone['callback_inbound_call'] = \descartes\Router::url('Callback', 'inbound_call', ['id_phone' => $phone['id']], ['api_key' => $api_key]); $phone['callback_inbound_call'] = \descartes\Router::url('Callback', 'inbound_call', ['id_phone' => $phone['id']], ['api_key' => $api_key]);
} }
if ($adapter['meta_support_end_call_callback']) if ($adapter['meta_support_end_call_callback'])
{ {
$phone['callback_end_call'] = \descartes\Router::url('Callback', 'end_call', ['id_phone' => $phone['id']], ['api_key' => $api_key]); $phone['callback_end_call'] = \descartes\Router::url('Callback', 'end_call', ['id_phone' => $phone['id']], ['api_key' => $api_key]);

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)
{ {
@ -265,7 +265,7 @@ namespace controllers\publics;
$files = $_FILES['medias'] ?? false; $files = $_FILES['medias'] ?? false;
//Iterate over files to re-create individual $_FILES array //Iterate over files to re-create individual $_FILES array
$files_arrays = []; $files_arrays = [];
if ($files && is_array($files['name'])) if ($files && is_array($files['name']))
{ {
foreach ($files as $property_name => $files_values) foreach ($files as $property_name => $files_values)
@ -281,11 +281,11 @@ 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]);
} }
@ -325,7 +325,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Scheduled', 'add')); return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
} }
//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)
@ -339,15 +339,16 @@ 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'));
} }
$media_ids[] = $new_media_id; $media_ids[] = $new_media_id;
} }
} }
$mms = (bool) count($media_ids); $mms = (bool) count($media_ids);
$scheduled_id = $this->internal_scheduled->create($id_user, $at, $text, $id_phone, $flash, $mms, $numbers, $contacts, $groups, $conditional_groups, $media_ids); $scheduled_id = $this->internal_scheduled->create($id_user, $at, $text, $id_phone, $flash, $mms, $numbers, $contacts, $groups, $conditional_groups, $media_ids);
if (!$scheduled_id) if (!$scheduled_id)
{ {
@ -403,7 +404,7 @@ 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 && is_array($files['name'])) if ($files && is_array($files['name']))
{ {
foreach ($files as $property_name => $files_values) foreach ($files as $property_name => $files_values)
@ -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]);
} }
@ -456,7 +457,7 @@ namespace controllers\publics;
{ {
continue; continue;
} }
//If mms is enable and we have medias uploaded //If mms is enable and we have medias uploaded
if ($_SESSION['user']['settings']['mms'] && $files_arrays) if ($_SESSION['user']['settings']['mms'] && $files_arrays)
{ {
@ -471,7 +472,7 @@ namespace controllers\publics;
continue 2; continue 2;
} }
$media_ids[] = $new_media_id; $media_ids[] = $new_media_id;
} }
} }
@ -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

@ -58,7 +58,7 @@ class User extends \descartes\Controller
{ {
$quota_percentage = $this->internal_quota->get_usage_percentage($entity['id']); $quota_percentage = $this->internal_quota->get_usage_percentage($entity['id']);
$entity['quota_percentage'] = $quota_percentage * 100; $entity['quota_percentage'] = $quota_percentage * 100;
$quota = $this->internal_quota->get_user_quota($entity['id']); $quota = $this->internal_quota->get_user_quota($entity['id']);
if (!$quota) if (!$quota)
{ {
@ -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,15 +216,15 @@ 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.');
return $this->redirect(\descartes\Router::url('User', 'add')); return $this->redirect(\descartes\Router::url('User', 'add'));
} }
$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)
@ -263,9 +259,9 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'list')); return $this->redirect(\descartes\Router::url('User', 'list'));
} }
/** /**
* Return the edition page for the users * Return the edition page for the users.
* *
* @param int... $ids : users ids * @param int... $ids : users ids
*/ */
@ -285,7 +281,7 @@ class User extends \descartes\Controller
{ {
$user['quota'] = $this->internal_quota->get_user_quota($user['id']); $user['quota'] = $this->internal_quota->get_user_quota($user['id']);
} }
$now = new \DateTime(); $now = new \DateTime();
$now = $now->format('Y-m-d H:i:00'); $now = $now->format('Y-m-d H:i:00');
@ -294,10 +290,9 @@ class User extends \descartes\Controller
'now' => $now, 'now' => $now,
]); ]);
} }
/** /**
* 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.
@ -310,7 +305,7 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'add')); return $this->redirect(\descartes\Router::url('User', 'add'));
} }
$nb_update = 0; $nb_update = 0;
$users = $_POST['users'] ?? []; $users = $_POST['users'] ?? [];
foreach ($users as $id_user => $user) foreach ($users as $id_user => $user)
@ -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,18 +347,18 @@ 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.');
continue; continue;
} }
$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.');
continue; continue;
} }
$quota['renew_interval'] = $quota_renew_interval; $quota['renew_interval'] = $quota_renew_interval;
@ -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,
@ -397,22 +389,22 @@ class User extends \descartes\Controller
if (!$success) if (!$success)
{ {
\FlashMessage\FlashMessage::push('danger', 'L\'utilisateur #' . (int) $id_user . ' n\'as pas pu être mis à jour.'); \FlashMessage\FlashMessage::push('danger', 'L\'utilisateur #' . (int) $id_user . ' n\'as pas pu être mis à jour.');
continue; continue;
} }
$nb_update++; ++$nb_update;
} }
if ($nb_update != count($users)) if ($nb_update != count($users))
{ {
\FlashMessage\FlashMessage::push('danger', 'Certains utilisateurs n\'ont pas pu être mis à jour.'); \FlashMessage\FlashMessage::push('danger', 'Certains utilisateurs n\'ont pas pu être mis à jour.');
return $this->redirect(\descartes\Router::url('User', 'list')); return $this->redirect(\descartes\Router::url('User', 'list'));
} }
\FlashMessage\FlashMessage::push('success', 'Tous les utilisateurs ont bien été mis à jour.'); \FlashMessage\FlashMessage::push('success', 'Tous les utilisateurs ont bien été mis à jour.');
return $this->redirect(\descartes\Router::url('User', 'list')); return $this->redirect(\descartes\Router::url('User', 'list'));
} }
} }

View File

@ -12,13 +12,13 @@
namespace models; namespace models;
/** /**
* Manage bdd operations for calls * Manage bdd operations for calls.
*/ */
class Call extends StandardModel class Call extends StandardModel
{ {
const DIRECTION_INBOUND = 'inbound'; const DIRECTION_INBOUND = 'inbound';
const DIRECTION_OUTBOUND = 'outbound'; const DIRECTION_OUTBOUND = 'outbound';
/** /**
* Return a list of call for a user. * Return a list of call for a user.
* Add a column contact_name and phone_name when available. * Add a column contact_name and phone_name when available.
@ -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

@ -39,7 +39,7 @@ namespace models;
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* Return all medias for a sended. * Return all medias for a sended.
* *
@ -63,7 +63,7 @@ namespace models;
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* Return all medias for a received. * Return all medias for a received.
* *
@ -87,16 +87,16 @@ namespace models;
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* 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,
@ -105,16 +105,16 @@ namespace models;
return $this->_insert('media_scheduled', $entry) ? $this->_last_id() : false; return $this->_insert('media_scheduled', $entry) ? $this->_last_id() : false;
} }
/** /**
* 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,
@ -123,16 +123,16 @@ namespace models;
return $this->_insert('media_received', $entry) ? $this->_last_id() : false; return $this->_insert('media_received', $entry) ? $this->_last_id() : false;
} }
/** /**
* 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,
@ -141,16 +141,16 @@ namespace models;
return $this->_insert('media_sended', $entry) ? $this->_last_id() : false; return $this->_insert('media_sended', $entry) ? $this->_last_id() : false;
} }
/** /**
* 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,
@ -177,16 +177,16 @@ namespace models;
return $this->_delete('media_received', $where); return $this->_delete('media_received', $where);
} }
/** /**
* 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,
@ -195,16 +195,15 @@ 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,
@ -212,15 +211,15 @@ namespace models;
return $this->_delete('media_scheduled', $where); return $this->_delete('media_scheduled', $where);
} }
/** /**
* 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`.*
@ -264,7 +264,7 @@ namespace models;
AND `media_received`.id IS NULL AND `media_received`.id IS NULL
AND `media_scheduled`.id IS NULL AND `media_scheduled`.id IS NULL
'; ';
return $this->_run_query($query); return $this->_run_query($query);
} }

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
@ -76,14 +80,16 @@ namespace models;
return (float) ($result[0]['usage_percentage'] ?? 0); return (float) ($result[0]['usage_percentage'] ?? 0);
} }
/** /**
* 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.*
@ -131,16 +135,15 @@ namespace models;
'setting_name' => 'alert_quota_limit_close', 'setting_name' => 'alert_quota_limit_close',
'event_type' => 'QUOTA_LIMIT_CLOSE', 'event_type' => 'QUOTA_LIMIT_CLOSE',
]; ];
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* 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.*
@ -162,21 +165,21 @@ namespace models;
AND at >= quota.start_date AND at >= quota.start_date
) = 0; ) = 0;
'; ';
$params = [ $params = [
'setting_name' => 'alert_quota_limit_reached', 'setting_name' => 'alert_quota_limit_reached',
'event_type' => 'QUOTA_LIMIT_REACHED', 'event_type' => 'QUOTA_LIMIT_REACHED',
]; ];
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* 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

@ -178,13 +178,13 @@ namespace models;
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }
/** /**
* 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

@ -233,8 +233,7 @@ 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

@ -112,13 +112,12 @@ 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.
* *