From c6050f06aa443394c7f9ea5aa5864b4f4d4de518 Mon Sep 17 00:00:00 2001 From: osaajani Date: Thu, 7 Nov 2019 16:17:18 +0100 Subject: [PATCH] Add transfer controller and model, remove database model and transfer responsabilities --- controllers/internals/Command.php | 11 ++ controllers/internals/Console.php | 87 +++++------ controllers/internals/Scheduled.php | 12 +- .../internals/{Sent.php => Sended.php} | 46 ++++-- controllers/internals/SmsStop.php | 10 ++ controllers/internals/Transfer.php | 141 +++++++++++++++++ controllers/internals/User.php | 10 ++ controllers/publics/Dashboard.php | 2 +- controllers/publics/Discussion.php | 2 +- controllers/publics/{Sent.php => Sended.php} | 8 +- models/Command.php | 10 ++ models/DataBase.php | 144 ----------------- models/Scheduled.php | 6 +- models/{Sent.php => Sended.php} | 20 ++- models/SmsStop.php | 10 ++ models/Transfer.php | 145 ++++++++++++++++++ models/User.php | 10 ++ templates/dashboard/show.php | 2 +- templates/incs/nav.php | 2 +- templates/sended/list.php | 6 +- 20 files changed, 465 insertions(+), 219 deletions(-) rename controllers/internals/{Sent.php => Sended.php} (71%) create mode 100755 controllers/internals/Transfer.php rename controllers/publics/{Sent.php => Sended.php} (93%) delete mode 100755 models/DataBase.php rename models/{Sent.php => Sended.php} (89%) create mode 100755 models/Transfer.php diff --git a/controllers/internals/Command.php b/controllers/internals/Command.php index 6cb0a77..d9db572 100755 --- a/controllers/internals/Command.php +++ b/controllers/internals/Command.php @@ -39,6 +39,17 @@ namespace controllers\internals; return $this->model_command->list($nb_entry, $nb_entry * $page); } + /** + * Get all commands. + * + * @return array + */ + public function get_all() + { + //Recupération des commandes + return $this->model_command->get_all(); + } + /** * Cette fonction retourne une liste des commandes sous forme d'un tableau. * diff --git a/controllers/internals/Console.php b/controllers/internals/Console.php index ce6a29c..3a8155c 100755 --- a/controllers/internals/Console.php +++ b/controllers/internals/Console.php @@ -15,13 +15,20 @@ namespace controllers\internals; class Console extends \descartes\InternalController { private $model_command; - private $model_database; - private $model_sent; + private $model_sended; private $model_smsstop; private $model_received; private $model_scheduled; private $model_user; + private $internal_contact; + private $internal_command; + private $internal_database; + private $internal_sended; + private $internal_sms_stop; + private $internal_received; private $internal_scheduled; + private $internal_user; + private $internal_transfer; private $internal_event; @@ -30,8 +37,7 @@ class Console extends \descartes\InternalController $bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD); $this->model_command = new \models\Command($bdd); - $this->model_database = new \models\DataBase($bdd); - $this->model_sent = new \models\Sent($bdd); + $this->model_sended = new \models\Sended($bdd); $this->model_smsstop = new \models\SmsStop($bdd); $this->model_received = new \models\Received($bdd); $this->model_user = new \models\User($bdd); @@ -80,32 +86,32 @@ class Console extends \descartes\InternalController $numbers = []; //On récupère les numéros pour le Sms et on les ajoute - $target_numbers = $this->model_database->get_numbers_for_scheduled($id_scheduled); + $target_numbers = $this->internal_scheduled->get_numbers($id_scheduled); foreach ($target_numbers as $target_number) { $numbers[] = $target_number['number']; } //On récupère les contacts, et on ajoute les numéros - $contacts = $this->model_database->getContactForScheduled($id_scheduled); + $contacts = $this->internal_scheduled->get_contacts($id_scheduled); foreach ($contacts as $contact) { $numbers[] = $contact['number']; } //On récupère les groups - $groups = $this->model_database->get_groups_for_scheduled($id_scheduled); + $groups = $this->internal_scheduled->get_groups($id_scheduled); foreach ($groups as $group) { //On récupère les contacts du group et on les ajoute aux numéros - $contacts = $this->model_database->get_by_group($group['id']); + $contacts = $this->internal_contact->get_by_group($group['id']); foreach ($contacts as $contact) { $numbers[] = $contact['number']; } } - $smsStops = $this->model_smsstop->_select('smsstop'); + $smsStops = $this->internal_sms_stop->get_all(); foreach ($numbers as $number) { @@ -132,7 +138,7 @@ class Console extends \descartes\InternalController $now = $now->format('Y-m-d H:i:s'); //On peut maintenant ajouter le Sms - if (!$id_sended = $this->model_sent->insert(['at' => $now, 'target' => $number, 'content' => $scheduled['content'], 'before_delivered' => ceil(mb_strlen($scheduled['content']) / 160)])) + if (!$id_sended = $this->model_sended->insert(['at' => $now, 'target' => $number, 'content' => $scheduled['content'], 'before_delivered' => ceil(mb_strlen($scheduled['content']) / 160)])) { echo 'Impossible d\'inserer le sms pour le numero '.$number."\n"; } @@ -238,7 +244,7 @@ class Console extends \descartes\InternalController $interval = new \DateInterval('PT12H'); $sinceDate = $now->sub($interval)->format('Y-m-d H:i:s'); - if (!$sendeds = $this->model_sent->_select('sendeds', ['target' => $number, 'delivered' => false, 'failed' => false, '>at' => $sinceDate], 'at', false, 1)) + if (!$sendeds = $this->model_sended->_select('sendeds', ['target' => $number, 'delivered' => false, 'failed' => false, '>at' => $sinceDate], 'at', false, 1)) { continue; } @@ -248,8 +254,8 @@ class Console extends \descartes\InternalController //On gère les echecs if ('Failed' === trim($text)) { - $this->model_sent->update($sended['id'], ['before_delivered' => 0, 'failed' => true]); - echo 'Sent Sms id '.$sended['id']." pass to failed status\n"; + $this->model_sended->update($sended['id'], ['before_delivered' => 0, 'failed' => true]); + echo 'Sended Sms id '.$sended['id']." pass to failed status\n"; continue; } @@ -257,15 +263,15 @@ class Console extends \descartes\InternalController //On gère le cas des messages de plus de 160 caractères, lesquels impliquent plusieurs accusés if ($sended['before_delivered'] > 1) { - $this->model_database->update($sended['id'], ['before_delivered' => $sended['before_delivered'] - 1]); - echo 'Sent Sms id '.$sended['id']." before_delivered decrement\n"; + $this->internal_sended->decrement_before_delivered($sended['id']); + echo 'Sended Sms id '.$sended['id']." before_delivered decrement\n"; continue; } //Si tout est bon, que nous avons assez d'accusés, nous validons ! - $this->model_database->update($sended['id'], ['before_delivered' => 0, 'delivered' => true]); - echo 'Sent Sms id '.$sended['id']." to delivered status\n"; + $this->internal_sended->set_delivered($sended['id']); + echo 'Sended Sms id '.$sended['id']." to delivered status\n"; continue; } @@ -280,20 +286,20 @@ class Console extends \descartes\InternalController $flags = \controllers\internals\Tool::parse_for_flag($text); //On créer le tableau qui permettra de stocker les commandes trouvées - $found_commands = []; //Si on reçu des identifiants if (\array_key_exists('LOGIN', $flags) && \array_key_exists('PASSWORD', $flags)) { - //Si on a bien un utilisateur avec les identifiants reçus - $user = $this->model_database->get_user_from_email($flags['LOGIN']); + $user = $this->internal_user->check_credentials($flags['LOGIN'], $flags['PASSWORD']); + error_log('We found '.\count($user).' users'); - if ($user && $user['password'] === sha1($flags['PASSWORD'])) + if ($user) { error_log('Password is valid'); + //On va passer en revue toutes les commandes, pour voir si on en trouve dans ce message - $commands = $this->model_database->_select('commands'); + $commands = $this->internal_command->get_all(); error_log('We found '.\count($commands).' commands'); foreach ($commands as $command) @@ -324,7 +330,7 @@ class Console extends \descartes\InternalController $send_by = $number; $content = $text; $is_command = \count($found_commands); - if (!$this->model_received->insert(['at' => $date, 'send_by' => $send_by, 'content' => $content, 'is_command' => $is_command])) + if ($id_received = $this->internal_received->create($date, $send_by, $content, $is_command)) { echo "Erreur lors de l'enregistrement du Sms\n"; error_log('Unable to process the Sms in file "'.$dir); @@ -332,7 +338,7 @@ class Console extends \descartes\InternalController } //On insert le Sms dans le tableau des sms à envoyer par mail - $this->model_database->_insert('transfers', ['id_received' => $this->model_database->lastId(), 'progress' => false]); + $this->internal_transfer->create($id_received); //Chaque commande sera executée. foreach ($found_commands as $command_name => $command) @@ -359,37 +365,32 @@ class Console extends \descartes\InternalController return false; } - $transfers = $this->model_database->_select('transfers', ['progress' => false]); + $users = $this->internal_user->gets_by_transfer(true); + $transfers = $this->internal_transfer->get_not_in_progress(); - $ids_transfers = []; - $ids_receiveds = []; foreach ($transfers as $transfer) { - $ids_transfers[] = $transfer['id']; - $ids_receiveds[] = $transfer['id_received']; - } + $this->internal_transfer->update($transfer['id'], $transfer['id_received'], true); - $this->model_database->update_progress_transfers_in($ids_transfers, true); + $received = $this->internal_received->get($transfer['id_received']); + if (!$received) + { + continue; + } - $receiveds = $this->model_received->gets($ids_receiveds); - - $users = $this->model_user->_select('users', ['transfer' => true]); - - foreach ($users as $user) - { - foreach ($receiveds as $received) + foreach ($users as $user) { echo "Transfer d'un Sms du ".$received['send_by']." à l'email ".$user['email']; + $to = $user['email']; $subject = '[RaspiSms] - Transfert d\'un Sms du '.$received['send_by']; $message = 'Le numéro '.$received['send_by']." vous a envoyé un Sms : \n".$received['content']; - $ok = mail($to, $subject, $message); - - echo ' ... '.($ok ? 'OK' : 'KO')."\n"; + $success = mail($to, $subject, $message); + echo ' ... '.($success ? 'ok' : 'ko')."\n"; } - } - $this->model_database->delete_transfers_in($ids_transfers); + $this->internal_transfer->delete($transfer['id']); + } } } diff --git a/controllers/internals/Scheduled.php b/controllers/internals/Scheduled.php index c19528a..1303725 100755 --- a/controllers/internals/Scheduled.php +++ b/controllers/internals/Scheduled.php @@ -182,10 +182,10 @@ namespace controllers\internals; * * @return array : La liste des scheduledes */ - public function get_number($id_scheduled) + public function get_numbers($id_scheduled) { //Recupération des scheduledes - return $this->model_scheduled->get_number($id_scheduled); + return $this->model_scheduled->get_numbers($id_scheduled); } /** @@ -195,10 +195,10 @@ namespace controllers\internals; * * @return array : La liste des contact */ - public function get_contact($id_scheduled) + public function get_contacts($id_scheduled) { //Recupération des scheduledes - return $this->model_scheduled->get_contact($id_scheduled); + return $this->model_scheduled->get_contacts($id_scheduled); } /** @@ -208,10 +208,10 @@ namespace controllers\internals; * * @return array : La liste des group */ - public function get_group($id_scheduled) + public function get_groups($id_scheduled) { //Recupération des scheduledes - return $this->model_scheduled->get_group($id_scheduled); + return $this->model_scheduled->get_groups($id_scheduled); } /** diff --git a/controllers/internals/Sent.php b/controllers/internals/Sended.php similarity index 71% rename from controllers/internals/Sent.php rename to controllers/internals/Sended.php index 7f470c2..6b6a512 100755 --- a/controllers/internals/Sent.php +++ b/controllers/internals/Sended.php @@ -15,13 +15,13 @@ namespace controllers\internals; /** * Classe des sendedes. */ - class Sent extends \descartes\InternalController + class Sended extends \descartes\InternalController { - private $model_sent; + private $model_sended; public function __construct(\PDO $bdd) { - $this->model_sent = new \models\Sent($bdd); + $this->model_sended = new \models\Sended($bdd); } /** @@ -35,7 +35,7 @@ namespace controllers\internals; public function list($nb_entry = false, $page = false) { //Recupération des sendedes - return $this->model_sent->list($nb_entry, $nb_entry * $page); + return $this->model_sended->list($nb_entry, $nb_entry * $page); } /** @@ -48,7 +48,7 @@ namespace controllers\internals; public function gets($ids) { //Recupération des sendedes - return $this->model_sent->gets($ids); + return $this->model_sended->gets($ids); } /** @@ -60,7 +60,7 @@ namespace controllers\internals; */ public function get_lasts_by_date($nb_entry = false) { - return $this->model_sent->get_lasts_by_date($nb_entry); + return $this->model_sended->get_lasts_by_date($nb_entry); } /** @@ -73,7 +73,7 @@ namespace controllers\internals; public function get_by_target($target) { //Recupération des sendeds - return $this->model_sent->get_by_target($target); + return $this->model_sended->get_by_target($target); } /** @@ -86,7 +86,7 @@ namespace controllers\internals; */ public function delete($id) { - return $this->model_sent->delete($id); + return $this->model_sended->delete($id); } /** @@ -98,7 +98,7 @@ namespace controllers\internals; */ public function create($sended) { - return $this->model_sent->create($sended); + return $this->model_sended->create($sended); } /** @@ -108,7 +108,7 @@ namespace controllers\internals; */ public function count() { - return $this->model_sent->count(); + return $this->model_sended->count(); } /** @@ -120,7 +120,7 @@ namespace controllers\internals; */ public function count_by_day_since($date) { - $counts_by_day = $this->model_sent->count_by_day_since($date); + $counts_by_day = $this->model_sended->count_by_day_since($date); $return = []; foreach ($counts_by_day as $count_by_day) @@ -130,4 +130,28 @@ namespace controllers\internals; return $return; } + + /** + * 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); + } + + /** + * Update sended to delivered. + * + * @param int $id_sended : id of the sended to mark as delivered + * + * @return int + */ + public function set_delivered($id_sended) + { + return $this->model_sended->update($id_sended, ['before_delivered' => 0, 'delivered' => true]); + } } diff --git a/controllers/internals/SmsStop.php b/controllers/internals/SmsStop.php index 51993ae..97279ab 100755 --- a/controllers/internals/SmsStop.php +++ b/controllers/internals/SmsStop.php @@ -24,6 +24,16 @@ namespace controllers\internals; $this->model_sms_stop = new \models\SmsStop($bdd); } + /** + * Return all smsstops. + * + * @return array + */ + public function get_all() + { + return $this->model_sms_stop->get_all(); + } + /** * Cette fonction retourne une liste des smsstopes sous forme d'un tableau. * diff --git a/controllers/internals/Transfer.php b/controllers/internals/Transfer.php new file mode 100755 index 0000000..8feff26 --- /dev/null +++ b/controllers/internals/Transfer.php @@ -0,0 +1,141 @@ + + * Dariusz Rumiński + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace controllers\internals; + + /** + * Classe des transfers. + */ + class Transfer extends \descartes\InternalController + { + private $model_transfer; + private $internal_event; + + public function __construct(\PDO $bdd) + { + $this->model_transfer = new \models\Transfer($bdd); + $this->internal_event = new \controllers\internals\Event($bdd); + } + + /** + * Return the list of transfers as an array. + * + * @param mixed(int|bool) $nb_entry : Le nombre d'entrées à retourner par page + * @param mixed(int|bool) $page : Le numéro de page en cours + * + * @return array : La liste des transfers + */ + public function list($nb_entry = false, $page = false) + { + return $this->model_transfer->list($nb_entry, $nb_entry * $page); + } + + /** + * Get all transfers. + * + * @return array + */ + public function get_all() + { + //Recupération des transfers + return $this->model_transfer->get_all(); + } + + /** + * Get transfers not in progress. + * + * @return array + */ + public function get_not_in_progress() + { + return $this->model_transfer->get_not_in_progress(); + } + + /** + * Cette fonction retourne une liste des transfers sous forme d'un tableau. + * + * @param array int $ids : Les ids des entrées à retourner + * + * @return array : La liste des transfers + */ + public function gets($ids) + { + //Recupération des transfers + return $this->model_transfer->gets($ids); + } + + /** + * Cette fonction permet de compter le nombre de scheduleds. + * + * @return int : Le nombre d'entrées dans la table + */ + public function count() + { + return $this->model_transfer->count(); + } + + /** + * Cette fonction va supprimer un transfer. + * + * @param array $id : L'id de la transfer à supprimer + * + * @return int : Le nombre de transfers supprimées; + */ + public function delete($id) + { + return $this->model_transfer->delete($id); + } + + /** + * This function insert a new transfer. + * + * @param int $id_received : Id of the received message to transfer + * @param bool $progress : If we must mark it as in progress + * + * @return int id of the new inserted transfer + */ + public function create($id_received, $progress = false) + { + $transfer = [ + 'id_received' => $id_received, + 'progress' => $progress, + ]; + + $result = $this->model_transfer->insert($transfer); + + if (!$result) + { + return false; + } + + return $result; + } + + /** + * Cette fonction met à jour un transfer. + * + * @param int $id + * @param int $id_received + * @param bool $progress + * + * @return int : le nombre de ligne modifiées + */ + public function update($id, $id_received, $progress) + { + $transfer = [ + 'id_received' => $id_received, + 'progress' => $progress, + ]; + + return $this->model_transfer->update($id, $transfer); + } + } diff --git a/controllers/internals/User.php b/controllers/internals/User.php index d4f94fe..02679a9 100755 --- a/controllers/internals/User.php +++ b/controllers/internals/User.php @@ -126,6 +126,16 @@ namespace controllers\internals; return $this->model_user->get_by_email($email); } + /** + * Return users by transfer status. + * + * @param bool $transfer : transfer status + */ + public function gets_by_transfer($transfer) + { + return $this->model_user->get_by_transfer($transfer); + } + /** * Cette fonction met à jour une série de users. * diff --git a/controllers/publics/Dashboard.php b/controllers/publics/Dashboard.php index 862e99d..de0d849 100755 --- a/controllers/publics/Dashboard.php +++ b/controllers/publics/Dashboard.php @@ -35,7 +35,7 @@ namespace controllers\publics; { $bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD); - $this->internal_sended = new \controllers\internals\Sent($bdd); + $this->internal_sended = new \controllers\internals\Sended($bdd); $this->internal_received = new \controllers\internals\Received($bdd); $this->internal_contact = new \controllers\internals\Contact($bdd); $this->internal_group = new \controllers\internals\Group($bdd); diff --git a/controllers/publics/Discussion.php b/controllers/publics/Discussion.php index 6a15452..0d97452 100755 --- a/controllers/publics/Discussion.php +++ b/controllers/publics/Discussion.php @@ -32,7 +32,7 @@ namespace controllers\publics; { $bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD); - $this->internal_sended = new \controllers\internals\Sent($bdd); + $this->internal_sended = new \controllers\internals\Sended($bdd); $this->internal_scheduled = new \controllers\internals\Scheduled($bdd); $this->internal_received = new \controllers\internals\Received($bdd); $this->internal_contact = new \controllers\internals\Contact($bdd); diff --git a/controllers/publics/Sent.php b/controllers/publics/Sended.php similarity index 93% rename from controllers/publics/Sent.php rename to controllers/publics/Sended.php index 1a08f8b..194a941 100755 --- a/controllers/publics/Sent.php +++ b/controllers/publics/Sended.php @@ -15,7 +15,7 @@ namespace controllers\publics; /** * Page des sendeds. */ - class Sent extends \descartes\Controller + class Sended extends \descartes\Controller { private $internal_sended; @@ -28,7 +28,7 @@ namespace controllers\publics; public function __construct() { $bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD); - $this->internal_sended = new \controllers\internals\Sent($bdd); + $this->internal_sended = new \controllers\internals\Sended($bdd); \controllers\internals\Tool::verifyconnect(); } @@ -60,7 +60,7 @@ namespace controllers\publics; { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); - return $this->redirect(\descartes\Router::url('Sent', 'list')); + return $this->redirect(\descartes\Router::url('Sended', 'list')); } $ids = $_GET['ids'] ?? []; @@ -69,6 +69,6 @@ namespace controllers\publics; $this->internal_sended->delete($id); } - return $this->redirect(\descartes\Router::url('Sent', 'list')); + return $this->redirect(\descartes\Router::url('Sended', 'list')); } } diff --git a/models/Command.php b/models/Command.php index 6c59e10..90183fd 100755 --- a/models/Command.php +++ b/models/Command.php @@ -17,6 +17,16 @@ namespace models; */ class Command extends \descartes\Model { + /** + * Get all commands. + * + * @return array + */ + public function get_all() + { + return $this->_select('command'); + } + /** * Retourne une entrée par son id. * diff --git a/models/DataBase.php b/models/DataBase.php deleted file mode 100755 index 24c9edc..0000000 --- a/models/DataBase.php +++ /dev/null @@ -1,144 +0,0 @@ - - * Dariusz Rumiński - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace models; - - class DataBase extends \descartes\Model - { - // - // PARTIE DES REQUETES SCHEDULEDS_NUMBERS - // - - /** - * Retourne tous les numéros pour un scheduled donné. - * - * @param int $id_scheduled : L'id du scheduled - * - * @return array : Tous les numéro compris dans le scheduled - */ - public function get_numbers_for_scheduled($id_scheduled) - { - $query = ' - SELECT * - FROM scheduled_number - WHERE id_scheduled = :id_scheduled - '; - - $params = [ - 'id_scheduled' => $id_scheduled, - ]; - - return $this->_run_query($query, $params); - } - - // - // PARTIE DES REQUETES SCHEDULEDS_GROUPS - // - - /** - * Retourne tous les groups pour un scheduled donnée. - * - * @param int $id_scheduled : L'id du schedulede - * - * @return array : Tous les groups compris dans le scheduled - */ - public function get_groups_for_scheduled($id_scheduled) - { - $query = ' - SELECT gro.id as id, gro.name as name - FROM scheduled_group as s_g - JOIN group as gro - ON (s_g.id_group = gro.id) - WHERE(s_g.id_scheduled = :id_scheduled) - '; - - $params = [ - 'id_scheduled' => $id_scheduled, - ]; - - return $this->_run_query($query, $params); - } - - // - // PARTIE DES REQUETES USERS - // - - /** - * Récupère un utilisateur à partir de son email. - * - * @param string $email = L'email de l'utilisateur - * - * @return array : Retourne l'utilisateur - */ - public function get_user_from_email($email) - { - $query = ' - SELECT * - FROM user - WHERE email = :email'; - - $params = [ - 'email' => $email, - ]; - - return $this->_run_query($query, $params, self::FETCH); - } - - // - // PARTIE DES REQUETES TRANSFERS - // - - /** - * Change le statut des tranfers dont l'id est fourni dans $transfers_id. - * - * @param array $transfers_ids = Tableau des id des transfers voulus - * @param mixed $progress - * - * @return int : Retourne le nombre de lignes mises à jour - */ - public function update_progress_transfers_in($transfers_ids, $progress) - { - $query = ' - UPDATE transfer - SET progress = :progress - WHERE id '; - - //On génère la clause IN et les paramètres adaptés depuis le tableau des id - $generted_in = $this->_generate_in_from_array($transfers_ids); - $query .= $generted_in['QUERY']; - $params = $generted_in['PARAMS']; - $params['progress'] = (bool) $progress; - - return $this->_run_query($query, $params, self::ROWCOUNT); - } - - /** - * Supprime tous les transfers dont l'id fait partie du tableau fourni. - * - * @param $transfers_ids : Tableau des id des transfers à supprimer - * - * @return int : Nombre de lignes supprimées - */ - public function delete_transfers_in($transfers_ids) - { - $query = ' - DELETE FROM transfer - WHERE id '; - - //On génère la clause IN et les paramètres adaptés depuis le tableau des id - $generted_in = $this->_generate_in_from_array($transfers_ids); - $query .= $generted_in['QUERY']; - $params = $generted_in['PARAMS']; - - return $this->_run_query($query, $params, self::ROWCOUNT); - } - } diff --git a/models/Scheduled.php b/models/Scheduled.php index 4b1c00c..013b0d8 100755 --- a/models/Scheduled.php +++ b/models/Scheduled.php @@ -197,7 +197,7 @@ namespace models; * * @return array : Les numéros des scheduled */ - public function get_number($id_scheduled) + public function get_numbers($id_scheduled) { return $this->_select('scheduled_number', ['id_scheduled' => $id_scheduled]); } @@ -209,7 +209,7 @@ namespace models; * * @return array : Les contact du scheduled */ - public function get_contact($id_scheduled) + public function get_contacts($id_scheduled) { $query = 'SELECT * FROM contact WHERE id IN (SELECT id_contact FROM scheduled_contact WHERE id_scheduled = :id_scheduled)'; @@ -225,7 +225,7 @@ namespace models; * * @return array : Les groups du scheduled */ - public function get_group($id_scheduled) + public function get_groups($id_scheduled) { $query = 'SELECT * FROM group WHERE id IN (SELECT id_group FROM scheduled_group WHERE id_scheduled = :id_scheduled)'; diff --git a/models/Sent.php b/models/Sended.php similarity index 89% rename from models/Sent.php rename to models/Sended.php index c759467..73f884a 100755 --- a/models/Sent.php +++ b/models/Sended.php @@ -15,7 +15,7 @@ namespace models; /** * Cette classe gère les accès bdd pour les sendedes. */ - class Sent extends \descartes\Model + class Sended extends \descartes\Model { /** * Retourne une entrée par son id. @@ -170,4 +170,22 @@ namespace models; return $this->_run_query($query, $params); } + + /** + * Decrement before_delivered field. + * + * @param int $id_sended : id of the sended sms to decrement + */ + public function decrement_before_delivered($id_sended) + { + $query = ' + UPDATE sended + SET before_delivered = before_delivered - 1 + WHERE id = :id_sended + '; + + $params = ['id_sended' => $id_sended]; + + return $this->_run_query($query, $params); + } } diff --git a/models/SmsStop.php b/models/SmsStop.php index 89aa7de..c7ff76b 100755 --- a/models/SmsStop.php +++ b/models/SmsStop.php @@ -17,6 +17,16 @@ namespace models; */ class SmsStop extends \descartes\Model { + /** + * Get all smsstops. + * + * @return array + */ + public function get_all() + { + return $this->_select('smsstop'); + } + /** * Retourne une entrée par son id. * diff --git a/models/Transfer.php b/models/Transfer.php new file mode 100755 index 0000000..4398deb --- /dev/null +++ b/models/Transfer.php @@ -0,0 +1,145 @@ + + * Dariusz Rumiński + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace models; + + /** + * Cette classe gère les accès bdd pour les transferes. + */ + class Transfer extends \descartes\Model + { + /** + * Get all transfers. + * + * @return array + */ + public function get_all() + { + return $this->_select('transfer'); + } + + /** + * Get transfers not in progress. + * + * @return array + */ + public function get_not_in_progress() + { + return $this->_select('transfer', ['progress' => false]); + } + + /** + * Retourne une entrée par son id. + * + * @param int $id : L'id de l'entrée + * + * @return array : L'entrée + */ + public function get($id) + { + $transfers = $this->_select('transfer', ['id' => $id]); + + return isset($transfers[0]) ? $transfers[0] : false; + } + + /** + * Retourne une liste de transferes sous forme d'un tableau. + * + * @param int $limit : Nombre de résultat maximum à retourner + * @param int $offset : Nombre de résultat à ingnorer + */ + public function list($limit, $offset) + { + return $this->_select('transfer', [], '', false, $limit, $offset); + } + + /** + * Retourne une liste de transferes sous forme d'un tableau. + * + * @param array $ids : un ou plusieurs id d'entrées à récupérer + * + * @return array : La liste des entrées + */ + public function gets($ids) + { + $query = ' + SELECT * FROM transfer + WHERE id '; + + //On génère la clause IN et les paramètres adaptés depuis le tableau des id + $generated_in = $this->_generate_in_from_array($ids); + $query .= $generated_in['QUERY']; + $params = $generated_in['PARAMS']; + + return $this->_run_query($query, $params); + } + + /** + * Supprime un transfer. + * + * @param array $id : l'id de l'entrée à supprimer + * + * @return int : Le nombre de lignes supprimées + */ + public function delete($id) + { + $query = ' + DELETE FROM transfer + WHERE id = :id'; + + $params = ['id' => $id]; + + return $this->_run_query($query, $params, self::ROWCOUNT); + } + + /** + * Insert un transfer. + * + * @param array $transfer : La transfere à insérer + * + * @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée + */ + public function insert($transfer) + { + $result = $this->_insert('transfer', $transfer); + + if (!$result) + { + return false; + } + + return $this->_last_id(); + } + + /** + * Met à jour un transfer par son id. + * + * @param int $id : L'id de la transfer à modifier + * @param array $transfer : Les données à mettre à jour pour la transfere + * + * @return int : le nombre de ligne modifiées + */ + public function update($id, $transfer) + { + return $this->_update('transfer', $transfer, ['id' => $id]); + } + + /** + * Compte le nombre d'entrées dans la table. + * + * @return int : Le nombre d'entrées + */ + public function count() + { + return $this->_count('transfer'); + } + } diff --git a/models/User.php b/models/User.php index b68583d..bc9f7dd 100755 --- a/models/User.php +++ b/models/User.php @@ -26,6 +26,16 @@ namespace models; return $this->_select_one('user', ['email' => $email]); } + /** + * Return users by transfer status. + * + * @param bool $transfer : transfer status + */ + public function gets_by_transfer($transfer) + { + return $this->_select('transfer', ['transfer' => $transfer]); + } + /** * Return list of user. * diff --git a/templates/dashboard/show.php b/templates/dashboard/show.php index a2792a1..1acdcae 100755 --- a/templates/dashboard/show.php +++ b/templates/dashboard/show.php @@ -166,7 +166,7 @@ diff --git a/templates/incs/nav.php b/templates/incs/nav.php index 670307e..af9c4bd 100755 --- a/templates/incs/nav.php +++ b/templates/incs/nav.php @@ -55,7 +55,7 @@ Logs
  • > - SMS envoyés + SMS envoyés
  • > SMS reçus diff --git a/templates/sended/list.php b/templates/sended/list.php index 6798586..894af56 100755 --- a/templates/sended/list.php +++ b/templates/sended/list.php @@ -1,7 +1,7 @@ render('incs/head', ['title' => 'Sents - Show All']) + $this->render('incs/head', ['title' => 'Sendeds - Show All']) ?>
    Action pour la séléction : - +