mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-22 01:16:26 +02:00
Add page and api for stats about phone sended sms
This commit is contained in:
parent
064d6fd941
commit
4f717ef849
11 changed files with 530 additions and 0 deletions
|
@ -294,6 +294,50 @@ namespace models;
|
|||
return $result[0] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of sended SMS by day and status between two dates, possibly by sending phone.
|
||||
*
|
||||
* @param int $id_user : user id
|
||||
* @param \DateTime $start_date : Date since which we want the messages
|
||||
* @param \DateTime $end_date : Date until which we want the messages
|
||||
* @param ?int $id_phone : Id of the phone to search sended for, null by default get all phones
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sended_status_stats ($id_user, $start_date, $end_date, ?int $id_phone = null)
|
||||
{
|
||||
$params = [
|
||||
'start_date' => $start_date->format('y-m-d H:i:s'),
|
||||
'end_date' => $end_date->format('y-m-d H:i:s'),
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
$query = "
|
||||
SELECT DATE_FORMAT(at, '%Y-%m-%d') as at_ymd, id_phone, status, COUNT(id) as nb
|
||||
FROM sended
|
||||
WHERE id_user = :id_user
|
||||
AND id_phone IS NOT NULL
|
||||
AND at >= :start_date
|
||||
AND at <= :end_date
|
||||
";
|
||||
|
||||
if ($id_phone)
|
||||
{
|
||||
$params['id_phone'] = $id_phone;
|
||||
$query .= "
|
||||
AND id_phone = :id_phone
|
||||
";
|
||||
}
|
||||
|
||||
$query .= "
|
||||
GROUP BY at_ymd, status, id_phone
|
||||
ORDER BY at_ymd, id_phone, status
|
||||
";
|
||||
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return table name.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue