Rename a few classes, fix bugs, fix syntax

This commit is contained in:
osaajani 2019-11-06 20:34:26 +01:00
parent 7cb963b8cf
commit bda1c7ddfd
18 changed files with 106 additions and 37 deletions

View File

@ -16,28 +16,29 @@ class Console extends \descartes\InternalController
{
private $model_command;
private $model_database;
private $model_sended;
private $model_sent;
private $model_smsstop;
private $model_received;
private $model_scheduled;
private $model_user;
private $internal_scheduled;
private $internal_event;
public function __construct()
{
$bdd = descartes\Model::connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
$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_sended = new \models\Sent($bdd);
$this->model_sent = new \models\Sent($bdd);
$this->model_smsstop = new \models\SmsStop($bdd);
$this->model_received = new \models\Received($bdd);
$this->model_user = new \models\User($bdd);
$this->internal_event = new \controllers\internals\Event($bdd);
}
/**
* Cette fonction envoie tous les Sms programmés qui doivent l'être.
*/
@ -131,7 +132,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_sended->insert(['at' => $now, 'target' => $number, 'content' => $scheduled['content'], 'before_delivered' => ceil(mb_strlen($scheduled['content']) / 160)]))
if (!$id_sended = $this->model_sent->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";
}
@ -237,7 +238,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_sended->_select('sendeds', ['target' => $number, 'delivered' => false, 'failed' => false, '>at' => $sinceDate], 'at', false, 1))
if (!$sendeds = $this->model_sent->_select('sendeds', ['target' => $number, 'delivered' => false, 'failed' => false, '>at' => $sinceDate], 'at', false, 1))
{
continue;
}
@ -247,8 +248,8 @@ class Console extends \descartes\InternalController
//On gère les echecs
if ('Failed' === trim($text))
{
$this->model_sended->update($sended['id'], ['before_delivered' => 0, 'failed' => true]);
echo 'Sent Sms id ' . $sended['id'] . " pass to failed status\n";
$this->model_sent->update($sended['id'], ['before_delivered' => 0, 'failed' => true]);
echo 'Sent Sms id '.$sended['id']." pass to failed status\n";
continue;
}
@ -257,14 +258,14 @@ class Console extends \descartes\InternalController
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";
echo 'Sent 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";
echo 'Sent Sms id '.$sended['id']." to delivered status\n";
continue;
}
@ -358,7 +359,6 @@ class Console extends \descartes\InternalController
return false;
}
global $this->model_database;
$transfers = $this->model_database->_select('transfers', ['progress' => false]);
$ids_transfers = [];

View File

