mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-06-06 06:46:25 +02:00
Update internal controllers to use standard one
This commit is contained in:
parent
25b461d611
commit
bc622285a4
16 changed files with 558 additions and 880 deletions
|
@ -26,7 +26,7 @@ namespace models;
|
|||
* @param string $number : phone number
|
||||
* @return array
|
||||
*/
|
||||
public function get_by_number_for_user (int $id_user, string $number)
|
||||
public function get_by_number_and_user (int $id_user, string $number)
|
||||
{
|
||||
return $this->_select_one('phone', ['number' => $number, 'id_user' => $id_user]);
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ namespace models;
|
|||
* @param int $id_user : user id
|
||||
* @return int : Number of received SMS for user
|
||||
*/
|
||||
public function count_for_user($id_user)
|
||||
public function count_for_user(int $id_user)
|
||||
{
|
||||
$query = '
|
||||
SELECT COUNT(id) as nb
|
||||
|
@ -178,7 +178,7 @@ namespace models;
|
|||
* @param int $nb_entry : Number of receiveds messages to return
|
||||
* @return array
|
||||
*/
|
||||
public function get_lasts_by_date_for_user($id_user, $nb_entry)
|
||||
public function get_lasts_by_date_for_user(int $id_user, int $nb_entry)
|
||||
{
|
||||
$nb_entry = (int) $nb_entry;
|
||||
|
||||
|
@ -229,7 +229,7 @@ namespace models;
|
|||
* @param \DateTime $date : Date since which we want the messages
|
||||
* @return array
|
||||
*/
|
||||
public function count_by_day_since_for_user($id_user, $date)
|
||||
public function count_by_day_since_for_user(int $id_user, $date)
|
||||
{
|
||||
$query = "
|
||||
SELECT COUNT(id) as nb, DATE_FORMAT(at, '%Y-%m-%d') as at_ymd
|
||||
|
@ -274,11 +274,11 @@ namespace models;
|
|||
|
||||
/**
|
||||
* Get SMS received since a date for a user
|
||||
* @param $date : La date depuis laquelle on veux les SMS (au format 2014-10-25 20:10:05)
|
||||
* @param int $id_user : User id
|
||||
* @param $date : La date depuis laquelle on veux les SMS (au format 2014-10-25 20:10:05)
|
||||
* @return array : Tableau avec tous les SMS depuis la date
|
||||
*/
|
||||
public function get_since_by_date_for_user($date, $id_user)
|
||||
public function get_since_by_date_for_user(int $id_user, $date)
|
||||
{
|
||||
$query = "
|
||||
SELECT *
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace models;
|
|||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_numbers($id_scheduled)
|
||||
public function get_numbers(int $id_scheduled)
|
||||
{
|
||||
return $this->_select('scheduled_number', ['id_scheduled' => $id_scheduled]);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace models;
|
|||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_contacts($id_scheduled)
|
||||
public function get_contacts(int $id_scheduled)
|
||||
{
|
||||
$query = 'SELECT * FROM contact WHERE id IN (SELECT id_contact FROM scheduled_contact WHERE id_scheduled = :id_scheduled)';
|
||||
$params = ['id_scheduled' => $id_scheduled];
|
||||
|
@ -49,7 +49,7 @@ namespace models;
|
|||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_groups($id_scheduled)
|
||||
public function get_groups(int $id_scheduled)
|
||||
{
|
||||
$query = 'SELECT * FROM `group` WHERE id IN (SELECT id_group FROM scheduled_group WHERE id_scheduled = :id_scheduled)';
|
||||
$params = ['id_scheduled' => $id_scheduled];
|
||||
|
|
|
@ -247,31 +247,6 @@ namespace models;
|
|||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all discussions (ie : numbers we have a message sended from or sended to) for a user
|
||||
* @param int $id_user : User id
|
||||
* @return array
|
||||
*/
|
||||
public function get_discussions_for_user(int $id_user)
|
||||
{
|
||||
$query = '
|
||||
SELECT at, number
|
||||
FROM (
|
||||
SELECT at, origin as number FROM sended
|
||||
WHERE destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
UNION (
|
||||
SELECT at, destination as number FROM sended
|
||||
WHERE origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
)
|
||||
) as discussions
|
||||
GROUP BY number
|
||||
ORDER BY at DESC
|
||||
';
|
||||
|
||||
$params = ['id_user' => $id_user];
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SMS sended since a date for a user
|
||||
* @param $date : La date depuis laquelle on veux les SMS (au format 2014-10-25 20:10:05)
|
||||
|
@ -295,30 +270,4 @@ namespace models;
|
|||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find messages sended since a date for a certain destination and user
|
||||
* @param int $id_user : User id
|
||||
* @param $date : Date we want messages sinces
|
||||
* @param string $destination : Origin number
|
||||
* @return array
|
||||
*/
|
||||
public function get_since_by_date_for_destination_and_user(int $id_user, $date, string $destination)
|
||||
{
|
||||
$query = "
|
||||
SELECT *
|
||||
FROM sended
|
||||
WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s')
|
||||
AND destination = :destination
|
||||
AND origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
ORDER BY at ASC
|
||||
";
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user
|
||||
'date' => $date,
|
||||
'destination' => $destination,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue