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-10 00:30:29 +01:00
|
|
|
public function list($nb_entry = null, $page = null)
|
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-11-10 17:36:42 +01:00
|
|
|
* @param mixed $at
|
|
|
|
* @param mixed $text
|
|
|
|
* @param mixed $flash
|
|
|
|
* @param mixed $progress
|
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 du nouveau scheduled inséré
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-10 16:53:47 +01:00
|
|
|
public function create($at, $text, $flash = false, $progress = false, $numbers = [], $contacts_ids = [], $groups_ids = [])
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
2019-11-10 16:53:47 +01:00
|
|
|
$scheduled = [
|
2019-11-10 17:36:42 +01:00
|
|
|
'at' => $at,
|
2019-11-10 16:53:47 +01:00
|
|
|
'text' => $text,
|
|
|
|
'flash' => $flash,
|
|
|
|
'progress' => $progress,
|
|
|
|
];
|
|
|
|
|
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-11-06 20:34:26 +01:00
|
|
|
* @param mixed $id
|
2019-11-10 16:53:47 +01:00
|
|
|
* @param mixed $text
|
2019-11-06 20:34:26 +01:00
|
|
|
* @param mixed $at
|
|
|
|
* @param mixed $contact_ids
|
|
|
|
* @param mixed $flash
|
|
|
|
* @param mixed $progress
|
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-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-10 16:53:47 +01:00
|
|
|
public function update($id, $text, $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 = [
|
2019-11-06 20:34:26 +01:00
|
|
|
'at' => $at,
|
2019-11-10 16:53:47 +01:00
|
|
|
'text' => $text,
|
2019-11-06 17:22:54 +01:00
|
|
|
'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-10 16:53:47 +01:00
|
|
|
foreach ($numbers as $number)
|
2019-11-06 17:22:54 +01:00
|
|
|
{
|
2019-11-10 16:53:47 +01:00
|
|
|
$this->model_scheduled->insert_scheduled_number($id, $number);
|
2019-11-06 17:22:54 +01:00
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-11-10 16:53:47 +01:00
|
|
|
foreach ($contact_ids as $contact_id)
|
2019-11-06 17:22:54 +01:00
|
|
|
{
|
2019-11-10 16:53:47 +01:00
|
|
|
$this->model_scheduled->insert_scheduled_contact($id, $contact_id);
|
2019-11-06 17:22:54 +01:00
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-10 16:53:47 +01:00
|
|
|
foreach ($groups_ids as $group_id)
|
2019-11-06 17:22:54 +01:00
|
|
|
{
|
2019-11-10 16:53:47 +01:00
|
|
|
$this->model_scheduled->insert_scheduled_group($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
|
|
|
*/
|
2019-11-07 16:17:18 +01:00
|
|
|
public function get_numbers($id_scheduled)
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
|
|
|
//Recupération des scheduledes
|
2019-11-07 16:17:18 +01:00
|
|
|
return $this->model_scheduled->get_numbers($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
|
|
|
*/
|
2019-11-07 16:17:18 +01:00
|
|
|
public function get_contacts($id_scheduled)
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
|
|
|
//Recupération des scheduledes
|
2019-11-07 16:17:18 +01:00
|
|
|
return $this->model_scheduled->get_contacts($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-11-07 16:17:18 +01:00
|
|
|
public function get_groups($id_scheduled)
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
|
|
|
//Recupération des scheduledes
|
2019-11-07 16:17:18 +01:00
|
|
|
return $this->model_scheduled->get_groups($id_scheduled);
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
2019-11-06 20:27:16 +01:00
|
|
|
|
|
|
|
/**
|
2019-11-06 20:34:26 +01:00
|
|
|
* This function update progress status of a scheduled sms.
|
|
|
|
*
|
|
|
|
* @param bool $progress : Progress status
|
|
|
|
* @param mixed $id_scheduled
|
|
|
|
*
|
2019-11-06 20:27:16 +01:00
|
|
|
* @return int : Number of update
|
|
|
|
*/
|
2019-11-06 20:34:26 +01:00
|
|
|
public function update_progress($id_scheduled, $progress)
|
2019-11-06 20:27:16 +01:00
|
|
|
{
|
|
|
|
return $this->model_scheduled->update($id_scheduled, ['progress' => $progress]);
|
|
|
|
}
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|