@ -1,5 +1,15 @@
<?php
/*
* 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.
*/
namespace controllers\internals;
/**

View File

@ -133,13 +133,19 @@ namespace controllers\internals;
* @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
* @param mixed $id
* @param mixed $content
* @param mixed $at
* @param mixed $contact_ids
* @param mixed $flash
* @param mixed $progress
*
* @return int : le nombre de ligne modifiées
*/
public function update($id, $content, $at, $numbers = [], $contact_ids = [], $groups_ids = [], $flash = false, $progress = false)
{
$scheduled = [
'at' => $date,
'at' => $at,
'content' => $content,
'flash' => $flash,
'progress' => $progress,
@ -209,11 +215,14 @@ namespace controllers\internals;
}
/**
* This function update progress status of a scheduled sms
* @param bool $progress : Progress status
* This function update progress status of a scheduled sms.
*
* @param bool $progress : Progress status
* @param mixed $id_scheduled
*
* @return int : Number of update
*/
public function update_progress ($id_scheduled, $progress)
public function update_progress($id_scheduled, $progress)
{
return $this->model_scheduled->update($id_scheduled, ['progress' => $progress]);
}

View File

@ -17,11 +17,11 @@ namespace controllers\internals;
*/
class Sent extends \descartes\InternalController
{
private $model_sended;
private $model_sent;
public function __construct(\PDO $bdd)
{
$this->model_sended = new \models\Sent($bdd);
$this->model_sent = new \models\Sent($bdd);
}
/**
@ -35,7 +35,7 @@ namespace controllers\internals;
public function list($nb_entry = false, $page = false)
{
//Recupération des sendedes
return $this->model_sended->list($nb_entry, $nb_entry * $page);
return $this->model_sent->list($nb_entry, $nb_entry * $page);
}
/**
@ -48,7 +48,7 @@ namespace controllers\internals;
public function gets($ids)
{
//Recupération des sendedes
return $this->model_sended->gets($ids);
return $this->model_sent->gets($ids);
}
/**
@ -60,7 +60,7 @@ namespace controllers\internals;
*/
public function get_lasts_by_date($nb_entry = false)
{
return $this->model_sended->get_lasts_by_date($nb_entry);
return $this->model_sent->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_sended->get_by_target($target);
return $this->model_sent->get_by_target($target);
}
/**
@ -86,7 +86,7 @@ namespace controllers\internals;
*/
public function delete($id)
{
return $this->model_sended->delete($id);
return $this->model_sent->delete($id);
}
/**
@ -98,7 +98,7 @@ namespace controllers\internals;
*/
public function create($sended)
{
return $this->model_sended->create($sended);
return $this->model_sent->create($sended);
}
/**
@ -108,7 +108,7 @@ namespace controllers\internals;
*/
public function count()
{
return $this->model_sended->count();
return $this->model_sent->count();
}
/**
@ -120,7 +120,7 @@ namespace controllers\internals;
*/
public function count_by_day_since($date)
{
$counts_by_day = $this->model_sended->count_by_day_since($date);
$counts_by_day = $this->model_sent->count_by_day_since($date);
$return = [];
foreach ($counts_by_day as $count_by_day)

View File

@ -108,6 +108,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Command', 'list'));
}
@ -118,16 +119,19 @@ namespace controllers\publics;
if (!$name || !$script)
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Renseignez au moins un nom et un script.');
return $this->redirect(\descartes\Router::url('Command', 'list'));
}
if (!$this->internal_command->create($name, $script, $admin))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible créer cette commande.');
return $this->redirect(\descartes\Router::url('commands', 'add'));
}
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'La commande a bien été crée.');
return $this->redirect(\descartes\Router::url('Command', 'list'));
}
@ -144,6 +148,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Command', 'list'));
}
@ -157,10 +162,12 @@ namespace controllers\publics;
if ($nb_commands_update !== \count($_POST['commands']))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certaines commandes n\'ont pas pu êtres mises à jour.');
return $this->redirect(\descartes\Router::url('Command', 'list'));
}
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Toutes les commandes ont été modifiées avec succès.');
return $this->redirect(\descartes\Router::url('Command', 'list'));
}
}

View File

@ -87,6 +87,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Connect', 'forget_password'));
}
@ -96,6 +97,7 @@ namespace controllers\publics;
if (!$email || !$user)
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Aucun utilisateur n\'existe pour cette adresse mail.');
return $this->redirect(\descartes\Router::url('Connect', 'forget_password'));
}
@ -144,6 +146,7 @@ namespace controllers\publics;
{
session_unset();
session_destroy();
return $this->redirect(\descartes\Router::url('Connect', 'login'));
}
}

View File

@ -45,6 +45,7 @@ namespace controllers\publics;
{
$page = (int) $page;
$contacts = $this->internal_contact->list(25, $page);
return $this->render('contact/list', ['contacts' => $contacts]);
}
@ -61,6 +62,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Contact', 'list'));
}

View File

@ -60,12 +60,14 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Event', 'list'));
}
if (!\controllers\internals\Tool::is_admin())
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être admin pour pouvoir supprimer des events.');
return $this->redirect(\descartes\Router::url('Event', 'list'));
}

View File

@ -70,6 +70,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Group', 'list'));
}
@ -120,6 +121,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Group', 'add'));
}
@ -129,6 +131,7 @@ namespace controllers\publics;
if (!$name || !$contacts_ids)
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Des champs sont manquants !');
return $this->redirect(\descartes\Router::url('Group', 'add'));
}
@ -136,10 +139,12 @@ namespace controllers\publics;
if (!$id_group)
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer ce groupe.');
return $this->redirect(\descartes\Router::url('Group', 'add'));
}
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le groupe a bien été créé.');
return $this->redirect(\descartes\Router::url('Group', 'list'));
}
@ -156,6 +161,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Group', 'list'));
}
@ -170,10 +176,12 @@ namespace controllers\publics;
if ($nb_groups_update !== \count($groups))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certains groupes n\'ont pas pu êtres mis à jour.');
return $this->redirect(\descartes\Router::url('Group', 'list'));
}
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Tous les groupes ont été modifiés avec succès.');
return $this->redirect(\descartes\Router::url('Group', 'list'));
}

