2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of PHP CS Fixer.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* 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 scheduledes.
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
|
|
|
class Scheduled extends \descartes\InternalController
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
private $model_scheduled;
|
|
|
|
private $internal_event;
|
|
|
|
|
|
|
|
public function __construct(\PDO $bdd)
|
|
|
|
{
|
|
|
|
$this->model_scheduled = new \models\Scheduled($bdd);
|
|
|
|
$this->internal_event = new \controllers\internals\Event($bdd);
|
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction retourne une liste des scheduledes sous forme d'un tableau.
|
|
|
|
*
|
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 scheduledes
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-04 17:12:52 +01:00
|
|
|
public function list($nb_entry = false, $page = false)
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
|
|
|
//Recupération des scheduledes
|
2019-11-04 17:12:52 +01:00
|
|
|
return $this->model_scheduled->list($nb_entry, $nb_entry * $page);
|
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 scheduledes 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 scheduledes
|
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 scheduledes
|
2019-11-04 17:12:52 +01:00
|
|
|
return $this->model_scheduled->gets($ids);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction retourne les messages programmés avant une date et pour un numéro.
|
|
|
|
*
|
|
|
|
* @param \DateTime $date : La date avant laquelle on veux le message
|
|
|
|
* @param string $number : Le numéro
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return array : Les messages programmés avant la date
|
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
public function get_before_date_for_number($date, $number)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->model_scheduled->get_before_date_for_number($date, $number);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction permet de compter le nombre de scheduled.
|
|
|
|
*
|
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-10-30 00:17:10 +01:00
|
|
|
return $this->model_scheduled->count();
|
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 un scheduled.
|
|
|
|
*
|
2019-10-29 18:36:25 +01:00
|
|
|
* @param int $id : L'id du scheduled à supprimer
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 18:36:25 +01:00
|
|
|
* @return int : Le nombre de scheduledes supprimées;
|
|
|
|
*/
|
|
|
|
public function delete($id)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-04 17:12:52 +01:00
|
|
|
return $this->model_scheduled->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 un nouveau scheduled.
|
|
|
|
*
|
|
|
|
* @param array $scheduled : Le scheduled à créer avec at, content, flash, progress
|
|
|
|
* @param array $numbers : Les numéros auxquels envoyer le scheduled
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param array $contacts_ids : Les ids des contact auquels envoyer le scheduled
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param array $groups_ids : Les ids des group auxquels envoyer le scheduled
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return mixed bool|int : false si echec, sinon l'id du nouveau scheduled inséré
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-10-30 00:17:10 +01:00
|
|
|
public function create($scheduled, $numbers = [], $contacts_ids = [], $groups_ids = [])
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
2019-10-30 00:30:39 +01:00
|
|
|
if (!$id_scheduled = $this->model_scheduled->insert($scheduled))
|
|
|
|
{
|
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
$this->internal_event->create('SCHEDULED_ADD', 'Ajout d\'un Sms pour le '.$date.'.');
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($numbers as $number)
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
$this->model_scheduled->insert_scheduled_number($id_scheduled, $number);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($contacts_ids as $contact_id)
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
$this->model_scheduled->insert_scheduled_contact($id_scheduled, $contact_id);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
foreach ($groups_ids as $group_id)
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
$this->model_scheduled->insert_scheduled_group($id_scheduled, $group_id);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $id_scheduled;
|
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 met à jour une série de scheduledes.
|
|
|
|
*
|
|
|
|
* @param array $scheduleds : Un tableau de scheduled à modifier avec at, content, flash, progress + pour chaque scheduled number, contact_ids, group_ids
|
|
|
|
* @param array $numbers : Les numéros auxquels envoyer le scheduled
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param array $contacts_ids : Les ids des contact auquels envoyer le scheduled
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param array $groups_ids : Les ids des group auxquels envoyer le scheduled
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return int : le nombre de ligne modifiées
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-06 17:22:54 +01:00
|
|
|
public function update($id, $content, $at, $numbers = [], $contact_ids = [], $groups_ids = [], $flash = false, $progress = false)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-06 17:22:54 +01:00
|
|
|
$scheduled = [
|
|
|
|
'at' => $date,
|
|
|
|
'content' => $content,
|
|
|
|
'flash' => $flash,
|
|
|
|
'progress' => $progress,
|
|
|
|
];
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-06 17:22:54 +01:00
|
|
|
$success = $this->model_scheduled->update($id, $scheduled);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-06 17:22:54 +01:00
|
|
|
$this->model_scheduled->delete_scheduled_numbers($id);
|
|
|
|
$this->model_scheduled->delete_scheduled_contacts($id);
|
|
|
|
$this->model_scheduled->delete_scheduled_groups($id);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-06 17:22:54 +01:00
|
|
|
foreach ($scheduled['number'] as $number)
|
|
|
|
{
|
|
|
|
$this->model_scheduled->insert_scheduled_number($scheduled['scheduled']['id'], $number);
|
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-11-06 17:22:54 +01:00
|
|
|
foreach ($scheduled['contact_ids'] as $contact_id)
|
|
|
|
{
|
|
|
|
$this->model_scheduled->insert_scheduled_contact($scheduled['scheduled']['id'], $contact_id);
|
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-06 17:22:54 +01:00
|
|
|
foreach ($scheduled['group_ids'] as $group_id)
|
|
|
|
{
|
|
|
|
$this->model_scheduled->insert_scheduled_group($scheduled['scheduled']['id'], $group_id);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-11-06 17:22:54 +01:00
|
|
|
return (bool) $success;
|
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 de numéro pour un scheduled.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param int $id_scheduled : L'id du scheduled pour lequel on veux le numéro
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return array : La liste des scheduledes
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
|
|
|
public function get_number($id_scheduled)
|
|
|
|
{
|
|
|
|
//Recupération des scheduledes
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->model_scheduled->get_number($id_scheduled);
|
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 retourne une liste de contact pour un scheduled.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param int $id_scheduled : L'id du scheduled pour lequel on veux le numéro
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return array : La liste des contact
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
|
|
|
public function get_contact($id_scheduled)
|
|
|
|
{
|
|
|
|
//Recupération des scheduledes
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->model_scheduled->get_contact($id_scheduled);
|
2019-10-29 18:36:25 +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 de group pour un scheduled.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param int $id_scheduled : L'id du scheduled pour lequel on veux le numéro
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-30 00:17:10 +01:00
|
|
|
* @return array : La liste des group
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-10-30 00:17:10 +01:00
|
|
|
public function get_group($id_scheduled)
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
|
|
|
//Recupération des scheduledes
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->model_scheduled->get_group($id_scheduled);
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
2019-11-06 20:27:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function update progress status of a scheduled sms
|
|
|
|
* @param bool $progress : Progress status
|
|
|
|
* @return int : Number of update
|
|
|
|
*/
|
|
|
|
public function update_progress ($id_scheduled, $progress)
|
|
|
|
{
|
|
|
|
return $this->model_scheduled->update($id_scheduled, ['progress' => $progress]);
|
|
|
|
}
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|