1
0
Fork 0
mirror of https://github.com/RaspbianFrance/raspisms.git synced 2025-05-14 03:56:26 +02:00

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

@ -12,13 +12,13 @@
namespace models;
/**
* Manage bdd operations for calls
*/
* Manage bdd operations for calls.
*/
class Call extends StandardModel
{
const DIRECTION_INBOUND = 'inbound';
const DIRECTION_OUTBOUND = 'outbound';
/**
* Return a list of call for a user.
* 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
*
* @param int $id_user : user id
* Get a call for a user by his phone and uid.
*
* @param int $id_user : user 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
*/

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 string $type : Event type we want
* @param \DateTime $since : Date to get events since
* @param ?\DateTime $until (optional) : Date until wich we want events, if not specified no limit
* @param int $id_user : User id
* @param string $type : Event type we want
* @param \DateTime $since : Date to get events since
* @param ?\DateTime $until (optional) : Date until wich we want events, if not specified no limit
*
* @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 = [
'id_user' => $id_user,
@ -44,7 +44,7 @@ namespace models;
'>=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');
}

View file

@ -39,7 +39,7 @@ namespace models;
return $this->_run_query($query, $params);
}
/**
* Return all medias for a sended.
*
@ -63,7 +63,7 @@ namespace models;
return $this->_run_query($query, $params);
}
/**
* Return all medias for a received.
*
@ -87,16 +87,16 @@ namespace models;
return $this->_run_query($query, $params);
}
/**
* Link a media to a scheduled
*
* @param int $id_media : Media id
* Link a media to a scheduled.
*
* @param int $id_media : Media id
* @param int $id_scheduled : Scheduled id
*
* @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 = [
'id_media' => $id_media,
@ -105,16 +105,16 @@ namespace models;
return $this->_insert('media_scheduled', $entry) ? $this->_last_id() : false;
}
/**
* Link a media to a received
*
* @param int $id_media : Media id
* Link a media to a received.
*
* @param int $id_media : Media id
* @param int $id_received : Scheduled id
*
* @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 = [
'id_media' => $id_media,
@ -123,16 +123,16 @@ namespace models;
return $this->_insert('media_received', $entry) ? $this->_last_id() : false;
}
/**
* Link a media to a sended
*
* @param int $id_media : Media id
* Link a media to a sended.
*
* @param int $id_media : Media id
* @param int $id_sended : Scheduled id
*
* @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 = [
'id_media' => $id_media,
@ -141,16 +141,16 @@ namespace models;
return $this->_insert('media_sended', $entry) ? $this->_last_id() : false;
}
/**
* Unlink a media of a scheduled
*
* @param int $id_media : Media id
* Unlink a media of a scheduled.
*
* @param int $id_media : Media id
* @param int $id_scheduled : Scheduled id
*
* @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 = [
'id_media' => $id_media,
@ -161,14 +161,14 @@ namespace models;
}
/**
* Unlink a media of a received
*
* @param int $id_media : Media id
* Unlink a media of a received.
*
* @param int $id_media : Media id
* @param int $id_received : Scheduled id
*
* @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 = [
'id_media' => $id_media,
@ -177,16 +177,16 @@ namespace models;
return $this->_delete('media_received', $where);
}
/**
* Unlink a media of a sended
*
* @param int $id_media : Media id
* Unlink a media of a sended.
*
* @param int $id_media : Media id
* @param int $id_sended : Scheduled id
*
* @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 = [
'id_media' => $id_media,
@ -195,16 +195,15 @@ namespace models;
return $this->_delete('media_sended', $where);
}
/**
* Unlink all medias of a scheduled
*
* Unlink all medias of a scheduled.
*
* @param int $id_scheduled : Scheduled id
*
* @return bool | int
*/
public function delete_all_for_scheduled (int $id_scheduled)
public function delete_all_for_scheduled(int $id_scheduled)
{
$where = [
'id_scheduled' => $id_scheduled,
@ -212,15 +211,15 @@ namespace models;
return $this->_delete('media_scheduled', $where);
}
/**
* Unlink all medias of a received
*
* Unlink all medias of a received.
*
* @param int $id_received : Scheduled id
*
* @return bool | int
*/
public function delete_all_for_received (int $id_received)
public function delete_all_for_received(int $id_received)
{
$where = [
'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
*
* @return bool | int
*/
public function delete_all_for_sended (int $id_sended)
public function delete_all_for_sended(int $id_sended)
{
$where = [
'id_sended' => $id_sended,
@ -246,10 +245,11 @@ namespace models;
}
/**
* Find all unused medias
* Find all unused medias.
*
* @return array
*/
public function gets_unused ()
public function gets_unused()
{
$query = '
SELECT `media`.*
@ -264,7 +264,7 @@ namespace models;
AND `media_received`.id IS NULL
AND `media_scheduled`.id IS NULL
';
return $this->_run_query($query);
}

View file

@ -27,12 +27,14 @@ namespace models;
/**
* Get remaining credit for a date
* if no quota for this user return max int
* @param int $id_user : User id
* @param \DateTime $at : date to get credit at
* if no quota for this user return max int.
*
* @param int $id_user : User id
* @param \DateTime $at : date to get credit at
*
* @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 = '
SELECT (credit + additional - consumed) AS remaining_credit
@ -48,17 +50,19 @@ namespace models;
$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
* if no quota for this user return 0
* @param int $id_user : User id
* @param \DateTime $at : date to get usage percent at
* if no quota for this user return 0.
*
* @param int $id_user : User id
* @param \DateTime $at : date to get usage percent at
*
* @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 = '
SELECT (consumed / (credit + additional)) AS usage_percentage
@ -76,14 +80,16 @@ namespace models;
return (float) ($result[0]['usage_percentage'] ?? 0);
}
/**
* Consume some credit for a user
* @param int $id_user : User id
* Consume some credit for a user.
*
* @param int $id_user : User id
* @param int $quantity : Number of credits to consume
*
* @return bool
*/
public function consume_credit (int $id_user, int $quantity): int
public function consume_credit(int $id_user, int $quantity): int
{
$query = '
UPDATE quota
@ -98,13 +104,11 @@ namespace models;
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
* do not return quotas when user already had an event QUOTA_LIMIT_CLOSE since quota start_date
* @return array
* do not return quotas when user already had an event QUOTA_LIMIT_CLOSE since quota start_date.
*/
public function get_quotas_for_limit_close() : array
public function get_quotas_for_limit_close(): array
{
$query = '
SELECT quota.*
@ -131,16 +135,15 @@ namespace models;
'setting_name' => 'alert_quota_limit_close',
'event_type' => 'QUOTA_LIMIT_CLOSE',
];
return $this->_run_query($query, $params);
}
/**
* 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
* @return array
* do not return quotas when user already had an event QUOTA_LIMIT_REACHED since quota start_date.
*/
public function get_quotas_for_limit_reached() : array
public function get_quotas_for_limit_reached(): array
{
$query = '
SELECT quota.*
@ -162,21 +165,21 @@ namespace models;
AND at >= quota.start_date
) = 0;
';
$params = [
'setting_name' => 'alert_quota_limit_reached',
'event_type' => 'QUOTA_LIMIT_REACHED',
];
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
* @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');
$where = [

View file

@ -178,13 +178,13 @@ namespace models;
return $this->_run_query($query, $params);
}
/**
* 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 $origin : Number who sent the message
* @param string $origin : Number who sent the message
*
* @return array
*/

View file

@ -233,8 +233,7 @@ namespace models;
return $this->_run_query($query, $params);
}
/**
* 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 sendeds for an destination and a user since a date.
*
* @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
*
* @return array

View file

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

View file

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