View File

@ -108,12 +108,14 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Received', 'list'));
}
if (!\controllers\internals\Tool::is_admin())
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour effectuer cette action.');
return $this->redirect(\descartes\Router::url('Received', 'list'));
}

View File

@ -58,6 +58,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
}
@ -141,6 +142,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
}
@ -153,12 +155,14 @@ namespace controllers\publics;
if (!$content)
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous ne pouvez pas créer un Sms sans message.');
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
}
if (!\controllers\internals\Tool::validate_date($date, 'Y-m-d H:i:s') && !\controllers\internals\Tool::validate_date($date, 'Y-m-d H:i'))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez fournir une date valide.');
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
}
@ -179,6 +183,7 @@ namespace controllers\publics;
if (!$numbers && !$contacts && !$groups)
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez renseigner au moins un destinataire pour le Sms.');
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
}
@ -192,10 +197,12 @@ namespace controllers\publics;
if (!$scheduled_id = $this->internal_scheduled->create($scheduled, $numbers, $contacts, $groups))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer le Sms.');
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
}
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le Sms a bien été créé pour le '.$date.'.');
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
}
@ -212,6 +219,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
}
@ -230,12 +238,14 @@ namespace controllers\publics;
if (!$content)
{
$all_update_ok = false;
continue;
}
if (!\controllers\internals\Tool::validate_date($date, 'Y-m-d H:i:s') && !\controllers\internals\Tool::validate_date($date, 'Y-m-d H:i'))
{
$all_update_ok = false;
continue;
}
@ -246,6 +256,7 @@ namespace controllers\publics;
if (!$number)
{
unset($numbers[$key]);
continue;
}
@ -255,13 +266,15 @@ namespace controllers\publics;
if (!$numbers && !$contacts && !$groups)
{
$all_update_ok = false;
continue;
}
$success = $this->internal_scheduled->update($id_scheduled, $content, $at, $numbers, $contacts, $groups);
$success = $this->internal_scheduled->update($id_scheduled, $content, $date, $numbers, $contacts, $groups);
if (!$success)
{
$all_update_ok = false;
continue;
}
}
@ -269,10 +282,12 @@ namespace controllers\publics;
if (!$all_update_ok)
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certains SMS n\'ont pas pu êtres mis à jour.');
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
}
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Tous les SMS ont été mis à jour.');
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
}
}

View File

@ -59,6 +59,7 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Sent', 'list'));
}

View File

@ -59,12 +59,14 @@ namespace controllers\publics;
if (!$this->verify_csrf($csrf))
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('SmsStop', 'list'));
}
if (!\controllers\internals\Tool::is_admin())
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour pouvoir supprimer un "STOP Sms" !');
return $this->redirect(\descartes\Router::url('SmsStop', 'list'));
}

View File

@ -58,18 +58,17 @@ namespace models;
return isset($contacts[0]) ? $contacts[0] : false;
}
/**
* Get contacts of a particular group
* Get contacts of a particular group.
*
* @param int $id_group : Id of the group we want contacts for
*
* @return array
*/
public function get_by_group($id_group)
{
$contacts = $this->_select('contact', ['id_group' => $id_group]);
return $contacts;
return $this->_select('contact', ['id_group' => $id_group]);
}
/**

View File

@ -14,7 +14,6 @@ namespace models;
class DataBase extends \descartes\Model
{
//
// PARTIE DES REQUETES SCHEDULEDS_NUMBERS
//

View File

@ -1,5 +1,14 @@
<?php
/*
* 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.
*/
namespace models;

View File

@ -64,16 +64,17 @@ namespace models;
}
/**
* Get scheduleds message not in progress and before a date
* Get scheduleds message not in progress and before a date.
*
* @param string $date : Limit date
*
* @return array
*/
public function get_scheduleds_not_in_progress_before ($date)
public function get_scheduleds_not_in_progress_before($date)
{
return $this->_select('scheduleds', ['<=at' => $date, 'progress' => false]);
}
/**
* Cette fonction retourne les messages programmés avant une date et pour un numéro.
*

View File

@ -15,7 +15,7 @@ namespace models;
/**
* Cette classe gère les accès bdd pour les sendedes.
*/
class Sended extends \descartes\Model
class Sent extends \descartes\Model
{
/**
* Retourne une entrée par son id.