Update all models to use StandardModel basis
This commit is contained in:
parent
0e22f3d02c
commit
155a048834
Binary file not shown.
|
@ -1,140 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of RaspiSMS.
|
||||
*
|
||||
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
|
||||
*
|
||||
* This source file is subject to the GPL-3.0 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 = null, $page = null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -168,14 +168,6 @@ CREATE TABLE IF NOT EXISTS validation
|
|||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS transfer
|
||||
(
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
id_received INT NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY (id_received) REFERENCES received (id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS smsstop
|
||||
(
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
|
|
|
@ -416,7 +416,7 @@
|
|||
}
|
||||
|
||||
|
||||
$query = "UPDATE `" . $table . "` SET " . implode(', ', $sets) . " WHERE 1 AND " . implode(' AND ', $wheres);
|
||||
$query = "UPDATE `" . $table . "` SET " . implode(', ', $sets) . " WHERE 1 " . (count($wheres) ? " AND " : "") . implode(' AND ', $wheres);
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@
|
|||
$params = array_merge($params, $condition['PARAM']);
|
||||
}
|
||||
|
||||
$query = "DELETE FROM `" . $table . "` WHERE 1 AND " . implode(' AND ', $wheres);
|
||||
$query = "DELETE FROM `" . $table . "` WHERE 1 " . (count($wheres) ? " AND " : "") . implode(' AND ', $wheres);
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Cette classe gère les accès bdd pour les commandes.
|
||||
*/
|
||||
class Command extends StandardModel
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -11,167 +11,11 @@
|
|||
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Cette classe gère les accès bdd pour les contactes.
|
||||
*/
|
||||
class Contact extends \descartes\Model
|
||||
class Contact extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Retourne une entrée par son id.
|
||||
*
|
||||
* @param int $id : L'id de l'entrée
|
||||
*
|
||||
* @return array : L'entrée
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$contacts = $this->_select('contact', ['id' => $id]);
|
||||
|
||||
return isset($contacts[0]) ? $contacts[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une entrée par son numéro de tel.
|
||||
*
|
||||
* @param string $number : Le numéro de tél
|
||||
*
|
||||
* @return array : L'entrée
|
||||
*/
|
||||
public function get_by_number($number)
|
||||
{
|
||||
$contacts = $this->_select('contact', ['number' => $number]);
|
||||
|
||||
return isset($contacts[0]) ? $contacts[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a contact for a user by a number
|
||||
* @param int $id_user : user id
|
||||
* @param string $number : Contact number
|
||||
* @return array
|
||||
*/
|
||||
public function get_by_number_and_user($number, $id_user)
|
||||
{
|
||||
return $this->_select_one('contact', ['number' => $number, 'id_user' => $id_user]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une entrée par son numéro de tel.
|
||||
*
|
||||
* @param string $name : Le numéro de tél
|
||||
*
|
||||
* @return array : L'entrée
|
||||
*/
|
||||
public function get_by_name($name)
|
||||
{
|
||||
$contacts = $this->_select('contact', ['name' => $name]);
|
||||
|
||||
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)
|
||||
{
|
||||
return $this->_select('contact', ['id_group' => $id_group]);
|
||||
}
|
||||
|
||||
/**
|
||||
* List contacts for a user
|
||||
* @param int $id_user : user id
|
||||
* @param mixed(int|bool) $nb_entry : Number of entry to return
|
||||
* @param mixed(int|bool) $page : Pagination, will offset $nb_entry * $page results
|
||||
* @return array
|
||||
*/
|
||||
public function list_for_user($id_user, $limit, $offset)
|
||||
{
|
||||
return $this->_select('contact', ['id_user' => $id_user], null, false, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de contactes sous forme d'un tableau.
|
||||
* @param int $id_user : user id
|
||||
* @param array $ids : un ou plusieurs id d'entrées à récupérer
|
||||
* @return array : La liste des entrées
|
||||
*/
|
||||
public function gets_for_user($id_user, $ids)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM contact
|
||||
WHERE id_user = :id_user
|
||||
AND ';
|
||||
|
||||
//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'];
|
||||
$params['id_user'] = $id_user;
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprimer un contact par son id.
|
||||
*
|
||||
* @param array $id : un ou plusieurs id d'entrées à supprimer
|
||||
*
|
||||
* @return int : Le nombre de lignes supprimées
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM contact
|
||||
WHERE id = :id';
|
||||
|
||||
$params = ['id' => $id];
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert une contacte.
|
||||
*
|
||||
* @param array $contact : La contacte à insérer avec les champs name, script, admin & admin
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
||||
*/
|
||||
public function insert($contact)
|
||||
{
|
||||
$result = $this->_insert('contact', $contact);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour une contacte par son id.
|
||||
*
|
||||
* @param int $id : L'id de la contact à modifier
|
||||
* @param array $contact : Les données à mettre à jour pour la contacte
|
||||
*
|
||||
* @return int : le nombre de ligne modifiées
|
||||
*/
|
||||
public function update($id, $contact)
|
||||
{
|
||||
return $this->_update('contact', $contact, ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compte le nombre d'entrées dans la table contact.
|
||||
*
|
||||
* @return int : Le nombre de contact
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->_count('contact');
|
||||
}
|
||||
protected function get_table_name() : string { return 'contact'; }
|
||||
}
|
||||
|
|
111
models/Event.php
111
models/Event.php
|
@ -11,114 +11,23 @@
|
|||
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Cette classe gère les accès bdd pour les eventes.
|
||||
*/
|
||||
class Event extends \descartes\Model
|
||||
class Event extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Retourne une entrée par son id.
|
||||
*
|
||||
* @param int $id : L'id de l'entrée
|
||||
*
|
||||
* @return array : L'entrée
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$events = $this->_select('event', ['id' => $id]);
|
||||
protected function get_table_name() : string { return 'event'; }
|
||||
|
||||
return isset($events[0]) ? $events[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de eventes sous forme d'un tableau.
|
||||
*
|
||||
* @param int $limit : Nombre de résultat maximum à retourner
|
||||
* @param int $offset : Nombre de résultat à ingnorer
|
||||
* Gets lasts x events for a user order by date
|
||||
* @param int $id_user : User id
|
||||
* @param int $nb_entry : Number of events to return
|
||||
* @return array
|
||||
*/
|
||||
public function list($limit, $offset)
|
||||
public function get_lasts_by_date_for_user (int $id_user, int $nb_entry)
|
||||
{
|
||||
return $this->_select('event', [], null, false, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne les X dernières entrées triées par date.
|
||||
*
|
||||
* @param mixed $nb_entry
|
||||
*
|
||||
* @return array : Les dernières entrées
|
||||
*/
|
||||
public function get_lasts_by_date($nb_entry)
|
||||
{
|
||||
return $this->_select('event', [], 'at', true, $nb_entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de eventes 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 event
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de eventes sous forme d'un tableau.
|
||||
*
|
||||
* @param array $ids : un ou plusieurs id d'entrées à supprimer
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return int : Le nombre de lignes supprimées
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM event
|
||||
WHERE id = :id';
|
||||
|
||||
$params = ['id' => $id];
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert une evente.
|
||||
*
|
||||
* @param array $event : La evente à insérer avec les champs name, script, admin & admin
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
||||
*/
|
||||
public function insert($event)
|
||||
{
|
||||
$result = $this->_insert('event', $event);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compte le nombre d'entrées dans la table.
|
||||
*
|
||||
* @return int : Le nombre d'entrées
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->_count('event');
|
||||
return $this->_select('event', ['id_user' => $id_user], 'at', true, $nb_entry);
|
||||
}
|
||||
}
|
||||
|
|
179
models/Group.php
179
models/Group.php
|
@ -11,184 +11,65 @@
|
|||
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Cette classe gère les accès bdd pour les groups.
|
||||
*/
|
||||
class Group extends \descartes\Model
|
||||
class Group extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Retourne une entrée par son id.
|
||||
*
|
||||
* @param int $id : L'id de l'entrée
|
||||
*
|
||||
* @return array : L'entrée
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$groups = $this->_select('group', ['id' => $id]);
|
||||
protected function get_table_name() : string { return 'group'; }
|
||||
|
||||
return isset($groups[0]) ? $groups[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une entrée par son numéro de tel.
|
||||
*
|
||||
* @param string $name : Le numéro de tél
|
||||
*
|
||||
* @return array : L'entrée
|
||||
* Return a group by his name for a user
|
||||
* @param int $id_user : User id
|
||||
* @param string $name : Group name
|
||||
* @return array
|
||||
*/
|
||||
public function get_by_name($name)
|
||||
public function get_by_name_for_user (int $id_user, string $name)
|
||||
{
|
||||
$groups = $this->_select('group', ['name' => $name]);
|
||||
|
||||
return isset($groups[0]) ? $groups[0] : false;
|
||||
return $this->_select_one($this->get_table_name(), ['id_user' => $id_user, 'name' => $name]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne une liste de groups sous forme d'un tableau.
|
||||
*
|
||||
* @param int $limit : Nombre de résultat maximum à retourner
|
||||
* @param int $offset : Nombre de résultat à ingnorer
|
||||
* Delete relations between group and contacts for a group
|
||||
* @param int $id_group : Group id
|
||||
* @return int : Number of deleted rows
|
||||
*/
|
||||
public function list($limit, $offset)
|
||||
public function delete_group_contact_relations (int $id_group)
|
||||
{
|
||||
return $this->_select('group', [], null, false, $limit, $offset);
|
||||
return $this->delete('group_contact', ['id_group' => $id_group]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne une liste de groups 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
|
||||
* Insert a relation between a group and a contact
|
||||
* @param int $id_group : Group id
|
||||
* @param int $id_contact : Contact id
|
||||
* @return mixed (bool|int) : False on error, new row id else
|
||||
*/
|
||||
public function gets($ids)
|
||||
public function insert_group_contact_relation (int $id_group, int $id_contact)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM `group`
|
||||
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);
|
||||
$success = (bool) $this->_insert('group_contact', ['id_group' => $id_group, 'id_contact' => $id_contact]);
|
||||
return ($success ? $this->_last_id() : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de groups sous forme d'un tableau.
|
||||
*
|
||||
* @param array $ids : un ou plusieurs id d'entrées à supprimer
|
||||
*
|
||||
* @return int : Le nombre de lignes supprimées
|
||||
*/
|
||||
public function deletes($ids)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM `group`
|
||||
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, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime les liens group/contact pour un group précis.
|
||||
*
|
||||
* @param int $id_group : L'id du group pour lequel supprimer
|
||||
*
|
||||
* @return int : Le nmbre d'entrées modifiées
|
||||
* Get groups contacts
|
||||
* @param int $id_group : Group id
|
||||
* @return array : Contacts of the group
|
||||
*/
|
||||
public function delete_group_contacts($id_group)
|
||||
{
|
||||
return $this->_delete('group_contact', ['id_group' => $id_group]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert une group.
|
||||
*
|
||||
* @param array $group : La group à insérer avec les champs name, script, admin & admin
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
||||
*/
|
||||
public function insert($group)
|
||||
{
|
||||
$result = $this->_insert('group', $group);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert un lien group/contact.
|
||||
*
|
||||
* @param int $id_group : L'id du group à liéer
|
||||
* @param int $id_contact : L'id du contact à liéer
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
||||
*/
|
||||
public function insert_group_contact($id_group, $id_contact)
|
||||
{
|
||||
$result = $this->_insert('group_contact', ['id_group' => $id_group, 'id_contact' => $id_contact]);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour une group par son id.
|
||||
*
|
||||
* @param int $id : L'id de la group à modifier
|
||||
* @param array $group : Les données à mettre à jour pour la group
|
||||
*
|
||||
* @return int : le nombre de ligne modifiées
|
||||
*/
|
||||
public function update($id, $group)
|
||||
{
|
||||
return $this->_update('group', $group, ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compte le nombre d'entrées dans la table.
|
||||
*
|
||||
* @return int : Le nombre d'entrées
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->_count('group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne les contact pour un group.
|
||||
*
|
||||
* @param string $id : L'id du group
|
||||
*
|
||||
* @return array : Un tableau avec les contact
|
||||
*/
|
||||
public function get_contacts($id)
|
||||
public function get_contacts (int $id_group)
|
||||
{
|
||||
$query = '
|
||||
SELECT *
|
||||
FROM `contact`
|
||||
WHERE id IN (SELECT id_contact FROM `group_contact` WHERE id_group = :id)
|
||||
WHERE id IN (SELECT id_contact FROM `group_contact` WHERE id_group = :id_group)
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id' => $id,
|
||||
];
|
||||
$params = ['id_group' => $id_group];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
|
|
@ -11,91 +11,23 @@
|
|||
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Allow phone database management
|
||||
*/
|
||||
class Phone extends \descartes\Model
|
||||
class Phone extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Return a phone by his id
|
||||
* @param int $id : Phone id
|
||||
* @return array
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
public function get (int $id)
|
||||
{
|
||||
return $this->_select_one('phone', ['id' => $id]);
|
||||
}
|
||||
protected function get_table_name() : string { return 'phone'; }
|
||||
|
||||
|
||||
/**
|
||||
* Return list of phones.
|
||||
* @param int $id_user : User id
|
||||
* @param int $limit : Number of user to return
|
||||
* @param int $offset : Number of user to skip
|
||||
*/
|
||||
public function list_for_user($id_user, $limit, $offset)
|
||||
{
|
||||
return $this->_select('phone', ['id_user' => $id_user], null, false, $limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a phone by his number and user
|
||||
* @param string $number : phone number
|
||||
* @param int $id_user : user id
|
||||
* @param string $number : phone number
|
||||
* @return array
|
||||
*/
|
||||
public function get_by_number_for_user (string $number, int $id_user)
|
||||
public function get_by_number_for_user (int $id_user, string $number)
|
||||
{
|
||||
return $this->_select_one('phone', ['number' => $number, 'id_user' => $id_user]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find phones of a user
|
||||
* @param string $id_user : user's id
|
||||
* @return array
|
||||
*/
|
||||
public function gets_for_user (int $id_user)
|
||||
{
|
||||
return $this->_select('phone', ['id_user' => $id_user]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a phone
|
||||
* @param int $id : phone id
|
||||
* @return array
|
||||
*/
|
||||
public function delete_for_user ($id_user, $id)
|
||||
{
|
||||
return $this->_delete('phone', ['id_user' => $id_user, 'id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a phone
|
||||
* @param int $id_user : User to insert phone for
|
||||
* @param string $number : The number of the phone
|
||||
* @param string $adapter : The adapter to use the phone
|
||||
* @param string JSON $adapter_datas : A json string representing the datas of the adapter (for exemple credentials of an api)
|
||||
* @return mixed bool : false on error, true on success
|
||||
*/
|
||||
public function insert($phone)
|
||||
{
|
||||
return (bool) $this->_insert('phone', $phone);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a phone
|
||||
* @param int $id : Id of the phone
|
||||
* @param int $id_user : User to insert phone for
|
||||
* @param array $phone : updated datas
|
||||
* @return mixed bool : false on error, true on success
|
||||
*/
|
||||
public function update_for_user ($id_user, $id, $phone)
|
||||
{
|
||||
return (bool) $this->_update('phone', $phone, ['id_user' => $id_user, 'id' => $id]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,22 +14,16 @@ namespace models;
|
|||
/**
|
||||
* Cette classe gère les accès bdd pour les receivedes.
|
||||
*/
|
||||
class Received extends \descartes\Model
|
||||
class Received extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Retourne une entrée par son id.
|
||||
*
|
||||
* @param int $id : L'id de l'entrée
|
||||
*
|
||||
* @return array : L'entrée
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return $this->_select_one('received', ['id' => $id]);
|
||||
}
|
||||
|
||||
protected function get_table_name() : string { return 'received'; }
|
||||
|
||||
/**
|
||||
* Return a list of sms where destination in array allowed_destinations
|
||||
* Return a list of received for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $limit : Max results to return
|
||||
* @param int $offset : Number of results to ignore
|
||||
|
@ -51,15 +45,117 @@ namespace models;
|
|||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction retourne les X dernières entrées triées par date pour un utilisateur.
|
||||
*
|
||||
* @param int $id_user : User id
|
||||
* @param int $nb_entry : Nombre d'entrée à retourner
|
||||
*
|
||||
* @return array : Les dernières entrées
|
||||
* Return a list of receiveds in a group of ids and for a user
|
||||
* @param int $id_user : user id
|
||||
* @param array $ids : ids of receiveds to find
|
||||
* @return array
|
||||
*/
|
||||
public function get_lasts_for_user_by_date($id_user, $nb_entry)
|
||||
public function gets_in_for_user(int $id_user, $ids)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM received
|
||||
WHERE destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
AND 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'];
|
||||
$params['id_user'] = $id_user;
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a entry by his id for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id : Entry id
|
||||
* @return int : Number of removed rows
|
||||
*/
|
||||
public function delete_for_user(int $id_user, int $id)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM received
|
||||
WHERE id = :id
|
||||
AND destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params = ['id_user' => $id_user, 'id' => $id];
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a received sms for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id : Entry id
|
||||
* @param array $datas : datas to update
|
||||
*
|
||||
* @return int : number of modified rows
|
||||
*/
|
||||
public function update_for_user (int $id_user, int $id, array $datas)
|
||||
{
|
||||
$params = [];
|
||||
$sets = [];
|
||||
|
||||
foreach ($datas as $label => $value)
|
||||
{
|
||||
$label = preg_replace('#[^a-zA-Z0-9_]#', '', $label);
|
||||
$params['set_' . $label] = $value;
|
||||
$sets[] = '`' . $label . '` = :set_' . $label . ' ';
|
||||
}
|
||||
|
||||
$query = '
|
||||
UPDATE `received`
|
||||
SET ' . implode(', ', $sets) . '
|
||||
WHERE id = :id
|
||||
AND destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
//If try to update destination, also check it does belong to user
|
||||
if ($sets['set_destination'] ?? false)
|
||||
{
|
||||
$query .= ' AND :set_destination IN (SELECT number FROM phone WHERE id_user = :id_user)'
|
||||
}
|
||||
|
||||
$params['id'] = $id;
|
||||
$params['id_user'] = $id_user;
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Count number of received sms for user
|
||||
* @param int $id_user : user id
|
||||
* @return int : Number of received SMS for user
|
||||
*/
|
||||
public function count_for_user($id_user)
|
||||
{
|
||||
$query = '
|
||||
SELECT COUNT(id) as nb
|
||||
FROM received
|
||||
WHERE destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params)[0]['nb'] ?? 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return x last receiveds message for a user, order by date
|
||||
* @param int $id_user : User id
|
||||
* @param int $nb_entry : Number of receiveds messages to return
|
||||
* @return array
|
||||
*/
|
||||
public function get_lasts_by_date_for_user($id_user, $nb_entry)
|
||||
{
|
||||
$nb_entry = (int) $nb_entry;
|
||||
|
||||
|
@ -77,118 +173,40 @@ namespace models;
|
|||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des received sous forme d'un tableau.
|
||||
*
|
||||
* @param string $origin : Le numéro depuis lequel est envoyé le message
|
||||
*
|
||||
* @return array : La liste des received
|
||||
*/
|
||||
public function get_by_origin($origin)
|
||||
{
|
||||
return $this->_select('received', ['origin' => $origin]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de receivedes 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
|
||||
* Return receiveds for an origin and a user
|
||||
* @param int $id_user : User id
|
||||
* @param string $origin : Number who sent the message
|
||||
* @return array
|
||||
*/
|
||||
public function gets($ids)
|
||||
public function gets_by_origin_for_user(int $id_user, string $origin)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM received
|
||||
WHERE id ';
|
||||
$nb_entry = (int) $nb_entry;
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de receivedes sous forme d'un tableau.
|
||||
*
|
||||
* @param array $ids : un ou plusieurs id d'entrées à supprimer
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return int : Le nombre de lignes supprimées
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM received
|
||||
WHERE id = :id';
|
||||
|
||||
$params = ['id' => $id];
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert une receivede.
|
||||
*
|
||||
* @param array $received : La receivede à insérer avec les champs name, script, admin & admin
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
||||
*/
|
||||
public function insert($received)
|
||||
{
|
||||
$result = $this->_insert('received', $received);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour une receivede par son id.
|
||||
*
|
||||
* @param int $id : L'id de la received à modifier
|
||||
* @param array $received : Les données à mettre à jour pour la receivede
|
||||
*
|
||||
* @return int : le nombre de ligne modifiées
|
||||
*/
|
||||
public function update($id, $received)
|
||||
{
|
||||
return $this->_update('received', $received, ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of received sms for user
|
||||
* @param int $id_user : user id
|
||||
* @return int : Number of received SMS for user
|
||||
*/
|
||||
public function count($id_user)
|
||||
{
|
||||
$query = '
|
||||
SELECT COUNT(id) as nb
|
||||
SELECT *
|
||||
FROM received
|
||||
WHERE destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
AND origin = :origin
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
'origin' => $origin,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params)[0]['nb'] ?? 0;
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Récupère le nombre de SMS envoyés pour chaque jour depuis une date.
|
||||
* Get number of sended SMS for every date since a date for a specific user
|
||||
* @param int $id_user : user id
|
||||
* @param \DateTime $date : La date depuis laquelle on veux les SMS
|
||||
*
|
||||
* @return array : Tableau avec le nombre de SMS depuis la date
|
||||
* @param \DateTime $date : Date since which we want the messages
|
||||
* @return array
|
||||
*/
|
||||
public function count_for_user_by_day_since($id_user, $date)
|
||||
public function count_by_day_since_for_user($id_user, $date)
|
||||
{
|
||||
$query = "
|
||||
SELECT COUNT(id) as nb, DATE_FORMAT(at, '%Y-%m-%d') as at_ymd
|
||||
|
@ -207,18 +225,28 @@ namespace models;
|
|||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne toutes les discussions, càd les numéros pour lesquels ont a a la fois un message et une réponse.
|
||||
* Return all discussions (ie : numbers we have a message received from or sended to) for a user
|
||||
* @param int $id_user : User id
|
||||
* @return array
|
||||
*/
|
||||
public function get_discussions()
|
||||
public function get_discussions_for_user(int $id_user)
|
||||
{
|
||||
$query = '
|
||||
SELECT MAX(at) as at, number
|
||||
FROM (SELECT at, destination as number FROM sended UNION (SELECT at, origin as number FROM received)) as discussions
|
||||
SELECT at, number
|
||||
FROM (
|
||||
SELECT at, destination as number FROM sended
|
||||
WHERE origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
UNION (
|
||||
SELECT at, origin as number FROM received
|
||||
WHERE destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
)
|
||||
) as discussions
|
||||
GROUP BY number
|
||||
ORDER BY at DESC
|
||||
';
|
||||
|
||||
return $this->_run_query($query);
|
||||
$params = ['id_user' => $id_user];
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,24 +273,25 @@ namespace models;
|
|||
}
|
||||
|
||||
/**
|
||||
* Récupère les SMS reçus depuis une date pour un numero.
|
||||
*
|
||||
* @param $date : La date depuis laquelle on veux les SMS (au format 2014-10-25 20:10:05)
|
||||
* @param $origin : Le numéro
|
||||
*
|
||||
* @return array : Tableau avec tous les SMS depuis la date
|
||||
* Find messages received since a date for a certain origin and user
|
||||
* @param int $id_user : User id
|
||||
* @param $date : Date we want messages sinces
|
||||
* @param string $origin : Origin number
|
||||
* @return array
|
||||
*/
|
||||
public function get_since_for_origin_by_date($date, $origin)
|
||||
public function get_since_by_date_for_origin_and_user(int $id_user, $date, string $origin)
|
||||
{
|
||||
$query = "
|
||||
SELECT *
|
||||
FROM received
|
||||
WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s')
|
||||
AND origin = :origin
|
||||
AND destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
ORDER BY at ASC
|
||||
";
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user
|
||||
'date' => $date,
|
||||
'origin' => $origin,
|
||||
];
|
||||
|
|
|
@ -11,83 +11,138 @@
|
|||
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Cette classe gère les accès bdd pour les scheduledes.
|
||||
*/
|
||||
class Scheduled extends \descartes\Model
|
||||
class Scheduled extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Retourne une entrée par son id.
|
||||
*
|
||||
* @param int $id : L'id de l'entrée
|
||||
*
|
||||
* @return array : L'entrée
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$scheduleds = $this->_select('scheduled', ['id' => $id]);
|
||||
protected function get_table_name() : string { return 'scheduled'; }
|
||||
|
||||
return isset($scheduleds[0]) ? $scheduleds[0] : false;
|
||||
|
||||
/**
|
||||
* Return numbers for a scheduled message
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_numbers($id_scheduled)
|
||||
{
|
||||
return $this->_select('scheduled_number', ['id_scheduled' => $id_scheduled]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de scheduledes sous forme d'un tableau.
|
||||
* @param int $id_user : User id
|
||||
* @param int $limit : Nombre de résultat maximum à retourner
|
||||
* @param int $offset : Nombre de résultat à ingnorer
|
||||
*/
|
||||
public function list($id_user, $limit, $offset)
|
||||
{
|
||||
return $this->_select('scheduled', ['id_user' => $id_user], null, false, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de scheduledes 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
|
||||
* Return contacts for a scheduled message
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function gets($ids)
|
||||
public function get_contacts($id_scheduled)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM scheduled
|
||||
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'];
|
||||
|
||||
$query = 'SELECT * FROM contact WHERE id IN (SELECT id_contact FROM scheduled_contact WHERE id_scheduled = :id_scheduled)';
|
||||
$params = ['id_scheduled' => $id_scheduled];
|
||||
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.
|
||||
*
|
||||
* @param \DateTime $date : La date avant laquelle on veux le message
|
||||
* @param string $number : Le numéro
|
||||
*
|
||||
* @return array : Les messages programmés avant la date
|
||||
* Return groups for a scheduled message
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_before_date_for_number($date, $number)
|
||||
public function get_groups($id_scheduled)
|
||||
{
|
||||
$query = '
|
||||
$query = 'SELECT * FROM `group` WHERE id IN (SELECT id_group FROM scheduled_group WHERE id_scheduled = :id_scheduled)';
|
||||
$params = ['id_scheduled' => $id_scheduled];
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert a number for a scheduled
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @param string $number : Number
|
||||
* @return mixed (bool|int) : False on error, new row id else
|
||||
*/
|
||||
public function insert_scheduled_number(int $id_scheduled, string $number)
|
||||
{
|
||||
$success = $this->_insert('scheduled_number', ['id_scheduled' => $id_scheduled, 'number' => $number]);
|
||||
return ($success ? $this->_last_id() : false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert a relation between a scheduled and a contact
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @param int $id_contact : Group id
|
||||
* @return mixed (bool|int) : False on error, new row id else
|
||||
*/
|
||||
public function insert_scheduled_contact_relation(int $id_scheduled, int $id_contact)
|
||||
{
|
||||
$success = $this->_insert('scheduled_contact', ['id_scheduled' => $id_scheduled, 'id_contact' => $id_contact]);
|
||||
return ($success ? $this->_last_id() : false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert a relation between a scheduled and a group
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @param int $id_group : Group id
|
||||
* @return mixed (bool|int) : False on error, new row id else
|
||||
*/
|
||||
public function insert_scheduled_group_relation(int $id_scheduled, int $id_group)
|
||||
{
|
||||
$success = $this->_insert('scheduled_group', ['id_scheduled' => $id_scheduled, 'id_group' => $id_group]);
|
||||
return ($success ? $this->_last_id() : false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete numbers for a scheduled
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @return mixed int : Number of deleted rows
|
||||
*/
|
||||
public function delete_scheduled_numbers(int $id_scheduled)
|
||||
{
|
||||
return $this->_delete('scheduled_number', ['id_scheduled' => $id_scheduled]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete contact scheduled relations for a scheduled
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @return mixed int : Number of deleted rows
|
||||
*/
|
||||
public function delete_scheduled_contact_relations(int $id_scheduled)
|
||||
{
|
||||
return $this->_delete('scheduled_contact', ['id_scheduled' => $id_scheduled]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete group scheduled relations for a scheduled
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @return mixed int : Number of deleted rows
|
||||
*/
|
||||
public function delete_scheduled_group_relations(int $id_scheduled)
|
||||
{
|
||||
return $this->_delete('scheduled_group', ['id_scheduled' => $id_scheduled]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get messages scheduled before a date for a number and a user
|
||||
* @param int $id_user : User id
|
||||
* @param $date : Date before which we want messages
|
||||
* @param string $number : Number for which we want messages
|
||||
* @return array
|
||||
*/
|
||||
public function get_before_date_for_number_and_user (int $id_user, $date, string $number)
|
||||
{
|
||||
$query = '
|
||||
SELECT *
|
||||
FROM scheduled
|
||||
WHERE at <= :date
|
||||
AND id_user = :id_user
|
||||
AND (
|
||||
id IN (
|
||||
SELECT id_scheduled
|
||||
|
@ -120,6 +175,7 @@ namespace models;
|
|||
';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
'date' => $date,
|
||||
'number' => $number,
|
||||
];
|
||||
|
@ -127,205 +183,4 @@ namespace models;
|
|||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de scheduledes sous forme d'un tableau.
|
||||
*
|
||||
* @param array $ids : un ou plusieurs id d'entrées à supprimer
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return int : Le nombre de lignes supprimées
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM scheduled
|
||||
WHERE id = :id';
|
||||
|
||||
//On génère la clause IN et les paramètres adaptés depuis le tableau des id
|
||||
$params = ['id' => $id];
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert une schedulede.
|
||||
*
|
||||
* @param array $scheduled : La schedulede à insérer avec les champs name, script, admin & admin
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
||||
*/
|
||||
public function insert($scheduled)
|
||||
{
|
||||
$result = $this->_insert('scheduled', $scheduled);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour une schedulede par son id.
|
||||
*
|
||||
* @param int $id : L'id de la scheduled à modifier
|
||||
* @param array $scheduled : Les données à mettre à jour pour la schedulede
|
||||
*
|
||||
* @return int : le nombre de ligne modifiées
|
||||
*/
|
||||
public function update($id, $scheduled)
|
||||
{
|
||||
return $this->_update('scheduled', $scheduled, ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compte le nombre d'entrées dans la table.
|
||||
*
|
||||
* @return int : Le nombre d'entrées
|
||||
*/
|
||||
public function count($id_user)
|
||||
{
|
||||
return $this->_count('scheduled', ['id_user' => $id_user]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste de numéro pour un scheduled.
|
||||
*
|
||||
* @param int $id_scheduled : L'id du scheduled pour lequel on veux le numéro
|
||||
*
|
||||
* @return array : Les numéros des scheduled
|
||||
*/
|
||||
public function get_numbers($id_scheduled)
|
||||
{
|
||||
return $this->_select('scheduled_number', ['id_scheduled' => $id_scheduled]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste de contact pour un scheduled.
|
||||
*
|
||||
* @param int $id_scheduled : L'id du scheduled pour lequel on veux le numéro
|
||||
*
|
||||
* @return array : Les contact du 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)';
|
||||
|
||||
$params = ['id_scheduled' => $id_scheduled];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste de groups pour un scheduled.
|
||||
*
|
||||
* @param int $id_scheduled : L'id du scheduled pour lequel on veux le numéro
|
||||
*
|
||||
* @return array : Les groups du 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)';
|
||||
|
||||
$params = ['id_scheduled' => $id_scheduled];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert un liens scheduled/number.
|
||||
*
|
||||
* @param int $id_scheduled : L'id du scheduled
|
||||
* @param string $number : Le numéro à lier
|
||||
*
|
||||
* @return int : le nombre d'entrées
|
||||
*/
|
||||
public function insert_scheduled_number($id_scheduled, $number)
|
||||
{
|
||||
$result = $this->_insert('scheduled_number', ['id_scheduled' => $id_scheduled, 'number' => $number]);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert un liens scheduled/contact.
|
||||
*
|
||||
* @param int $id_scheduled : L'id du scheduled
|
||||
* @param int $id_contact : L'id du contact
|
||||
*
|
||||
* @return int : le nombre d'entrées
|
||||
*/
|
||||
public function insert_scheduled_contact($id_scheduled, $id_contact)
|
||||
{
|
||||
$result = $this->_insert('scheduled_contact', ['id_scheduled' => $id_scheduled, 'id_contact' => $id_contact]);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert un liens scheduled/group.
|
||||
*
|
||||
* @param int $id_scheduled : L'id du scheduled
|
||||
* @param int $id_group : L'id du group
|
||||
*
|
||||
* @return int : le nombre d'entrées
|
||||
*/
|
||||
public function insert_scheduled_group($id_scheduled, $id_group)
|
||||
{
|
||||
$result = $this->_insert('scheduled_group', ['id_scheduled' => $id_scheduled, 'id_group' => $id_group]);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime les liens scheduled/number pour un scheduled précis.
|
||||
*
|
||||
* @param int $id_scheduled : L'id du scheduled pour lequel supprimer
|
||||
*
|
||||
* @return int : Le nmbre d'entrées modifiées
|
||||
*/
|
||||
public function delete_scheduled_numbers($id_scheduled)
|
||||
{
|
||||
return $this->_delete('scheduled_number', ['id_scheduled' => $id_scheduled]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime les liens scheduled/contact pour un scheduled précis.
|
||||
*
|
||||
* @param int $id_scheduled : L'id du scheduled pour lequel supprimer
|
||||
*
|
||||
* @return int : Le nmbre d'entrées modifiées
|
||||
*/
|
||||
public function delete_scheduled_contacts($id_scheduled)
|
||||
{
|
||||
return $this->_delete('scheduled_contact', ['id_scheduled' => $id_scheduled]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime les liens scheduled/group pour un scheduled précis.
|
||||
*
|
||||
* @param int $id_scheduled : L'id du scheduled pour lequel supprimer
|
||||
*
|
||||
* @return int : Le nmbre d'entrées modifiées
|
||||
*/
|
||||
public function delete_scheduled_groups($id_scheduled)
|
||||
{
|
||||
return $this->_delete('scheduled_group', ['id_scheduled' => $id_scheduled]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,24 +14,17 @@ namespace models;
|
|||
/**
|
||||
* Cette classe gère les accès bdd pour les sendedes.
|
||||
*/
|
||||
class Sended extends \descartes\Model
|
||||
class Sended extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Retourne une entrée par son id.
|
||||
*
|
||||
* @param int $id : L'id de l'entrée
|
||||
*
|
||||
* @return array : L'entrée
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$sendeds = $this->_select('sended', ['id' => $id]);
|
||||
|
||||
return isset($sendeds[0]) ? $sendeds[0] : false;
|
||||
}
|
||||
|
||||
protected function get_table_name() : string { return 'sended'; }
|
||||
|
||||
|
||||
/**
|
||||
* Return a list of sms where destination in array allowed_destinations
|
||||
* Return a list of sended for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $limit : Max results to return
|
||||
* @param int $offset : Number of results to ignore
|
||||
|
@ -53,149 +46,256 @@ namespace models;
|
|||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne une liste de sendedes 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
|
||||
* Return a list of sendeds in a group of ids and for a user
|
||||
* @param int $id_user : user id
|
||||
* @param array $ids : ids of sendeds to find
|
||||
* @return array
|
||||
*/
|
||||
public function gets($ids)
|
||||
public function gets_in_for_user(int $id_user, $ids)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM sended
|
||||
WHERE id ';
|
||||
WHERE origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
AND 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'];
|
||||
$params['id_user'] = $id_user;
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a entry by his id for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id : Entry id
|
||||
* @return int : Number of removed rows
|
||||
*/
|
||||
public function delete_for_user(int $id_user, int $id)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM sended
|
||||
WHERE id = :id
|
||||
AND origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params = ['id_user' => $id_user, 'id' => $id];
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a sended sms for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id : Entry id
|
||||
* @param array $datas : datas to update
|
||||
*
|
||||
* @return int : number of modified rows
|
||||
*/
|
||||
public function update_for_user (int $id_user, int $id, array $datas)
|
||||
{
|
||||
$params = [];
|
||||
$sets = [];
|
||||
|
||||
foreach ($datas as $label => $value)
|
||||
{
|
||||
$label = preg_replace('#[^a-zA-Z0-9_]#', '', $label);
|
||||
$params['set_' . $label] = $value;
|
||||
$sets[] = '`' . $label . '` = :set_' . $label . ' ';
|
||||
}
|
||||
|
||||
$query = '
|
||||
UPDATE `sended`
|
||||
SET ' . implode(', ', $sets) . '
|
||||
WHERE id = :id
|
||||
AND origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
//If try to update origin, also check it does belong to user
|
||||
if ($sets['set_origin'] ?? false)
|
||||
{
|
||||
$query .= ' AND :set_origin IN (SELECT number FROM phone WHERE id_user = :id_user)'
|
||||
}
|
||||
|
||||
$params['id'] = $id;
|
||||
$params['id_user'] = $id_user;
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Count number of sended sms for user
|
||||
* @param int $id_user : user id
|
||||
* @return int : Number of sended SMS for user
|
||||
*/
|
||||
public function count_for_user($id_user)
|
||||
{
|
||||
$query = '
|
||||
SELECT COUNT(id) as nb
|
||||
FROM sended
|
||||
WHERE origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params)[0]['nb'] ?? 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return x last sendeds message for a user, order by date
|
||||
* @param int $id_user : User id
|
||||
* @param int $nb_entry : Number of sendeds messages to return
|
||||
* @return array
|
||||
*/
|
||||
public function get_lasts_by_date_for_user($id_user, $nb_entry)
|
||||
{
|
||||
$nb_entry = (int) $nb_entry;
|
||||
|
||||
$query = '
|
||||
SELECT *
|
||||
FROM sended
|
||||
WHERE origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
ORDER BY at ASC
|
||||
LIMIT ' . $nb_entry;
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction retourne les X dernières entrées triées par date.
|
||||
*
|
||||
* @param int $nb_entry : Nombre d'entrée à retourner
|
||||
*
|
||||
* @return array : Les dernières entrées
|
||||
* Return sendeds for an destination and a user
|
||||
* @param int $id_user : User id
|
||||
* @param string $destination : Number who sent the message
|
||||
* @return array
|
||||
*/
|
||||
public function get_lasts_by_date($nb_entry)
|
||||
public function gets_by_destination_for_user(int $id_user, string $destination)
|
||||
{
|
||||
return $this->_select('sended', [], 'at', true, $nb_entry);
|
||||
$nb_entry = (int) $nb_entry;
|
||||
|
||||
$query = '
|
||||
SELECT *
|
||||
FROM sended
|
||||
WHERE origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
AND destination = :destination
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
'destination' => $destination,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des sended sous forme d'un tableau.
|
||||
*
|
||||
* @param string $destination : Le numéro auquel est envoyé le message
|
||||
*
|
||||
* @return array : La liste des sended
|
||||
*/
|
||||
public function get_by_destination($destination)
|
||||
{
|
||||
return $this->_select('sended', ['destination' => $destination]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de sendedes sous forme d'un tableau.
|
||||
*
|
||||
* @param array $ids : un ou plusieurs id d'entrées à supprimer
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return int : Le nombre de lignes supprimées
|
||||
* Get number of sended SMS for every date since a date for a specific user
|
||||
* @param int $id_user : user id
|
||||
* @param \DateTime $date : Date since which we want the messages
|
||||
* @return array
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM sended
|
||||
WHERE id = :id';
|
||||
|
||||
$params = ['id' => $id];
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert une sendede.
|
||||
*
|
||||
* @param array $sended : La sendede à insérer avec les champs name, script, admin & admin
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
||||
*/
|
||||
public function insert($sended)
|
||||
{
|
||||
$result = $this->_insert('sended', $sended);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour une sendede par son id.
|
||||
*
|
||||
* @param int $id : L'id de la sended à modifier
|
||||
* @param array $sended : Les données à mettre à jour pour la sendede
|
||||
*
|
||||
* @return int : le nombre de ligne modifiées
|
||||
*/
|
||||
public function update($id, $sended)
|
||||
{
|
||||
return $this->_update('sended', $sended, ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compte le nombre d'entrées dans la table.
|
||||
*
|
||||
* @return int : Le nombre d'entrées
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->_count('sended');
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le nombre de SMS envoyés pour chaque jour depuis une date.
|
||||
*
|
||||
* @param \DateTime $date : La date depuis laquelle on veux les SMS
|
||||
*
|
||||
* @return array : Tableau avec le nombre de SMS depuis la date
|
||||
*/
|
||||
public function count_by_day_since($date)
|
||||
public function count_by_day_since_for_user($id_user, $date)
|
||||
{
|
||||
$query = "
|
||||
SELECT COUNT(id) as nb, DATE_FORMAT(at, '%Y-%m-%d') as at_ymd
|
||||
FROM sended
|
||||
WHERE at > :date
|
||||
AND origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
GROUP BY at_ymd
|
||||
";
|
||||
|
||||
$params = [
|
||||
'date' => $date,
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement before_delivered field.
|
||||
*
|
||||
* @param int $id_sended : id of the sended sms to decrement
|
||||
* Return all discussions (ie : numbers we have a message sended from or sended to) for a user
|
||||
* @param int $id_user : User id
|
||||
* @return array
|
||||
*/
|
||||
public function decrement_before_delivered($id_sended)
|
||||
public function get_discussions_for_user(int $id_user)
|
||||
{
|
||||
$query = '
|
||||
UPDATE sended
|
||||
SET before_delivered = before_delivered - 1
|
||||
WHERE id = :id_sended
|
||||
';
|
||||
SELECT at, number
|
||||
FROM (
|
||||
SELECT at, origin as number FROM sended
|
||||
WHERE destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
UNION (
|
||||
SELECT at, destination as number FROM sended
|
||||
WHERE origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
)
|
||||
) as discussions
|
||||
GROUP BY number
|
||||
ORDER BY at DESC
|
||||
';
|
||||
|
||||
$params = ['id_sended' => $id_sended];
|
||||
$params = ['id_user' => $id_user];
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SMS sended since a date for a user
|
||||
* @param $date : La date depuis laquelle on veux les SMS (au format 2014-10-25 20:10:05)
|
||||
* @param int $id_user : User id
|
||||
* @return array : Tableau avec tous les SMS depuis la date
|
||||
*/
|
||||
public function get_since_by_date_for_user($date, $id_user)
|
||||
{
|
||||
$query = "
|
||||
SELECT *
|
||||
FROM sended
|
||||
WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s')
|
||||
AND origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
ORDER BY at ASC";
|
||||
|
||||
$params = [
|
||||
'date' => $date,
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find messages sended since a date for a certain destination and user
|
||||
* @param int $id_user : User id
|
||||
* @param $date : Date we want messages sinces
|
||||
* @param string $destination : Origin number
|
||||
* @return array
|
||||
*/
|
||||
public function get_since_by_date_for_destination_and_user(int $id_user, $date, string $destination)
|
||||
{
|
||||
$query = "
|
||||
SELECT *
|
||||
FROM sended
|
||||
WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s')
|
||||
AND destination = :destination
|
||||
AND origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
ORDER BY at ASC
|
||||
";
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user
|
||||
'date' => $date,
|
||||
'destination' => $destination,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
|
|
@ -11,42 +11,11 @@
|
|||
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Cette classe gère les accès bdd pour les settinges.
|
||||
*/
|
||||
class Setting extends \descartes\Model
|
||||
class Setting extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Return array of all settings.
|
||||
* @param int $id_user : user id
|
||||
* @return array
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
public function gets_for_user (int $id_user): array
|
||||
{
|
||||
return $this->_select('setting', ['id_user' => $id_user]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new setting
|
||||
* @param array $setting
|
||||
* @return bool
|
||||
*/
|
||||
public function insert (array $setting) : bool
|
||||
{
|
||||
return (bool) $this->_insert('setting', $setting);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a setting by his name.
|
||||
* @param int $id_user : user id
|
||||
* @param string $name : setting name
|
||||
* @param mixed $value
|
||||
* @return int : number of modified lines
|
||||
*/
|
||||
public function update (int $id_user, string $name, $value): int
|
||||
{
|
||||
return $this->_update('setting', ['value' => $value], ['id_user' => $id_user, 'name' => $name]);
|
||||
}
|
||||
protected function get_table_name() : string { return 'setting'; }
|
||||
}
|
||||
|
|
|
@ -11,139 +11,23 @@
|
|||
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Cette classe gère les accès bdd pour les smsstopes.
|
||||
*/
|
||||
class SmsStop extends \descartes\Model
|
||||
class SmsStop extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Get all smsstops.
|
||||
*
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
protected function get_table_name() : string { return 'smsstop'; }
|
||||
|
||||
|
||||
/**
|
||||
* Return a smsstop by his number and user
|
||||
* @param int $id_user : user id
|
||||
* @param string $number : phone number
|
||||
* @return array
|
||||
*/
|
||||
public function get_all()
|
||||
public function get_by_number_for_user (int $id_user, string $number)
|
||||
{
|
||||
return $this->_select('smsstop');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$smsstops = $this->_select('smsstop', ['id' => $id]);
|
||||
|
||||
return isset($smsstops[0]) ? $smsstops[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une entrée par son numéro de tel.
|
||||
*
|
||||
* @param string $number : Le numéro de tél
|
||||
*
|
||||
* @return array : L'entrée
|
||||
*/
|
||||
public function get_by_number($number)
|
||||
{
|
||||
$smsstops = $this->_select('smsstop', ['number' => $number]);
|
||||
|
||||
return isset($smsstops[0]) ? $smsstops[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de smsstopes 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('smsstop', [], null, false, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de smsstopes 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 smsstop
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de smsstopes sous forme d'un tableau.
|
||||
*
|
||||
* @param array $ids : un ou plusieurs id d'entrées à supprimer
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return int : Le nombre de lignes supprimées
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM smsstop
|
||||
WHERE id = :id';
|
||||
|
||||
$params = ['id' => $id];
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert une smsstope.
|
||||
*
|
||||
* @param array $smsstop : La smsstope à insérer avec les champs name, script, admin & admin
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
||||
*/
|
||||
public function insert($smsstop)
|
||||
{
|
||||
$result = $this->_insert('smsstop', $smsstop);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour une smsstope par son id.
|
||||
*
|
||||
* @param int $id : L'id de la smsstop à modifier
|
||||
* @param array $smsstop : Les données à mettre à jour pour la smsstope
|
||||
*
|
||||
* @return int : le nombre de ligne modifiées
|
||||
*/
|
||||
public function update($id, $smsstop)
|
||||
{
|
||||
return $this->_update('smsstop', $smsstop, ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compte le nombre d'entrées dans la table smsstop.
|
||||
*
|
||||
* @return int : Le nombre de smsstop
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->_count('smsstop');
|
||||
return $this->_select_one($this->get_table_name(), ['number' => $number, 'id_user' => $id_user]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace models;
|
|||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
protected function get_table_name() : string;
|
||||
abstract protected function get_table_name() : string;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -108,6 +108,7 @@ namespace models;
|
|||
return $this->_update($this->get_table_name(), $entry, ['id_user' => $id_user, 'id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Count number of entry for a user
|
||||
* @param int $id_user : User id
|
||||
|
|
|
@ -1,144 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of RaspiSMS.
|
||||
*
|
||||
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
|
||||
*
|
||||
* This source file is subject to the GPL-3.0 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', [], null, 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');
|
||||
}
|
||||
}
|
|
@ -11,30 +11,33 @@
|
|||
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Class for user table administration. Not a standard model because has absolutly no user based restrictions
|
||||
*/
|
||||
class User extends \descartes\Model
|
||||
{
|
||||
/**
|
||||
* Retourne un user par son email.
|
||||
*
|
||||
* @param string $email : L'email du user
|
||||
*
|
||||
* @return mixed array | false : false si pas de user pour ce mail, sinon le user associé sous forme de tableau
|
||||
* Find a user using his email
|
||||
* @param string $email : User email
|
||||
* @return mixed array
|
||||
*/
|
||||
public function get_by_email($email)
|
||||
{
|
||||
return $this->_select_one('user', ['email' => $email]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return users by transfer status.
|
||||
*
|
||||
* Return users by their transfer status.
|
||||
* @param bool $transfer : transfer status
|
||||
* @return array
|
||||
*/
|
||||
public function gets_by_transfer($transfer)
|
||||
{
|
||||
return $this->_select('transfer', ['transfer' => $transfer]);
|
||||
return $this->_select('user', ['transfer' => $transfer]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return list of user.
|
||||
*
|
||||
|
@ -46,6 +49,7 @@ namespace models;
|
|||
return $this->_select('user', [], null, false, $limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne une liste de useres sous forme d'un tableau.
|
||||
*
|
||||
|
@ -59,44 +63,35 @@ namespace models;
|
|||
return $this->_delete('user', ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert un user.
|
||||
*
|
||||
* @param array $user : La user à insérer avec les champs name, script, admin & admin
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
||||
* Insert a new user
|
||||
* @param array $user : User to insert
|
||||
* @return mixed bool|int : false if fail, new user id else
|
||||
*/
|
||||
public function insert($user)
|
||||
{
|
||||
$result = $this->_insert('user', $user);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_last_id();
|
||||
$success = $this->_insert('user', $user);
|
||||
return ($success ? $this->_last_id() : false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Met à jour un user par son id.
|
||||
*
|
||||
* @param int $id : L'id de la user à modifier
|
||||
* @param array $user : Les données à mettre à jour pour la user
|
||||
*
|
||||
* @return int : le nombre de ligne modifiées
|
||||
* Update a user using his is
|
||||
* @param int $id : User id
|
||||
* @param array $datas : Datas to update
|
||||
* @return int : number of modified rows
|
||||
*/
|
||||
public function update($id, $user)
|
||||
public function update($id, $datas)
|
||||
{
|
||||
return $this->_update('user', $user, ['id' => $id]);
|
||||
return $this->_update('user', $datas, ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a user password by his id.
|
||||
*
|
||||
* @param int $id : User id
|
||||
* @param array $password : The new password of the user
|
||||
*
|
||||
* @return int : Number of modified lines
|
||||
*/
|
||||
public function update_password($id, $password)
|
||||
|
@ -104,12 +99,11 @@ namespace models;
|
|||
return $this->_update('user', ['password' => $password], ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a user transfer property value by his id.
|
||||
*
|
||||
* @param int $id : User id
|
||||
* @param array $transfer : The new transfer property value
|
||||
*
|
||||
* @return int : Number of modified lines
|
||||
*/
|
||||
public function update_transfer($id, $transfer)
|
||||
|
@ -117,12 +111,11 @@ namespace models;
|
|||
return $this->_update('user', ['transfer' => $transfer], ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a user email by his id.
|
||||
*
|
||||
* @param int $id : User id
|
||||
* @param array $email : The new email
|
||||
*
|
||||
* @return int : Number of modified lines
|
||||
*/
|
||||
public function update_email($id, $email)
|
||||
|
|
Loading…
Reference in New Issue