2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
/*
|
2019-11-10 17:48:54 +01:00
|
|
|
* This file is part of RaspiSMS.
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-11-10 17:48:54 +01:00
|
|
|
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
|
2019-10-30 00:30:39 +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-10-30 00:30:39 +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-30 00:30:39 +01:00
|
|
|
* Classe des sendedes.
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-07 16:17:18 +01:00
|
|
|
class Sended extends \descartes\InternalController
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
private $model_sended;
|
2019-10-30 00:17:10 +01:00
|
|
|
|
|
|
|
public function __construct(\PDO $bdd)
|
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
$this->model_sended = new \models\Sended($bdd);
|
2019-10-30 00:17:10 +01:00
|
|
|
}
|
2019-10-29 18:36:25 +01:00
|
|
|
|
|
|
|
/**
|
2019-11-12 17:58:07 +01:00
|
|
|
* List sms for a user
|
|
|
|
* @param int $id_user : user id
|
|
|
|
* @param mixed(int|bool) $nb_entry : Number of entry to return
|
|
|
|
* @param mixed(int|bool) $page : Pagination, will offset $nb_entry * $page results
|
|
|
|
* @return array
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-12 17:58:07 +01:00
|
|
|
public function list($id_user, $nb_entry = null, $page = null)
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
2019-11-12 17:58:07 +01:00
|
|
|
return $this->model_sended->list_for_user($id_user, $nb_entry, $nb_entry * $page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a sended sms
|
|
|
|
* @param $id : received id
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get($id)
|
|
|
|
{
|
|
|
|
return $this->model_sended->get($id);
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction retourne une liste des sendedes 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 sendedes
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-04 17:12:52 +01:00
|
|
|
public function gets($ids)
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
|
|
|
//Recupération des sendedes
|
2019-11-07 16:17:18 +01:00
|
|
|
return $this->model_sended->gets($ids);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction retourne les X dernières entrées triées par date.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param mixed false|int $nb_entry : Nombre d'entrée à retourner ou faux pour tout
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return array : Les dernières entrées
|
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
public function get_lasts_by_date($nb_entry = false)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
return $this->model_sended->get_lasts_by_date($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 receivedes sous forme d'un tableau.
|
|
|
|
*
|
2019-11-10 17:32:59 +01:00
|
|
|
* @param string $destination : Le numéro auquel 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 sendeds
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-10 17:32:59 +01:00
|
|
|
public function get_by_destination($destination)
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
|
|
|
//Recupération des sendeds
|
2019-11-10 17:32:59 +01:00
|
|
|
return $this->model_sended->get_by_destination($destination);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction va supprimer une liste de sendeds.
|
|
|
|
*
|
2019-10-29 18:36:25 +01:00
|
|
|
* @param array $ids : Les id des sendedes à supprimer
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param mixed $id
|
|
|
|
*
|
2019-10-29 18:36:25 +01:00
|
|
|
* @return int : Le nombre de sendedes supprimées;
|
|
|
|
*/
|
|
|
|
public function delete($id)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
return $this->model_sended->delete($id);
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction insert une nouvelle sendede.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param array $sended : Un tableau représentant la sendede à insérer
|
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 sendede insérée
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
|
|
|
public function create($sended)
|
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
return $this->model_sended->create($sended);
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction permet de compter le nombre de sendeds.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return int : Le nombre d'entrées dans la table
|
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
public function count()
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
return $this->model_sended->count();
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction compte le nombre de sendeds par jour depuis une date.
|
|
|
|
*
|
|
|
|
* @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-10-29 18:36:25 +01:00
|
|
|
public function count_by_day_since($date)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
$counts_by_day = $this->model_sended->count_by_day_since($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-11-07 16:17:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrement before delivered.
|
|
|
|
*
|
|
|
|
* @param int $id_sended : id of the sended to decrement delivered for
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function decrement_before_delivered($id_sended)
|
|
|
|
{
|
|
|
|
return $this->model_sended->decrement_before_delivered($id_sended);
|
|
|
|
}
|
|
|
|
|
2019-11-10 02:04:13 +01:00
|
|
|
/**
|
2019-11-10 17:36:42 +01:00
|
|
|
* Update status.
|
|
|
|
*
|
|
|
|
* @param int $id_sended : id of the sended to mark as delivered
|
|
|
|
* @param string $status : new status
|
2019-11-10 02:04:13 +01:00
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function update_status($id_sended, $status)
|
|
|
|
{
|
|
|
|
return $this->model_sended->update($id_sended, ['status' => $status]);
|
|
|
|
}
|
2019-11-10 17:36:42 +01:00
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
/**
|
|
|
|
* Update sended to delivered.
|
|
|
|
*
|
|
|
|
* @param int $id_sended : id of the sended to mark as delivered
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function set_delivered($id_sended)
|
|
|
|
{
|
2019-11-10 02:04:13 +01:00
|
|
|
return $this->model_sended->update($id_sended, ['status' => 'delivered']);
|
2019-11-07 16:17:18 +01:00
|
|
|
}
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|