2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
class DataBase extends \descartes\Model
|
|
|
|
{
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
//
|
|
|
|
// PARTIE DES REQUETES RECEIVEDS
|
|
|
|
//
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Récupère les receiveds dont l'id fait partie de la liste fournie.
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @param array $receiveds_ids = Tableau des id des receiveds voulus
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @return array : Retourne un tableau avec les receiveds adaptés
|
|
|
|
*/
|
2019-11-06 18:08:22 +01:00
|
|
|
public function get_receiveds_in($receiveds_ids)
|
2019-10-29 18:33:49 +01:00
|
|
|
{
|
2019-10-30 00:30:39 +01:00
|
|
|
$query = '
|
2019-10-29 14:57:13 +01:00
|
|
|
SELECT *
|
|
|
|
FROM received
|
2019-10-30 00:30:39 +01:00
|
|
|
WHERE id ';
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
//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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
//
|
|
|
|
// PARTIE DES REQUETES GROUPS_CONTACTS
|
|
|
|
//
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Retourne tous les contacts pour un group donnée.
|
|
|
|
*
|
2019-10-30 00:17:10 +01:00
|
|
|
* @param int $id_group : L'id du group
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-30 00:17:10 +01:00
|
|
|
* @return array : Tous les contacts compris dans le group
|
2019-10-29 18:33:49 +01:00
|
|
|
*/
|
2019-11-06 18:08:22 +01:00
|
|
|
public function get_contacts_for_group($id_group)
|
2019-10-29 18:33:49 +01:00
|
|
|
{
|
|
|
|
$query = '
|
2019-10-29 14:57:13 +01:00
|
|
|
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)
|
|
|
|
';
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$params = [
|
2019-10-29 18:33:49 +01:00
|
|
|
'id_group' => $id_group,
|
2019-10-30 00:30:39 +01:00
|
|
|
];
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
return $this->_run_query($query, $params);
|
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
//
|
|
|
|
// PARTIE DES REQUETES SCHEDULEDS
|
|
|
|
//
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Récupère tout les sms programmés non en cours, et dont la date d'envoie inférieure à celle renseignée.
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @param string $date : \Date avant laquelle on veux les sms
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @return array : Tableau avec les sms programmés demandés
|
|
|
|
*/
|
2019-11-06 18:08:22 +01:00
|
|
|
public function get_scheduleds_not_in_progress_before($date)
|
2019-10-29 18:33:49 +01:00
|
|
|
{
|
2019-10-30 00:30:39 +01:00
|
|
|
$query = '
|
2019-10-29 14:57:13 +01:00
|
|
|
SELECT *
|
|
|
|
FROM scheduled
|
|
|
|
WHERE progress = 0
|
|
|
|
AND at <= :date
|
2019-10-30 00:30:39 +01:00
|
|
|
';
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$params = [
|
2019-10-29 18:33:49 +01:00
|
|
|
'date' => $date,
|
2019-10-30 00:30:39 +01:00
|
|
|
];
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
return $this->_run_query($query, $params);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Supprime tous les sms programmés dont l'id fait partie du tableau fourni.
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @param $contacts_ids : Tableau des id des sms à supprimer
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param mixed $scheduleds_ids
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @return int : Nombre de lignes supprimées
|
|
|
|
*/
|
2019-11-06 18:08:22 +01:00
|
|
|
public function delete_scheduleds_in($scheduleds_ids)
|
2019-10-29 18:33:49 +01:00
|
|
|
{
|
2019-10-30 00:30:39 +01:00
|
|
|
$query = '
|
2019-10-29 14:57:13 +01:00
|
|
|
DELETE FROM scheduled
|
2019-10-30 00:30:39 +01:00
|
|
|
WHERE id ';
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
//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($scheduleds_ids);
|
|
|
|
$query .= $generted_in['QUERY'];
|
|
|
|
$params = $generted_in['PARAMS'];
|
|
|
|
|
|
|
|
return $this->_run_query($query, $params, self::ROWCOUNT);
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
//
|
|
|
|
// PARTIE DES REQUETES SCHEDULEDS_CONTACTS
|
|
|
|
//
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Change le statut des scheduleds dont l'id est fourni dans $scheduleds_id.
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @param array $scheduleds_ids = Tableau des id des sms voulus
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param mixed $progress
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @return int : Retourne le nombre de lignes mises à jour
|
|
|
|
*/
|
2019-11-06 18:08:22 +01:00
|
|
|
public function update_progress_scheduleds_in($scheduleds_ids, $progress)
|
2019-10-29 18:33:49 +01:00
|
|
|
{
|
2019-10-30 00:30:39 +01:00
|
|
|
$query = '
|
2019-10-29 14:57:13 +01:00
|
|
|
UPDATE scheduled
|
|
|
|
SET progress = :progress
|
2019-10-30 00:30:39 +01:00
|
|
|
WHERE id ';
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
//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($scheduleds_ids);
|
|
|
|
$query .= $generted_in['QUERY'];
|
|
|
|
$params = $generted_in['PARAMS'];
|
2019-10-30 00:30:39 +01:00
|
|
|
$params['progress'] = (bool) $progress;
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
return $this->_run_query($query, $params, self::ROWCOUNT);
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
//
|
|
|
|
// PARTIE DES REQUETES SCHEDULEDS_NUMBERS
|
|
|
|
//
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Retourne tous les numéros pour un scheduled donné.
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @param int $id_scheduled : L'id du scheduled
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @return array : Tous les numéro compris dans le scheduled
|
|
|
|
*/
|
2019-11-06 18:08:22 +01:00
|
|
|
public function get_numbers_for_scheduled($id_scheduled)
|
2019-10-29 18:33:49 +01:00
|
|
|
{
|
|
|
|
$query = '
|
2019-10-29 14:57:13 +01:00
|
|
|
SELECT *
|
|
|
|
FROM scheduled_number
|
|
|
|
WHERE id_scheduled = :id_scheduled
|
|
|
|
';
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$params = [
|
2019-10-29 18:33:49 +01:00
|
|
|
'id_scheduled' => $id_scheduled,
|
2019-10-30 00:30:39 +01:00
|
|
|
];
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
return $this->_run_query($query, $params);
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
//
|
|
|
|
// PARTIE DES REQUETES SCHEDULEDS_GROUPS
|
|
|
|
//
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Retourne tous les groups pour un scheduled donnée.
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @param int $id_scheduled : L'id du schedulede
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-30 00:17:10 +01:00
|
|
|
* @return array : Tous les groups compris dans le scheduled
|
2019-10-29 18:33:49 +01:00
|
|
|
*/
|
2019-11-06 18:08:22 +01:00
|
|
|
public function get_groups_for_scheduled($id_scheduled)
|
2019-10-29 18:33:49 +01:00
|
|
|
{
|
|
|
|
$query = '
|
2019-10-29 14:57:13 +01:00
|
|
|
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)
|
|
|
|
';
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$params = [
|
2019-10-29 18:33:49 +01:00
|
|
|
'id_scheduled' => $id_scheduled,
|
2019-10-30 00:30:39 +01:00
|
|
|
];
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
return $this->_run_query($query, $params);
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
//
|
|
|
|
// PARTIE DES REQUETES USERS
|
|
|
|
//
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Récupère un utilisateur à partir de son email.
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @param string $email = L'email de l'utilisateur
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @return array : Retourne l'utilisateur
|
|
|
|
*/
|
2019-11-06 18:08:22 +01:00
|
|
|
public function get_user_from_email($email)
|
2019-10-29 18:33:49 +01:00
|
|
|
{
|
2019-10-30 00:30:39 +01:00
|
|
|
$query = '
|
2019-10-29 14:57:13 +01:00
|
|
|
SELECT *
|
|
|
|
FROM user
|
2019-10-30 00:30:39 +01:00
|
|
|
WHERE email = :email';
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
'email' => $email,
|
|
|
|
];
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
return $this->_run_query($query, $params, self::FETCH);
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
//
|
|
|
|
// PARTIE DES REQUETES TRANSFERS
|
|
|
|
//
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Change le statut des tranfers dont l'id est fourni dans $transfers_id.
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @param array $transfers_ids = Tableau des id des transfers voulus
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param mixed $progress
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @return int : Retourne le nombre de lignes mises à jour
|
|
|
|
*/
|
2019-11-06 18:08:22 +01:00
|
|
|
public function update_progress_transfers_in($transfers_ids, $progress)
|
2019-10-29 18:33:49 +01:00
|
|
|
{
|
2019-10-30 00:30:39 +01:00
|
|
|
$query = '
|
2019-10-29 14:57:13 +01:00
|
|
|
UPDATE transfer
|
|
|
|
SET progress = :progress
|
2019-10-30 00:30:39 +01:00
|
|
|
WHERE id ';
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
//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'];
|
2019-10-30 00:30:39 +01:00
|
|
|
$params['progress'] = (bool) $progress;
|
2019-10-29 18:33:49 +01:00
|
|
|
|
|
|
|
return $this->_run_query($query, $params, self::ROWCOUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Supprime tous les transfers dont l'id fait partie du tableau fourni.
|
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @param $transfers_ids : Tableau des id des transfers à supprimer
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-10-29 18:33:49 +01:00
|
|
|
* @return int : Nombre de lignes supprimées
|
|
|
|
*/
|
2019-11-06 18:08:22 +01:00
|
|
|
public function delete_transfers_in($transfers_ids)
|
2019-10-29 18:33:49 +01:00
|
|
|
{
|
2019-10-30 00:30:39 +01:00
|
|
|
$query = '
|
2019-10-29 14:57:13 +01:00
|
|
|
DELETE FROM transfer
|
2019-10-30 00:30:39 +01:00
|
|
|
WHERE id ';
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
//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);
|
|
|
|
}
|
|
|
|
}
|