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-11-12 17:37:20 +01:00
|
|
|
* Classe des scheduleds.
|
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-11-12 17:37:20 +01:00
|
|
|
* Cette fonction retourne une liste des scheduleds sous forme d'un tableau.
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
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-11-12 17:37:20 +01:00
|
|
|
* @return array : La liste des scheduleds
|
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 18:36:25 +01:00
|
|
|
{
|
2019-11-12 17:37:20 +01:00
|
|
|
//Recupération des scheduleds
|
|
|
|
return $this->model_scheduled->list($id_user, $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-11-12 17:37:20 +01:00
|
|
|
* Cette fonction retourne une liste des scheduleds sous forme d'un tableau.
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
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-11-12 17:37:20 +01:00
|
|
|
* @return array : La liste des scheduleds
|
|
|
|
*/
|
|
|
|
public function get ($id)
|
|
|
|
{
|
|
|
|
//Recupération des scheduleds
|
|
|
|
return $this->model_scheduled->get($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction retourne une liste des scheduleds sous forme d'un tableau.
|
|
|
|
*
|
|
|
|
* @param array int $ids : Les ids des entrées à retourner
|
|
|
|
*
|
|
|
|
* @return array : La liste des scheduleds
|
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
|
|
|
{
|
2019-11-12 17:37:20 +01:00
|
|
|
//Recupération des scheduleds
|
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-11-12 17:37:20 +01:00
|
|
|
* @param int $id_user : User id
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return int : Le nombre d'entrées dans la table
|
|
|
|
*/
|
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_scheduled->count($id_user);
|
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-11-12 17:37:20 +01:00
|
|
|
* @return int : Le nombre de scheduleds 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_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.
|
2019-11-12 17:37:20 +01:00
|
|
|
* @param int $id_user
|
2019-11-10 17:36:42 +01:00
|
|
|
* @param mixed $at
|
|
|
|
* @param mixed $text
|
2019-11-12 17:37:20 +01:00
|
|
|
* @param mixed $origin
|
2019-11-10 17:36:42 +01:00
|
|
|
* @param mixed $flash
|
|
|
|
* @param mixed $progress
|
2019-11-12 17:37:20 +01:00
|
|
|
* @param array $numbers : Les numéros auxquels envoyer le scheduled
|
|
|
|
* @param array $contacts_ids : Les ids des contact auquels envoyer le scheduled
|
|
|
|
* @param array $groups_ids : Les ids des group auxquels envoyer le scheduled
|
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-12 17:37:20 +01:00
|
|
|
public function create($id_user, $at, $text, $origin = null, $flash = 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-12 17:37:20 +01:00
|
|
|
'id_user' => $id_user,
|
2019-11-10 17:36:42 +01:00
|
|
|
'at' => $at,
|
2019-11-10 16:53:47 +01:00
|
|
|
'text' => $text,
|
2019-11-12 17:37:20 +01:00
|
|
|
'origin' => $origin,
|
2019-11-10 16:53:47 +01:00
|
|
|
'flash' => $flash,
|
|
|
|
];
|
|
|
|
|
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-11-12 17:37:20 +01:00
|
|
|
* Cette fonction met à jour une série de scheduleds.
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-11-06 20:34:26 +01:00
|
|
|
* @param mixed $id
|
2019-11-12 17:37:20 +01:00
|
|
|
* @param int $id_user : User id
|
2019-11-10 16:53:47 +01:00
|
|
|
* @param mixed $text
|
2019-11-06 20:34:26 +01:00
|
|
|
* @param mixed $at
|
2019-11-12 17:37:20 +01:00
|
|
|
* @param mixed $origin
|
|
|
|
* @param array $numbers : Les numéros auxquels envoyer le scheduled
|
|
|
|
* @param array $contacts_ids : Les ids des contact auquels envoyer le scheduled
|
|
|
|
* @param array $groups_ids : Les ids des group auxquels envoyer le scheduled
|
2019-11-06 20:34:26 +01:00
|
|
|
* @param mixed $flash
|
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-12 17:37:20 +01:00
|
|
|
public function update($id, $id_user, $at, $text, $origin = null, $flash = false, $numbers = [], $contacts_ids = [], $groups_ids = [])
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-06 17:22:54 +01:00
|
|
|
$scheduled = [
|
2019-11-12 17:37:20 +01:00
|
|
|
'id_user' => $id_user,
|
2019-11-06 20:34:26 +01:00
|
|
|
'at' => $at,
|
2019-11-10 16:53:47 +01:00
|
|
|
'text' => $text,
|
2019-11-12 17:37:20 +01:00
|
|
|
'origin' => $origin,
|
2019-11-06 17:22:54 +01:00
|
|
|
'flash' => $flash,
|
|
|
|
];
|
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-12 17:37:20 +01:00
|
|
|
foreach ($contacts_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-11-12 17:37:20 +01:00
|
|
|
* @return array : La liste des scheduleds
|
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
|
|
|
{
|
2019-11-12 17:37:20 +01:00
|
|
|
//Recupération des scheduleds
|
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
|
|
|
{
|
2019-11-12 17:37:20 +01:00
|
|
|
//Recupération des scheduleds
|
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
|
|
|
{
|
2019-11-12 17:37:20 +01:00
|
|
|
//Recupération des scheduleds
|
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
|
|
|
}
|