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)