Transfer few methods from model database to propers tables models
This commit is contained in:
parent
f1170c82ea
commit
155cace466
|
@ -51,7 +51,7 @@ class Console extends \descartes\InternalController
|
||||||
|
|
||||||
echo "Début de l'envoi des Sms programmés\n";
|
echo "Début de l'envoi des Sms programmés\n";
|
||||||
|
|
||||||
$scheduleds = $this->model_database->get_scheduleds_not_in_progress_before($now);
|
$scheduleds = $this->model_scheduled->get_scheduleds_not_in_progress_before($now);
|
||||||
|
|
||||||
$ids_scheduleds = [];
|
$ids_scheduleds = [];
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class Console extends \descartes\InternalController
|
||||||
foreach ($groups as $group)
|
foreach ($groups as $group)
|
||||||
{
|
{
|
||||||
//On récupère les contacts du group et on les ajoute aux numéros
|
//On récupère les contacts du group et on les ajoute aux numéros
|
||||||
$contacts = $this->model_database->get_contacts_for_group($group['id']);
|
$contacts = $this->model_database->get_by_group($group['id']);
|
||||||
foreach ($contacts as $contact)
|
foreach ($contacts as $contact)
|
||||||
{
|
{
|
||||||
$numbers[] = $contact['number'];
|
$numbers[] = $contact['number'];
|
||||||
|
@ -151,7 +151,10 @@ class Console extends \descartes\InternalController
|
||||||
|
|
||||||
echo "Tous les Sms sont en cours d'envoi.\n";
|
echo "Tous les Sms sont en cours d'envoi.\n";
|
||||||
//Tous les Sms ont été envoyés.
|
//Tous les Sms ont été envoyés.
|
||||||
$this->model_database->delete_scheduleds_in($ids_scheduleds);
|
foreach ($ids_scheduleds as $id_scheduled)
|
||||||
|
{
|
||||||
|
$this->model_scheduled->delete($id_scheduled);
|
||||||
|
}
|
||||||
|
|
||||||
//On dors 2 secondes
|
//On dors 2 secondes
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
@ -365,7 +368,7 @@ class Console extends \descartes\InternalController
|
||||||
|
|
||||||
$this->model_database->update_progress_transfers_in($ids_transfers, true);
|
$this->model_database->update_progress_transfers_in($ids_transfers, true);
|
||||||
|
|
||||||
$receiveds = $this->model_database->get_receiveds_in($ids_receiveds);
|
$receiveds = $this->model_received->gets($ids_receiveds);
|
||||||
|
|
||||||
$users = $this->model_user->_select('users', ['transfer' => true]);
|
$users = $this->model_user->_select('users', ['transfer' => true]);
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,19 @@ namespace models;
|
||||||
|
|
||||||
return isset($contacts[0]) ? $contacts[0] : false;
|
return isset($contacts[0]) ? $contacts[0] : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne une liste de contactes sous forme d'un tableau.
|
* Retourne une liste de contactes sous forme d'un tableau.
|
||||||
|
|
|
@ -15,89 +15,11 @@ namespace models;
|
||||||
class DataBase extends \descartes\Model
|
class DataBase extends \descartes\Model
|
||||||
{
|
{
|
||||||
|
|
||||||
//
|
|
||||||
// PARTIE DES REQUETES RECEIVEDS
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Récupère les receiveds dont l'id fait partie de la liste fournie.
|
|
||||||
*
|
|
||||||
* @param array $receiveds_ids = Tableau des id des receiveds voulus
|
|
||||||
*
|
|
||||||
* @return array : Retourne un tableau avec les receiveds adaptés
|
|
||||||
*/
|
|
||||||
public function get_receiveds_in($receiveds_ids)
|
|
||||||
{
|
|
||||||
$query = '
|
|
||||||
SELECT *
|
|
||||||
FROM received
|
|
||||||
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($receiveds_ids);
|
|
||||||
$query .= $generted_in['QUERY'];
|
|
||||||
$params = $generted_in['PARAMS'];
|
|
||||||
|
|
||||||
return $this->_run_query($query, $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// PARTIE DES REQUETES GROUPS_CONTACTS
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retourne tous les contacts pour un group donnée.
|
|
||||||
*
|
|
||||||
* @param int $id_group : L'id du group
|
|
||||||
*
|
|
||||||
* @return array : Tous les contacts compris dans le group
|
|
||||||
*/
|
|
||||||
public function get_contacts_for_group($id_group)
|
|
||||||
{
|
|
||||||
$query = '
|
|
||||||
SELECT con.id as id, con.name as name, con.number as number
|
|
||||||
FROM group_contact as g_c
|
|
||||||
JOIN contact as con
|
|
||||||
ON (g_c.id_contact = con.id)
|
|
||||||
WHERE(g_c.id_group = :id_group)
|
|
||||||
';
|
|
||||||
|
|
||||||
$params = [
|
|
||||||
'id_group' => $id_group,
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this->_run_query($query, $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// PARTIE DES REQUETES SCHEDULEDS
|
// PARTIE DES REQUETES SCHEDULEDS
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
|
||||||
* Récupère tout les sms programmés non en cours, et dont la date d'envoie inférieure à celle renseignée.
|
|
||||||
*
|
|
||||||
* @param string $date : \Date avant laquelle on veux les sms
|
|
||||||
*
|
|
||||||
* @return array : Tableau avec les sms programmés demandés
|
|
||||||
*/
|
|
||||||
public function get_scheduleds_not_in_progress_before($date)
|
|
||||||
{
|
|
||||||
$query = '
|
|
||||||
SELECT *
|
|
||||||
FROM scheduled
|
|
||||||
WHERE progress = 0
|
|
||||||
AND at <= :date
|
|
||||||
';
|
|
||||||
|
|
||||||
$params = [
|
|
||||||
'date' => $date,
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this->_run_query($query, $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supprime tous les sms programmés dont l'id fait partie du tableau fourni.
|
* Supprime tous les sms programmés dont l'id fait partie du tableau fourni.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
<?php
|
<?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;
|
namespace models;
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,17 @@ namespace models;
|
||||||
return $this->_run_query($query, $params);
|
return $this->_run_query($query, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
return $this->_select('scheduleds', ['<=at' => $date, 'progress' => false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cette fonction retourne les messages programmés avant une date et pour un numéro.
|
* Cette fonction retourne les messages programmés avant une date et pour un numéro.
|
||||||
*
|
*
|
||||||
|
|
4
todo.txt
4
todo.txt
|
@ -2,9 +2,9 @@ Migrate to latest version of descartes. Remove all useless functions
|
||||||
y Account.php (almost done need to do user after)
|
y Account.php (almost done need to do user after)
|
||||||
y Command.php
|
y Command.php
|
||||||
y Connect.php
|
y Connect.php
|
||||||
y Console.php
|
p Console.php
|
||||||
y Contact.php
|
y Contact.php
|
||||||
Dashboard.php
|
y Dashboard.php
|
||||||
y Discussion.php
|
y Discussion.php
|
||||||
y Event.php
|
y Event.php
|
||||||
y Group.php
|
y Group.php
|
||||||
|
|
Loading…
Reference in New Issue