2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-11-06 20:34:26 +01:00
|
|
|
/*
|
2019-11-10 17:48:54 +01:00
|
|
|
* This file is part of RaspiSMS.
|
2019-11-06 20:34:26 +01:00
|
|
|
*
|
2019-11-10 17:48:54 +01:00
|
|
|
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
|
2019-11-06 20:34:26 +01:00
|
|
|
*
|
2019-11-10 17:48:54 +01:00
|
|
|
* This source file is subject to the GPL-3.0 license that is bundled
|
2019-11-06 20:34:26 +01:00
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
namespace controllers\internals;
|
2019-10-29 18:36:25 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Classe des receivedes.
|
2019-10-29 14:57:13 +01:00
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
class Received extends \descartes\InternalController
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
private $model_received;
|
2019-11-12 17:37:20 +01:00
|
|
|
private $internal_phone;
|
2019-10-30 00:17:10 +01:00
|
|
|
|
|
|
|
public function __construct(\PDO $bdd)
|
|
|
|
{
|
|
|
|
$this->model_received = new \models\Received($bdd);
|
2019-11-12 17:37:20 +01:00
|
|
|
$this->internal_phone = new \controllers\internals\Phone($bdd);
|
2019-10-30 00:17:10 +01:00
|
|
|
}
|
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction retourne une liste des receivedes sous forme d'un tableau.
|
2019-11-12 17:37:20 +01:00
|
|
|
* @param int $id_user : user id
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param mixed(int|bool) $nb_entry : Le nombre d'entrées à retourner par page
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param mixed(int|bool) $page : Le numéro de page en cours
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return array : La liste des receivedes
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-12 17:37:20 +01:00
|
|
|
public function list($id_user, $nb_entry = null, $page = null)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
|
|
|
//Recupération des receivedes
|
2019-11-12 17:37:20 +01:00
|
|
|
$allowed_destinations = $this->internal_phone->gets_for_user($id_user);
|
|
|
|
|
|
|
|
foreach ($allowed_destinations as &$allowed_destination)
|
|
|
|
{
|
|
|
|
$allowed_destination = $allowed_destination['number'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->model_received->list_for_destinations($allowed_destinations, $nb_entry, $nb_entry * $page);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a received sms
|
|
|
|
* @param $id : received id
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get($id)
|
|
|
|
{
|
|
|
|
return $this->model_received->get($id);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-11-12 17:37:20 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction retourne une liste des receivedes sous forme d'un tableau.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param array int $ids : Les ids des entrées à retourner
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return array : La liste des receivedes
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-04 17:12:52 +01:00
|
|
|
public function gets($ids)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
|
|
|
//Recupération des receivedes
|
2019-11-04 17:12:52 +01:00
|
|
|
return $this->model_received->gets($ids);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
/**
|
2019-11-12 17:37:20 +01:00
|
|
|
* Cette fonction retourne les X dernières entrées triées par date for a user.
|
|
|
|
* @param int $id_user
|
|
|
|
* @param int $nb_entry : Nombre d'entrée à retourner ou faux pour tout
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return array : Les dernières entrées
|
|
|
|
*/
|
2019-11-12 17:37:20 +01:00
|
|
|
public function get_lasts_for_user_by_date($id_user, $nb_entry)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-12 17:37:20 +01:00
|
|
|
return $this->model_received->get_lasts_for_user_by_date($id_user, $nb_entry);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction retourne une liste des receiveds sous forme d'un tableau.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param string $origin : Le numéro depuis lequel est envoyé le message
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return array : La liste des receiveds
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
|
|
|
public function get_by_origin($origin)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->model_received->get_by_origin($origin);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Récupère les Sms reçus depuis une date.
|
2019-10-30 00:17:10 +01:00
|
|
|
* @param $date : La date depuis laquelle on veux les Sms (au format 2014-10-25 20:10:05)
|
2019-11-12 17:37:20 +01:00
|
|
|
* @param int $id_user : User id
|
2019-10-30 00:17:10 +01:00
|
|
|
* @return array : Tableau avec tous les Sms depuis la date
|
2019-10-29 14:57:13 +01:00
|
|
|
*/
|
2019-11-12 17:37:20 +01:00
|
|
|
public function get_since_by_date_for_user($date, $id_user)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-12 17:37:20 +01:00
|
|
|
return $this->model_received->get_since_by_date_for_user($date, $id_user);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Récupère les Sms reçus depuis une date pour un numero.
|
|
|
|
*
|
2019-10-30 00:17:10 +01:00
|
|
|
* @param $date : La date depuis laquelle on veux les Sms (au format 2014-10-25 20:10:05)
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param $number : Le numéro
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-30 00:17:10 +01:00
|
|
|
* @return array : Tableau avec tous les Sms depuis la date
|
2019-10-29 14:57:13 +01:00
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
public function get_since_for_number_by_date($date, $number)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->model_received->get_since_for_number_by_date($date, $number);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction va supprimer une liste de receiveds.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param array $ids : Les id des receivedes à supprimer
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param mixed $id
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return int : Le nombre de receivedes supprimées;
|
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
public function delete($id)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-04 17:12:52 +01:00
|
|
|
return $this->model_received->delete($id);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction insert une nouvelle receivede.
|
|
|
|
*
|
2019-11-10 17:36:42 +01:00
|
|
|
* @param array $received : Un tableau représentant la receivede à insérer
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param mixed $at
|
|
|
|
* @param mixed $origin
|
|
|
|
* @param mixed $content
|
2019-11-10 17:00:21 +01:00
|
|
|
* @param mixed $command
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle receivede insérée
|
|
|
|
*/
|
2019-11-10 17:00:21 +01:00
|
|
|
public function create($at, $origin, $content, $command)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
|
|
|
$received = [
|
|
|
|
'at' => $at,
|
|
|
|
'origin' => $origin,
|
|
|
|
'content' => $content,
|
2019-11-10 17:00:21 +01:00
|
|
|
'command' => $command,
|
2019-10-29 14:57:13 +01:00
|
|
|
];
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->model_received->create($received);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction met à jour une série de receivedes.
|
|
|
|
*
|
|
|
|
* @param mixed $id
|
|
|
|
* @param mixed $at
|
|
|
|
* @param mixed $origin
|
|
|
|
* @param mixed $content
|
2019-11-10 17:00:21 +01:00
|
|
|
* @param mixed $command
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return int : le nombre de ligne modifiées
|
|
|
|
*/
|
2019-11-10 17:00:21 +01:00
|
|
|
public function update($id, $at, $origin, $content, $command)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
|
|
|
$received = [
|
|
|
|
'at' => $at,
|
|
|
|
'origin' => $origin,
|
|
|
|
'content' => $content,
|
2019-11-10 17:00:21 +01:00
|
|
|
'command' => $command,
|
2019-10-29 14:57:13 +01:00
|
|
|
];
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->model_received->update($id, $received);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-12 17:37:20 +01:00
|
|
|
* Count number of received sms for user
|
|
|
|
* @param int $id_user : user id
|
|
|
|
* @return int : Number of received SMS for user
|
2019-10-29 14:57:13 +01:00
|
|
|
*/
|
2019-11-12 17:37:20 +01:00
|
|
|
public function count($id_user)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-12 17:37:20 +01:00
|
|
|
return $this->model_received->count($id_user);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction compte le nombre de receiveds par jour depuis une date.
|
|
|
|
*
|
2019-11-12 17:37:20 +01:00
|
|
|
* @param int $id_user : user id
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param mixed $date
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return array : un tableau avec en clef la date et en valeure le nombre de sms envoyés
|
|
|
|
*/
|
2019-11-12 17:37:20 +01:00
|
|
|
public function count_for_user_by_day_since($id_user, $date)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-12 17:37:20 +01:00
|
|
|
$counts_by_day = $this->model_received->count_for_user_by_day_since($id_user, $date);
|
2019-10-29 14:57:13 +01:00
|
|
|
$return = [];
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
foreach ($counts_by_day as $count_by_day)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$return[$count_by_day['at_ymd']] = $count_by_day['nb'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction retourne les discussions avec un numéro.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return array : Un tableau avec la date de l'échange et le numéro de la personne
|
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
public function get_discussions()
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->model_received->get_discussions();
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
}
|