Update internal controllers to use standard one
This commit is contained in:
parent
25b461d611
commit
bc622285a4
|
@ -43,13 +43,14 @@ namespace controllers\internals;
|
|||
'admin' => $admin,
|
||||
];
|
||||
|
||||
$result = $this->model_command->insert($command);
|
||||
$result = $this->get_model()->insert($command);
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->internal_event->create($id_user, 'COMMAND_ADD', 'Ajout commande : ' . $name . ' => ' . $script);
|
||||
$internal_event = new Event($this->bdd);
|
||||
$internal_event->create($id_user, 'COMMAND_ADD', 'Ajout commande : ' . $name . ' => ' . $script);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -72,6 +73,6 @@ namespace controllers\internals;
|
|||
'admin' => $admin,
|
||||
];
|
||||
|
||||
return $this->model_command->update_for_user($id_user, $id, $datas);
|
||||
return $this->get_model()->update_for_user($id_user, $id, $datas);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace controllers\internals;
|
|||
*/
|
||||
public function get_by_number_and_user(int $id_user, string $number,)
|
||||
{
|
||||
return $this->model_contact->get_by_number_and_user($id_user, $number);
|
||||
return $this->get_model()->get_by_number_and_user($id_user, $number);
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,12 +45,12 @@ namespace controllers\internals;
|
|||
*/
|
||||
public function get_by_name_and_user(int $id_user, string $name)
|
||||
{
|
||||
return $this->model_contact->get_by_name_and_user($id_user, $name);
|
||||
return $this->get_model()->get_by_name_and_user($id_user, $name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new command
|
||||
* Create a new contact
|
||||
* @param int $id_user : User id
|
||||
* @param string $number : Contact number
|
||||
* @param string $name : Contact name
|
||||
|
@ -64,7 +64,7 @@ namespace controllers\internals;
|
|||
'name' => $name,
|
||||
];
|
||||
|
||||
$result = $this->model_contact->insert($contact);
|
||||
$result = $this->get_model()->insert($contact);
|
||||
if (!$result)
|
||||
{
|
||||
return $result;
|
||||
|
@ -79,7 +79,7 @@ namespace controllers\internals;
|
|||
/**
|
||||
* Update a contact
|
||||
* @param int $id_user : User id
|
||||
* @param int $id : Command id
|
||||
* @param int $id : Contact id
|
||||
* @param string $number : Contact number
|
||||
* @param string $name : Contact name
|
||||
* @return int : number of modified rows
|
||||
|
@ -91,6 +91,6 @@ namespace controllers\internals;
|
|||
'name' => $name,
|
||||
];
|
||||
|
||||
return $this->model_contact->update_for_user($id_user, $id, $datas);
|
||||
return $this->get_model()->update_for_user($id_user, $id, $datas);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,65 +11,45 @@
|
|||
|
||||
namespace controllers\internals;
|
||||
|
||||
/**
|
||||
* Classe des Event.
|
||||
*/
|
||||
class Event extends \descartes\InternalController
|
||||
class Event extends StandardController
|
||||
{
|
||||
private $model_event;
|
||||
|
||||
public function __construct(\PDO $bdd)
|
||||
{
|
||||
$this->model_event = new \models\Event($bdd);
|
||||
}
|
||||
protected $model = false;
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des events sous forme d'un tableau.
|
||||
*
|
||||
* @param PDO $bdd : instance PDO de la base de donnée
|
||||
* @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 events
|
||||
* Get the model for the Controller
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
public function list($nb_entry = null, $page = null)
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
//Recupération des events
|
||||
return $this->model_event->list($nb_entry, $nb_entry * $page);
|
||||
}
|
||||
$this->model = $this->model ?? new \models\Event($this->$bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction retourne les X dernières entrées triées par date.
|
||||
*
|
||||
* @param mixed false|int $nb_entry : Nombre d'entrée à retourner ou faux pour tout
|
||||
*
|
||||
* @return array : Les dernières entrées
|
||||
* Disabled methods
|
||||
*/
|
||||
public function get_lasts_by_date($nb_entry = false)
|
||||
{
|
||||
return $this->model_event->get_lasts_by_date($nb_entry);
|
||||
}
|
||||
public function update_for_user() { return false; }
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction va supprimer une liste de contacts.
|
||||
*
|
||||
* @param array $ids : Les id des contactes à supprimer
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return int : Le nombre de contactes supprimées;
|
||||
* 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 delete($id)
|
||||
public function get_lasts_by_date_for_user (int $id_user, int $nb_entry)
|
||||
{
|
||||
return $this->model_event->delete($id);
|
||||
return $this->get_lasts_by_date_for_user($id_user, $nb_entry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction insert un nouvel event.
|
||||
* Create a new event
|
||||
* @param int $id_user : user id
|
||||
* @param mixed $type
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id du nouvel event inséré
|
||||
* @return mixed bool : false on fail, new event id else
|
||||
*/
|
||||
public function create($id_user, $type, $text)
|
||||
{
|
||||
|
|
|
@ -14,94 +14,45 @@ namespace controllers\internals;
|
|||
/**
|
||||
* Classe des groups.
|
||||
*/
|
||||
class Group extends \descartes\InternalController
|
||||
class Group extends StandardController
|
||||
{
|
||||
private $model_group;
|
||||
private $internal_event;
|
||||
|
||||
public function __construct(\PDO $bdd)
|
||||
{
|
||||
$this->model_group = new \models\Group($bdd);
|
||||
$this->internal_event = new \controllers\internals\Event($bdd);
|
||||
}
|
||||
protected $model = false;
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des groups sous forme d'un tableau.
|
||||
*
|
||||
* @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 groups
|
||||
* Get the model for the Controller
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
public function list($nb_entry = null, $page = null)
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
//Recupération des groups
|
||||
return $this->model_group->list($nb_entry, $nb_entry * $page);
|
||||
}
|
||||
$this->model = $this->model ?? new \models\Event($this->$bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des groups sous forme d'un tableau.
|
||||
*
|
||||
* @param array int $ids : Les ids des entrées à retourner
|
||||
*
|
||||
* @return array : La liste des groups
|
||||
* Create a new group for a user
|
||||
* @param int $id_user : user id
|
||||
* @param stirng $name : Group name
|
||||
* @param array $contacts_ids : Ids of the contacts of the group
|
||||
* @return mixed bool|int : false on error, new group id
|
||||
*/
|
||||
public function gets($ids)
|
||||
{
|
||||
//Recupération des groups
|
||||
return $this->model_group->gets($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne un group par son name.
|
||||
*
|
||||
* @param string $name : Le name du group
|
||||
*
|
||||
* @return array : Le group
|
||||
*/
|
||||
public function get_by_name($name)
|
||||
{
|
||||
//Recupération des groups
|
||||
return $this->model_group->get_by_name($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction permet de compter le nombre de group.
|
||||
*
|
||||
* @return int : Le nombre d'entrées dans la table
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->model_group->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction va supprimer une liste de group.
|
||||
*
|
||||
* @param array $ids : Les id des groups à supprimer
|
||||
*
|
||||
* @return int : Le nombre de groups supprimées;
|
||||
*/
|
||||
public function delete($ids)
|
||||
{
|
||||
return $this->model_group->deletes($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction insert une nouvelle group.
|
||||
*
|
||||
* @param array $name : le nom du group
|
||||
* @param array $contacts_ids : Un tableau des ids des contact du group
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle group insérée
|
||||
*/
|
||||
public function create($name, $contacts_ids)
|
||||
public function create (int $id_user, string $name, array $contacts_ids)
|
||||
{
|
||||
$group = [
|
||||
'id_user' => $id_user,
|
||||
'name' => $name,
|
||||
];
|
||||
|
||||
$id_group = $this->model_group->insert($group);
|
||||
foreach ($contacts_ids as $key => $contact_id)
|
||||
{
|
||||
$contact = $this->get_model()->get_for_user($id_user, $contact_id);
|
||||
if (!$contact)
|
||||
{
|
||||
unset($contacts_ids[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$id_group = $this->get_model()->insert($group);
|
||||
if (!$id_group)
|
||||
{
|
||||
return false;
|
||||
|
@ -109,39 +60,46 @@ namespace controllers\internals;
|
|||
|
||||
foreach ($contacts_ids as $contact_id)
|
||||
{
|
||||
$this->model_group->insert_group_contact($id_group, $contact_id);
|
||||
$this->get_model()->insert_group_contact_relation($id_group, $contact_id);
|
||||
}
|
||||
|
||||
$this->internal_event->create($_SESSION['user']['id'], 'GROUP_ADD', 'Ajout group : '.$name);
|
||||
$internal_event = new Event($this->bdd);
|
||||
$internal_event->create($id_user, 'GROUP_ADD', 'Ajout group : ' . $name);
|
||||
|
||||
return $id_group;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction met à jour un group.
|
||||
*
|
||||
* @param int $id : L'id du group à update
|
||||
* @param string $name : Le nom du group à update
|
||||
* @param string $contacts_ids : Les ids des contact du group
|
||||
*
|
||||
* @return bool : True if all update ok, false else
|
||||
* Update a group for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id_group : Group id
|
||||
* @param stirng $name : Group name
|
||||
* @param array $contacts_ids : Ids of the contacts of the group
|
||||
* @return bool : False on error, true on success
|
||||
*/
|
||||
public function update($id, $name, $contacts_ids)
|
||||
public function update_for_user(int $id_user, int $id_group, string $name, array $contacts_ids)
|
||||
{
|
||||
$group = [
|
||||
'name' => $name,
|
||||
];
|
||||
|
||||
$result = $this->model_group->update($id, $group);
|
||||
$result = $this->get_model()->update_for_user($id_user, $id_group, $group);
|
||||
|
||||
$this->model_group->delete_group_contacts($id);
|
||||
$this->get_model()->delete_group_contact_relations($id_group);
|
||||
|
||||
$nb_contact_insert = 0;
|
||||
foreach ($contacts_ids as $contact_id)
|
||||
{
|
||||
if ($this->model_group->insert_group_contact($id, $contact_id))
|
||||
$contact = $this->get_model()->get_for_user($id_user, $contact_id);
|
||||
if (!$contact)
|
||||
{
|
||||
++$nb_contact_insert;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->get_model()->insert_group_contact_relation($id_group, $contact_id))
|
||||
{
|
||||
$nb_contact_insert++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,16 +111,26 @@ namespace controllers\internals;
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction retourne les contact pour un group.
|
||||
*
|
||||
* @param string $id : L'id du group
|
||||
*
|
||||
* @return array : Un tableau avec les contact
|
||||
* 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_contacts($id)
|
||||
public function get_by_name_for_user (int $id_user, string $name)
|
||||
{
|
||||
//Recupération des groups
|
||||
return $this->model_group->get_contacts($id);
|
||||
return $this->get_model()->get_by_name_for_user($id_user, $name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get groups contacts
|
||||
* @param int $id_group : Group id
|
||||
* @return array : Contacts of the group
|
||||
*/
|
||||
public function get_contacts($id_group)
|
||||
{
|
||||
return $this->get_model()->get_contacts($id_group);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,75 +11,32 @@
|
|||
|
||||
namespace controllers\internals;
|
||||
|
||||
class Phone extends \descartes\InternalController
|
||||
class Phone extends StandardController
|
||||
{
|
||||
private $model_phone;
|
||||
private $internal_event;
|
||||
|
||||
public function __construct(\PDO $bdd)
|
||||
{
|
||||
$this->model_phone = new \models\Phone($bdd);
|
||||
$this->internal_event = new \controllers\internals\Event($bdd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of phones
|
||||
* @param int $id_user : User id
|
||||
* @param mixed(int|bool) $nb_entry : Number of entry to return
|
||||
* @param mixed(int|bool) $page : Numero of page
|
||||
*
|
||||
* @return array|bool : List of user or false
|
||||
*/
|
||||
public function list_for_user(int $id_user, ?int $nb_entry = null, ?int $page = null)
|
||||
{
|
||||
return $this->model_phone->list_for_user($id_user, $nb_entry, $page * $nb_entry);
|
||||
}
|
||||
protected $model = false;
|
||||
|
||||
/**
|
||||
* Return a phone
|
||||
* @param int $id : id of the phone
|
||||
* @return array
|
||||
* Get the model for the Controller
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
public function get (int $id)
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
return $this->model_phone->get($id);
|
||||
}
|
||||
|
||||
|
||||
$this->model = $this->model ?? new \models\Phone($this->$bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a phone by his number and user
|
||||
* Return a phone for a user by a number
|
||||
* @param int $id_user : user id
|
||||
* @param string $number : phone number
|
||||
* @param string $number : Phone number
|
||||
* @return array
|
||||
*/
|
||||
public function get_by_number_for_user (int $id_user, string $number)
|
||||
public function get_by_number_and_user(int $id_user, string $number,)
|
||||
{
|
||||
return $this->model_phone->get_by_number_for_user($id_user, $number);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return phones of a user
|
||||
* @param int $id_user : id of the user
|
||||
* @return array
|
||||
*/
|
||||
public function gets_for_user (int $id_user)
|
||||
{
|
||||
return $this->model_phone->gets_for_user($id_user);
|
||||
return $this->model_phone->get_by_number_and_user($id_user, $number);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a phone
|
||||
* @param int $id : Phone id
|
||||
* @return bool
|
||||
*/
|
||||
public function delete_for_user (int $id_user, int $id) : bool
|
||||
{
|
||||
return (bool) $this->model_phone->delete_for_user($id_user, $id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a phone
|
||||
* @param int $id_user : User to insert phone for
|
||||
|
@ -90,7 +47,7 @@ namespace controllers\internals;
|
|||
*/
|
||||
public function create (int $id_user, string $number, string $adapter, ?string $adapter_datas) : bool
|
||||
{
|
||||
$phone = [
|
||||
$phone = [
|
||||
'id_user' => $id_user,
|
||||
'number' => $number,
|
||||
'adapter' => $adapter,
|
||||
|
@ -103,14 +60,14 @@ namespace controllers\internals;
|
|||
|
||||
/**
|
||||
* Update a phone
|
||||
* @param int $id : Phone id
|
||||
* @param int $id_user : User to insert phone for
|
||||
* @param int $id : Phone id
|
||||
* @param string $number : The number of the phone
|
||||
* @param string $adapter : The adapter to use the phone
|
||||
* @param array $adapter_datas : An array of the datas of the adapter (for example credentials for an api)
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function update_for_user (int $id, int $id_user, string $number, string $adapter, array $adapter_datas) : bool
|
||||
public function update_for_user (int $id_user, int $id, string $number, string $adapter, array $adapter_datas) : bool
|
||||
{
|
||||
$phone = [
|
||||
'id_user' => $id_user,
|
||||
|
@ -119,7 +76,6 @@ namespace controllers\internals;
|
|||
'adapter_datas' => json_encode($adapter_datas),
|
||||
];
|
||||
|
||||
return (bool) $this->model_phone->update_for_user($id, $phone);
|
||||
return (bool) $this->model_phone->update_for_user($id_user, $id, $phone);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,201 +11,136 @@
|
|||
|
||||
namespace controllers\internals;
|
||||
|
||||
/**
|
||||
* Classe des receivedes.
|
||||
*/
|
||||
class Received extends \descartes\InternalController
|
||||
{
|
||||
private $model_received;
|
||||
private $internal_phone;
|
||||
|
||||
public function __construct(\PDO $bdd)
|
||||
class Received extends StandardController
|
||||
{
|
||||
$this->model_received = new \models\Received($bdd);
|
||||
$this->internal_phone = new \controllers\internals\Phone($bdd);
|
||||
}
|
||||
protected $model = false;
|
||||
|
||||
/**
|
||||
* List sms 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($id_user, $nb_entry = null, $page = null)
|
||||
{
|
||||
return $this->model_received->list_for_user($id_user, $nb_entry, $nb_entry * $page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a received sms
|
||||
* @param $id : received id
|
||||
* @return array
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return $this->model_received->get($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des receivedes sous forme d'un tableau.
|
||||
*
|
||||
* @param array int $ids : Les ids des entrées à retourner
|
||||
*
|
||||
* @return array : La liste des receivedes
|
||||
*/
|
||||
public function gets($ids)
|
||||
{
|
||||
//Recupération des receivedes
|
||||
return $this->model_received->gets($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne les X dernières entrées triées par date for a user.
|
||||
* @param int $id_user
|
||||
* @param int $nb_entry : Nombre d'entrée à retourner ou faux pour tout
|
||||
* @return array : Les dernières entrées
|
||||
*/
|
||||
public function get_lasts_for_user_by_date($id_user, $nb_entry)
|
||||
{
|
||||
return $this->model_received->get_lasts_for_user_by_date($id_user, $nb_entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des receiveds sous forme d'un tableau.
|
||||
*
|
||||
* @param string $origin : Le numéro depuis lequel est envoyé le message
|
||||
*
|
||||
* @return array : La liste des receiveds
|
||||
*/
|
||||
public function get_by_origin($origin)
|
||||
{
|
||||
return $this->model_received->get_by_origin($origin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les Sms reçus depuis une date.
|
||||
* @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)
|
||||
{
|
||||
return $this->model_received->get_since_by_date_for_user($date, $id_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $number : Le numéro
|
||||
*
|
||||
* @return array : Tableau avec tous les Sms depuis la date
|
||||
*/
|
||||
public function get_since_for_number_by_date($date, $number)
|
||||
{
|
||||
return $this->model_received->get_since_for_number_by_date($date, $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction va supprimer une liste de receiveds.
|
||||
*
|
||||
* @param array $ids : Les id des receivedes à supprimer
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return int : Le nombre de receivedes supprimées;
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return $this->model_received->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction insert une nouvelle receivede.
|
||||
*
|
||||
* @param array $received : Un tableau représentant la receivede à insérer
|
||||
* @param mixed $at
|
||||
* @param mixed $origin
|
||||
* @param mixed $content
|
||||
* @param mixed $command
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle receivede insérée
|
||||
*/
|
||||
public function create($at, $origin, $content, $command)
|
||||
{
|
||||
$received = [
|
||||
'at' => $at,
|
||||
'origin' => $origin,
|
||||
'content' => $content,
|
||||
'command' => $command,
|
||||
];
|
||||
|
||||
return $this->model_received->create($received);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction met à jour une série de receivedes.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param mixed $at
|
||||
* @param mixed $origin
|
||||
* @param mixed $content
|
||||
* @param mixed $command
|
||||
*
|
||||
* @return int : le nombre de ligne modifiées
|
||||
*/
|
||||
public function update($id, $at, $origin, $content, $command)
|
||||
{
|
||||
$received = [
|
||||
'at' => $at,
|
||||
'origin' => $origin,
|
||||
'content' => $content,
|
||||
'command' => $command,
|
||||
];
|
||||
|
||||
return $this->model_received->update($id, $received);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
return $this->model_received->count($id_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction compte le nombre de receiveds par jour depuis une date.
|
||||
*
|
||||
* @param int $id_user : user id
|
||||
* @param mixed $date
|
||||
*
|
||||
* @return array : un tableau avec en clef la date et en valeure le nombre de sms envoyés
|
||||
*/
|
||||
public function count_for_user_by_day_since($id_user, $date)
|
||||
{
|
||||
$counts_by_day = $this->model_received->count_for_user_by_day_since($id_user, $date);
|
||||
$return = [];
|
||||
|
||||
foreach ($counts_by_day as $count_by_day)
|
||||
/**
|
||||
* Get the model for the Controller
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
$return[$count_by_day['at_ymd']] = $count_by_day['nb'];
|
||||
$this->model = $this->model ?? new \models\Received($this->$bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a received
|
||||
* @param $at : Reception date
|
||||
* @param $text : Text of the message
|
||||
* @param string $origin : Number of the sender
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param bool $command : Is the sms a command
|
||||
* @return bool : false on error, new received id else
|
||||
*/
|
||||
public function create ($at, string $text, string $origin, string $destination, bool $command = false) : bool
|
||||
{
|
||||
$received = [
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
'destination' => $destination,
|
||||
'command' => $command,
|
||||
];
|
||||
|
||||
return (bool) $this->get_model()->insert($received);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne les discussions avec un numéro.
|
||||
*
|
||||
* @return array : Un tableau avec la date de l'échange et le numéro de la personne
|
||||
*/
|
||||
public function get_discussions()
|
||||
{
|
||||
return $this->model_received->get_discussions();
|
||||
/**
|
||||
* Update a received for a user
|
||||
* @param int $id_user : user id
|
||||
* @param int $id_received : received id
|
||||
* @param $at : Reception date
|
||||
* @param $text : Text of the message
|
||||
* @param string $origin : Number of the sender
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param bool $command : Is the sms a command
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function update_for_user (int $id_user, int $id_received, $at, string $text, string $origin, string $destination, bool $command = false) : bool
|
||||
{
|
||||
$received = [
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
'destination' => $destination,
|
||||
'command' => $command,
|
||||
];
|
||||
|
||||
return (bool) $this->get_model()->update_for_user($id_user, $id_received, $received);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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(int $id_user, int $nb_entry)
|
||||
{
|
||||
return $this->get_model()->get_lasts_by_date_for_user($id_user, $nb_entry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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_by_origin_for_user(int $id_user, string $origin)
|
||||
{
|
||||
return $this->get_model()->gets_by_origin_for_user($id_user, $origin);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 count_by_day_since_for_user(int $id_user, $date)
|
||||
{
|
||||
return $this->get_model()->count_by_day_since_for_user($id_user, $date);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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_for_user(int $id_user)
|
||||
{
|
||||
return $this->get_model()->get_discussions_for_user($id_user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get SMS received 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(int $id_user, $date)
|
||||
{
|
||||
return $this->get_model()->get_since_by_date_for_user($id_user, $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_by_date_for_origin_and_user(int $id_user, $date, string $origin)
|
||||
{
|
||||
return $this->get_model()->get_since_by_date_for_origin_and_user($id_user, $date, $origin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,113 +11,35 @@
|
|||
|
||||
namespace controllers\internals;
|
||||
|
||||
/**
|
||||
* Classe des scheduleds.
|
||||
*/
|
||||
class Scheduled extends \descartes\InternalController
|
||||
class Scheduled extends StandardController
|
||||
{
|
||||
private $model_scheduled;
|
||||
private $internal_event;
|
||||
|
||||
public function __construct(\PDO $bdd)
|
||||
{
|
||||
$this->model_scheduled = new \models\Scheduled($bdd);
|
||||
$this->internal_event = new \controllers\internals\Event($bdd);
|
||||
}
|
||||
protected $model = false;
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des scheduleds sous forme d'un tableau.
|
||||
*
|
||||
* @param int $id_user : User id
|
||||
* @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 scheduleds
|
||||
* Get the model for the Controller
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
public function list($id_user, $nb_entry = null, $page = null)
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
//Recupération des scheduleds
|
||||
return $this->model_scheduled->list($id_user, $nb_entry, $nb_entry * $page);
|
||||
}
|
||||
$this->model = $this->model ?? new \models\Scheduled($this->$bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des scheduleds sous forme d'un tableau.
|
||||
*
|
||||
* @param array int $ids : Les ids des entrées à retourner
|
||||
*
|
||||
* @return array : La liste des scheduleds
|
||||
* Create a scheduled
|
||||
* @param int $id_user : User to insert scheduled for
|
||||
* @param $at : Scheduled date to send
|
||||
* @param string $text : Text of the message
|
||||
* @param ?string $origin : Origin number of the message, null by default
|
||||
* @param bool $flash : Is the sms a flash sms, by default false
|
||||
* @param array $numbers : Numbers to send message to
|
||||
* @param array $contacts_ids : Contact ids to send message to
|
||||
* @param array $groups_ids : Group ids to send message to
|
||||
* @return bool : false on error, new id on success
|
||||
*/
|
||||
public function get ($id)
|
||||
public function create (int $id_user, $at, string $text, ?string $origin = null, bool $flash = false, array $numbers = [], array $contacts_ids = [], array $groups_ids = [])
|
||||
{
|
||||
//Recupération des scheduleds
|
||||
return $this->model_scheduled->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des scheduleds sous forme d'un tableau.
|
||||
*
|
||||
* @param array int $ids : Les ids des entrées à retourner
|
||||
*
|
||||
* @return array : La liste des scheduleds
|
||||
*/
|
||||
public function gets($ids)
|
||||
{
|
||||
//Recupération des scheduleds
|
||||
return $this->model_scheduled->gets($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function get_before_date_for_number($date, $number)
|
||||
{
|
||||
return $this->model_scheduled->get_before_date_for_number($date, $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction permet de compter le nombre de scheduled.
|
||||
* @param int $id_user : User id
|
||||
* @return int : Le nombre d'entrées dans la table
|
||||
*/
|
||||
public function count($id_user)
|
||||
{
|
||||
return $this->model_scheduled->count($id_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction va supprimer un scheduled.
|
||||
*
|
||||
* @param int $id : L'id du scheduled à supprimer
|
||||
*
|
||||
* @return int : Le nombre de scheduleds supprimées;
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return $this->model_scheduled->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction insert un nouveau scheduled.
|
||||
* @param int $id_user
|
||||
* @param mixed $at
|
||||
* @param mixed $text
|
||||
* @param mixed $origin
|
||||
* @param mixed $flash
|
||||
* @param mixed $progress
|
||||
* @param array $numbers : Les numéros auxquels envoyer le scheduled
|
||||
* @param array $contacts_ids : Les ids des contact auquels envoyer le scheduled
|
||||
* @param array $groups_ids : Les ids des group auxquels envoyer le scheduled
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id du nouveau scheduled inséré
|
||||
*/
|
||||
public function create($id_user, $at, $text, $origin = null, $flash = false, $numbers = [], $contacts_ids = [], $groups_ids = [])
|
||||
{
|
||||
$scheduled = [
|
||||
$scheduled = [
|
||||
'id_user' => $id_user,
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
|
@ -125,50 +47,74 @@ namespace controllers\internals;
|
|||
'flash' => $flash,
|
||||
];
|
||||
|
||||
if (!$id_scheduled = $this->model_scheduled->insert($scheduled))
|
||||
if ($origin)
|
||||
{
|
||||
$internal_phone = new Phone($this->bdd);
|
||||
$find_phone = $internal_phone->get_by_number_and_user($id_user, $origin);
|
||||
|
||||
if (!$find_phone)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$id_scheduled = $this->get_model()->insert($scheduled);
|
||||
if (!$id_scheduled)
|
||||
{
|
||||
$date = date('Y-m-d H:i:s');
|
||||
$this->internal_event->create($id_user, 'SCHEDULED_ADD', 'Ajout d\'un Sms pour le '.$date.'.');
|
||||
|
||||
$internal_event = new Event($this->bdd);
|
||||
$internal_event->create($id_user, 'SCHEDULED_ADD', 'Ajout d\'un Sms pour le ' . $date . '.');
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($numbers as $number)
|
||||
{
|
||||
$this->model_scheduled->insert_scheduled_number($id_scheduled, $number);
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number);
|
||||
}
|
||||
|
||||
foreach ($contacts_ids as $contact_id)
|
||||
{
|
||||
$this->model_scheduled->insert_scheduled_contact($id_scheduled, $contact_id);
|
||||
$find_contact = $this->get_model()->get_for_user($id_user, $contact_id);
|
||||
if (!$find_contact)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->get_model()->insert_scheduled_contact($id_scheduled, $contact_id);
|
||||
}
|
||||
|
||||
foreach ($groups_ids as $group_id)
|
||||
{
|
||||
$this->model_scheduled->insert_scheduled_group($id_scheduled, $group_id);
|
||||
$find_group = $this->get_model()->get_for_user($id_user, $group_id);
|
||||
if (!$find_group)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->get_model()->insert_scheduled_group($id_scheduled, $group_id);
|
||||
}
|
||||
|
||||
return $id_scheduled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction met à jour une série de scheduleds.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param int $id_user : User id
|
||||
* @param mixed $text
|
||||
* @param mixed $at
|
||||
* @param mixed $origin
|
||||
* @param array $numbers : Les numéros auxquels envoyer le scheduled
|
||||
* @param array $contacts_ids : Les ids des contact auquels envoyer le scheduled
|
||||
* @param array $groups_ids : Les ids des group auxquels envoyer le scheduled
|
||||
* @param mixed $flash
|
||||
*
|
||||
* @return int : le nombre de ligne modifiées
|
||||
* Update a scheduled
|
||||
* @param int $id_user : User to insert scheduled for
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @param $at : Scheduled date to send
|
||||
* @param string $text : Text of the message
|
||||
* @param ?string $origin : Origin number of the message, null by default
|
||||
* @param bool $flash : Is the sms a flash sms, by default false
|
||||
* @param array $numbers : Numbers to send message to
|
||||
* @param array $contacts_ids : Contact ids to send message to
|
||||
* @param array $groups_ids : Group ids to send message to
|
||||
* @return bool : false on error, new id on success
|
||||
*/
|
||||
public function update($id, $id_user, $at, $text, $origin = null, $flash = false, $numbers = [], $contacts_ids = [], $groups_ids = [])
|
||||
public function update_for_user (int $id_user, int $id_scheduled, $at, string $text, ?string $origin = null, bool $flash = false, array $numbers = [], array $contacts_ids = [], array $groups_ids = [])
|
||||
{
|
||||
$scheduled = [
|
||||
$scheduled = [
|
||||
'id_user' => $id_user,
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
|
@ -176,7 +122,18 @@ namespace controllers\internals;
|
|||
'flash' => $flash,
|
||||
];
|
||||
|
||||
$success = $this->model_scheduled->update($id, $scheduled);
|
||||
if ($origin)
|
||||
{
|
||||
$internal_phone = new Phone($this->bdd);
|
||||
$find_phone = $internal_phone->get_by_number_and_user($id_user, $origin);
|
||||
|
||||
if (!$find_phone)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$success = (bool) $this->get_model()->update_for_user($id_user, $id_scheduled, $scheduled);
|
||||
|
||||
$this->model_scheduled->delete_scheduled_numbers($id);
|
||||
$this->model_scheduled->delete_scheduled_contacts($id);
|
||||
|
@ -184,71 +141,77 @@ namespace controllers\internals;
|
|||
|
||||
foreach ($numbers as $number)
|
||||
{
|
||||
$this->model_scheduled->insert_scheduled_number($id, $number);
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number);
|
||||
}
|
||||
|
||||
foreach ($contacts_ids as $contact_id)
|
||||
{
|
||||
$this->model_scheduled->insert_scheduled_contact($id, $contact_id);
|
||||
$find_contact = $this->get_model()->get_for_user($id_user, $contact_id);
|
||||
if (!$find_contact)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->get_model()->insert_scheduled_contact($id_scheduled, $contact_id);
|
||||
}
|
||||
|
||||
foreach ($groups_ids as $group_id)
|
||||
{
|
||||
$this->model_scheduled->insert_scheduled_group($id, $group_id);
|
||||
$find_group = $this->get_model()->get_for_user($id_user, $group_id);
|
||||
if (!$find_group)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->get_model()->insert_scheduled_group($id_scheduled, $group_id);
|
||||
}
|
||||
|
||||
return (bool) $success;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 : La liste des scheduleds
|
||||
*/
|
||||
public function get_numbers($id_scheduled)
|
||||
{
|
||||
//Recupération des scheduleds
|
||||
return $this->model_scheduled->get_numbers($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 : La liste des contact
|
||||
* 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_contacts($id_scheduled)
|
||||
public function get_before_date_for_number_and_user (int $id_user, $date, string $number)
|
||||
{
|
||||
//Recupération des scheduleds
|
||||
return $this->model_scheduled->get_contacts($id_scheduled);
|
||||
return $this->get_model()->get_before_date_for_number_and_user($id_user, $date, $number);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste de group pour un scheduled.
|
||||
*
|
||||
* @param int $id_scheduled : L'id du scheduled pour lequel on veux le numéro
|
||||
*
|
||||
* @return array : La liste des group
|
||||
* Return numbers for a scheduled message
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_groups($id_scheduled)
|
||||
public function get_numbers(int $id_scheduled)
|
||||
{
|
||||
//Recupération des scheduleds
|
||||
return $this->model_scheduled->get_groups($id_scheduled);
|
||||
return $this->get_model()->get_numbers($id_scheduled);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function update progress status of a scheduled sms.
|
||||
*
|
||||
* @param bool $progress : Progress status
|
||||
* @param mixed $id_scheduled
|
||||
*
|
||||
* @return int : Number of update
|
||||
* Return contacts for a scheduled message
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function update_progress($id_scheduled, $progress)
|
||||
public function get_contacts(int $id_scheduled)
|
||||
{
|
||||
return $this->model_scheduled->update($id_scheduled, ['progress' => $progress]);
|
||||
return $this->get_model()->get_contacts($id_scheduled);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return groups for a scheduled message
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_groups(int $id_scheduled)
|
||||
{
|
||||
return $this->get_model()->get_groups($id_scheduled);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,167 +11,121 @@
|
|||
|
||||
namespace controllers\internals;
|
||||
|
||||
/**
|
||||
* Classe des sendedes.
|
||||
*/
|
||||
class Sended extends \descartes\InternalController
|
||||
class Sended extends StandardController
|
||||
{
|
||||
private $model_sended;
|
||||
|
||||
public function __construct(\PDO $bdd)
|
||||
{
|
||||
$this->model_sended = new \models\Sended($bdd);
|
||||
}
|
||||
protected $model = false;
|
||||
|
||||
/**
|
||||
* List sms 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
|
||||
* Get the model for the Controller
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
public function list($id_user, $nb_entry = null, $page = null)
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
return $this->model_sended->list_for_user($id_user, $nb_entry, $nb_entry * $page);
|
||||
$this->model = $this->model ?? new \models\Sended($this->$bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sended
|
||||
* @param $at : Reception date
|
||||
* @param $text : Text of the message
|
||||
* @param string $origin : Number of the sender
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param bool $flash : Is the sms a flash
|
||||
* @param ?string $status : Status of a the sms. By default null -> unknown
|
||||
* @return bool : false on error, new sended id else
|
||||
*/
|
||||
public function create ($at, string $text, string $origin, string $destination, bool $flash = false, ?string $status = null) : bool
|
||||
{
|
||||
$sended = [
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
'destination' => $destination,
|
||||
'flash' => $flash,
|
||||
'status' => $status,
|
||||
];
|
||||
|
||||
return (bool) $this->get_model()->insert($sended);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a sended for a user
|
||||
* @param int $id_user : user id
|
||||
* @param int $id_sended : Sended id
|
||||
* @param $at : Reception date
|
||||
* @param $text : Text of the message
|
||||
* @param string $origin : Number of the sender
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param bool $flash : Is the sms a flash
|
||||
* @param ?string $status : Status of a the sms. By default null -> unknown
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function update_for_user (int $id_user, int $id_sended, $at, string $text, string $origin, string $destination, bool $flash = false, ?string $status = null) : bool
|
||||
{
|
||||
$sended = [
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
'destination' => $destination,
|
||||
'flash' => $flash,
|
||||
'status' => $status,
|
||||
];
|
||||
|
||||
return (bool) $this->get_model()->update_for_user($id_user, $id_sended, $sended);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a sended sms
|
||||
* @param $id : received id
|
||||
* Update a sended status for a user
|
||||
* @param int $id_user : user id
|
||||
* @param int $id_sended : Sended id
|
||||
* @param string $status : Status of a the sms (unknown, delivered, failed)
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function update_status_for_user (int $id_user, int $id_sended, string $status) : bool
|
||||
{
|
||||
$sended = [
|
||||
'status' => $status,
|
||||
];
|
||||
|
||||
return (bool) $this->get_model()->update_for_user($id_user, $id_sended, $sended);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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(int $id_user, int $nb_entry)
|
||||
{
|
||||
return $this->get_model()->get_lasts_by_date_for_user($id_user, $nb_entry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return sendeds for a destination and a user
|
||||
* @param int $id_user : User id
|
||||
* @param string $origin : Number who sent the message
|
||||
* @return array
|
||||
*/
|
||||
public function get($id)
|
||||
public function gets_by_destination_for_user(int $id_user, string $origin)
|
||||
{
|
||||
return $this->model_sended->get($id);
|
||||
return $this->get_model()->gets_by_destination_for_user($id_user, $origin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des sendedes sous forme d'un tableau.
|
||||
*
|
||||
* @param array int $ids : Les ids des entrées à retourner
|
||||
*
|
||||
* @return array : La liste des sendedes
|
||||
*/
|
||||
public function gets($ids)
|
||||
{
|
||||
//Recupération des sendedes
|
||||
return $this->model_sended->gets($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne les X dernières entrées triées par date.
|
||||
*
|
||||
* @param mixed false|int $nb_entry : Nombre d'entrée à retourner ou faux pour tout
|
||||
*
|
||||
* @return array : Les dernières entrées
|
||||
*/
|
||||
public function get_lasts_by_date($nb_entry = false)
|
||||
{
|
||||
return $this->model_sended->get_lasts_by_date($nb_entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des receivedes sous forme d'un tableau.
|
||||
*
|
||||
* @param string $destination : Le numéro auquel est envoyé le message
|
||||
*
|
||||
* @return array : La liste des sendeds
|
||||
*/
|
||||
public function get_by_destination($destination)
|
||||
{
|
||||
//Recupération des sendeds
|
||||
return $this->model_sended->get_by_destination($destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction va supprimer une liste de sendeds.
|
||||
*
|
||||
* @param array $ids : Les id des sendedes à supprimer
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return int : Le nombre de sendedes supprimées;
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return $this->model_sended->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction insert une nouvelle sendede.
|
||||
*
|
||||
* @param array $sended : Un tableau représentant la sendede à insérer
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle sendede insérée
|
||||
*/
|
||||
public function create($sended)
|
||||
{
|
||||
return $this->model_sended->create($sended);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction permet de compter le nombre de sendeds.
|
||||
*
|
||||
* @return int : Le nombre d'entrées dans la table
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->model_sended->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction compte le nombre de sendeds par jour depuis une date.
|
||||
*
|
||||
* @param mixed $date
|
||||
*
|
||||
* @return array : un tableau avec en clef la date et en valeure le nombre de sms envoyés
|
||||
*/
|
||||
public function count_by_day_since($date)
|
||||
{
|
||||
$counts_by_day = $this->model_sended->count_by_day_since($date);
|
||||
$return = [];
|
||||
|
||||
foreach ($counts_by_day as $count_by_day)
|
||||
{
|
||||
$return[$count_by_day['at_ymd']] = $count_by_day['nb'];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement before delivered.
|
||||
*
|
||||
* @param int $id_sended : id of the sended to decrement delivered for
|
||||
*
|
||||
* 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 decrement_before_delivered($id_sended)
|
||||
public function count_by_day_since_for_user(int $id_user, $date)
|
||||
{
|
||||
return $this->model_sended->decrement_before_delivered($id_sended);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update status.
|
||||
*
|
||||
* @param int $id_sended : id of the sended to mark as delivered
|
||||
* @param string $status : new status
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function update_status($id_sended, $status)
|
||||
{
|
||||
return $this->model_sended->update($id_sended, ['status' => $status]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update sended to delivered.
|
||||
*
|
||||
* @param int $id_sended : id of the sended to mark as delivered
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function set_delivered($id_sended)
|
||||
{
|
||||
return $this->model_sended->update($id_sended, ['status' => 'delivered']);
|
||||
return $this->get_model()->count_by_day_since_for_user($id_user, $date);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,14 +11,20 @@
|
|||
|
||||
namespace controllers\internals;
|
||||
|
||||
class Setting extends \descartes\InternalController
|
||||
class Setting extends StandardController
|
||||
{
|
||||
private $model_setting;
|
||||
protected $model = false;
|
||||
|
||||
public function __construct(\PDO $bdd)
|
||||
/**
|
||||
* Get the model for the Controller
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
$this->model_setting = new \models\Setting($bdd);
|
||||
}
|
||||
$this->model = $this->model ?? new \models\Setting($this->bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return all settings of a user.
|
||||
|
@ -27,7 +33,7 @@ namespace controllers\internals;
|
|||
*/
|
||||
public function gets_for_user (int $id_user)
|
||||
{
|
||||
$settings = $this->model_setting->gets_for_user($id_user);
|
||||
$settings = $this->get_model()->gets_for_user($id_user);
|
||||
$settings_array = [];
|
||||
|
||||
foreach ($settings as $setting)
|
||||
|
@ -46,9 +52,9 @@ namespace controllers\internals;
|
|||
* @param mixed $value
|
||||
* @return int : number of modified lines
|
||||
*/
|
||||
public function update (int $id_user, string $name, $value) : bool
|
||||
public function update_for_user (int $id_user, string $name, $value) : bool
|
||||
{
|
||||
return (bool) $this->model_setting->update($id_user, $name, $value);
|
||||
return (bool) $this->get_model()->update($id_user, $name, $value);
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,7 +65,7 @@ namespace controllers\internals;
|
|||
* @param mixed $value : value of the setting
|
||||
* @return bool
|
||||
*/
|
||||
public function insert (int $id_user, string $name, $value) : bool
|
||||
public function create (int $id_user, string $name, $value) : bool
|
||||
{
|
||||
$setting = [
|
||||
'id_user' => $id_user,
|
||||
|
@ -67,6 +73,6 @@ namespace controllers\internals;
|
|||
'value' => $value,
|
||||
];
|
||||
|
||||
return (bool) $this->model_setting->insert($setting);
|
||||
return (bool) $this->get_model()->insert($setting);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,100 +11,63 @@
|
|||
|
||||
namespace controllers\internals;
|
||||
|
||||
/**
|
||||
* Classe des smsstopes.
|
||||
*/
|
||||
class SmsStop extends \descartes\InternalController
|
||||
class SmsStop extends StandardController
|
||||
{
|
||||
private $model_sms_stop;
|
||||
|
||||
public function __construct(\PDO $bdd)
|
||||
{
|
||||
$this->model_sms_stop = new \models\SmsStop($bdd);
|
||||
}
|
||||
protected $model = false;
|
||||
|
||||
/**
|
||||
* Return all smsstops.
|
||||
*
|
||||
* Get the model for the Controller
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
$this->model = $this->model ?? new \models\SmsStop($this->$bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new smsstop
|
||||
* @param int $id_user : User id
|
||||
* @param string $number : Number to stop smss for
|
||||
* @return mixed bool|int : False if cannot create smsstop, id of the new smsstop else
|
||||
*/
|
||||
public function create(int $id_user, string $number)
|
||||
{
|
||||
$smsstop = [
|
||||
'id_user' => $id_user,
|
||||
'number' => $number,
|
||||
];
|
||||
|
||||
return $this->get_model()->insert($smsstop);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a smsstop
|
||||
* @param int $id_user : User id
|
||||
* @param int $id_smsstop : SmsStop id
|
||||
* @param string $number : Number to stop smss for
|
||||
* @return mixed bool|int : False if cannot create smsstop, id of the new smsstop else
|
||||
*/
|
||||
public function update_for_user(int $id_user, int $id_smsstop, string $number)
|
||||
{
|
||||
$datas = [
|
||||
'number' => $number,
|
||||
];
|
||||
|
||||
return $this->get_model()->update_for_user($id_user, $id_smsstop, $datas);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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->model_sms_stop->get_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des smsstopes sous forme d'un tableau.
|
||||
*
|
||||
* @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 smsstopes
|
||||
*/
|
||||
public function list($nb_entry = null, $page = null)
|
||||
{
|
||||
//Recupération des smsstopes
|
||||
return $this->model_sms_stop->list($nb_entry, $nb_entry * $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne une liste des smsstopes sous forme d'un tableau.
|
||||
*
|
||||
* @param array int $ids : Les ids des entrées à retourner
|
||||
*
|
||||
* @return array : La liste des smsstopes
|
||||
*/
|
||||
public function gets($ids)
|
||||
{
|
||||
//Recupération des smsstopes
|
||||
return $this->model_sms_stop->gets($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne un smsstop par son numéro de tel.
|
||||
*
|
||||
* @param string $number : Le numéro du smsstop
|
||||
*
|
||||
* @return array : Le smsstop
|
||||
*/
|
||||
public function get_by_number($number)
|
||||
{
|
||||
//Recupération des smsstopes
|
||||
return $this->model_sms_stop->get_by_number($number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction permet de compter le nombre de smsstops.
|
||||
*
|
||||
* @return int : Le nombre d'entrées dans la table
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->model_sms_stop->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction va supprimer une liste de smsstops.
|
||||
*
|
||||
* @param array $ids : Les id des smsstopes à supprimer
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return int : Le nombre de smsstopes supprimées;
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return $this->model_sms_stop->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction insert une nouvelle smsstope.
|
||||
*
|
||||
* @param array $smsstop : Un tableau représentant la smsstope à insérer
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle smsstope insérée
|
||||
*/
|
||||
public function create($smsstop)
|
||||
{
|
||||
return $this->model_sms_stop->insert($smsstop);
|
||||
return $this->get_model()->get_by_number_for_user($id_user, $number);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
|
||||
namespace controllers\internals;
|
||||
|
||||
/**
|
||||
* Some tools frequently used.
|
||||
* Not a standard controller as it's not linked to a model in any way
|
||||
*/
|
||||
class Tool extends \descartes\InternalController
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
|
||||
namespace controllers\internals;
|
||||
|
||||
/**
|
||||
* Methods to manage user. Not a standard controller as it has nothing to do with user based restrictions and must be usable only by admin
|
||||
*/
|
||||
class User extends \descartes\InternalController
|
||||
{
|
||||
private $model_user;
|
||||
|
@ -36,25 +39,26 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Cette fonction va supprimer une liste de users.
|
||||
* Delete a user.
|
||||
*
|
||||
* @param array $ids : Les id des useres à supprimer
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return int : Le nombre de useres supprimées;
|
||||
* @return int : Number of users deleted
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return $this->model_user->remove($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction vérifie s'il existe un utilisateur qui corresponde à ce couple login/password.
|
||||
* Check user credentials
|
||||
*
|
||||
* @param string $email : L'eamil de l'utilisateur
|
||||
* @param string $password : Le mot de passe de l'utilisateur
|
||||
* @param string $email : User email
|
||||
* @param string $password : User password
|
||||
*
|
||||
* @return mixed false | array : False si pas de user, le user correspondant sous forme d'array sinon
|
||||
* @return mixed false | array : False if no user for thoses credentials, the user else
|
||||
*/
|
||||
public function check_credentials($email, $password)
|
||||
{
|
||||
|
@ -114,11 +118,10 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne un utilisateur pour un mail donné.
|
||||
* Get a user by his email address
|
||||
* @param string $email : User email
|
||||
*
|
||||
* @param string $email : L'email de l'utilisateur
|
||||
*
|
||||
* @return mixed boolean | array : false si pas de user pour le mail, le user sinon
|
||||
* @return mixed boolean | array : false if cannot find user for this email, the user else
|
||||
*/
|
||||
public function get_by_email($email)
|
||||
{
|
||||
|
@ -136,15 +139,14 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Cette fonction met à jour une série de users.
|
||||
*
|
||||
* Update a user by his id
|
||||
* @param mixed $id
|
||||
* @param mixed $email
|
||||
* @param mixed $password
|
||||
* @param mixed $admin
|
||||
* @param mixed $transfer
|
||||
*
|
||||
* @return int : le nombre de ligne modifiées
|
||||
* @return int : Number of modified user
|
||||
*/
|
||||
public function update($id, $email, $password, $admin, $transfer)
|
||||
{
|
||||
|
@ -159,15 +161,14 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Cette fonction insert une nouvelle usere.
|
||||
* Create a new user
|
||||
*
|
||||
* @param array $user : Un tableau représentant la usere à insérer
|
||||
* @param mixed $email
|
||||
* @param mixed $password
|
||||
* @param mixed $admin
|
||||
* @param mixed $transfer
|
||||
*
|
||||
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle usere insérée
|
||||
* @return mixed bool|int : false on error, id of the new user else
|
||||
*/
|
||||
public function create($email, $password, $admin, $transfer = false)
|
||||
{
|
||||
|
@ -185,8 +186,6 @@ namespace controllers\internals;
|
|||
return false;
|
||||
}
|
||||
|
||||
$this->internal_event->create($_SESSION['user']['id'], 'CONTACT_ADD', 'Ajout de l\'utilisateur : '.$email.'.');
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace models;
|
|||
* @param string $number : phone number
|
||||
* @return array
|
||||
*/
|
||||
public function get_by_number_for_user (int $id_user, string $number)
|
||||
public function get_by_number_and_user (int $id_user, string $number)
|
||||
{
|
||||
return $this->_select_one('phone', ['number' => $number, 'id_user' => $id_user]);
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ namespace models;
|
|||
* @param int $id_user : user id
|
||||
* @return int : Number of received SMS for user
|
||||
*/
|
||||
public function count_for_user($id_user)
|
||||
public function count_for_user(int $id_user)
|
||||
{
|
||||
$query = '
|
||||
SELECT COUNT(id) as nb
|
||||
|
@ -178,7 +178,7 @@ namespace models;
|
|||
* @param int $nb_entry : Number of receiveds messages to return
|
||||
* @return array
|
||||
*/
|
||||
public function get_lasts_by_date_for_user($id_user, $nb_entry)
|
||||
public function get_lasts_by_date_for_user(int $id_user, int $nb_entry)
|
||||
{
|
||||
$nb_entry = (int) $nb_entry;
|
||||
|
||||
|
@ -229,7 +229,7 @@ namespace models;
|
|||
* @param \DateTime $date : Date since which we want the messages
|
||||
* @return array
|
||||
*/
|
||||
public function count_by_day_since_for_user($id_user, $date)
|
||||
public function count_by_day_since_for_user(int $id_user, $date)
|
||||
{
|
||||
$query = "
|
||||
SELECT COUNT(id) as nb, DATE_FORMAT(at, '%Y-%m-%d') as at_ymd
|
||||
|
@ -274,11 +274,11 @@ namespace models;
|
|||
|
||||
/**
|
||||
* Get SMS received 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
|
||||
* @param $date : La date depuis laquelle on veux les SMS (au format 2014-10-25 20:10:05)
|
||||
* @return array : Tableau avec tous les SMS depuis la date
|
||||
*/
|
||||
public function get_since_by_date_for_user($date, $id_user)
|
||||
public function get_since_by_date_for_user(int $id_user, $date)
|
||||
{
|
||||
$query = "
|
||||
SELECT *
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace models;
|
|||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_numbers($id_scheduled)
|
||||
public function get_numbers(int $id_scheduled)
|
||||
{
|
||||
return $this->_select('scheduled_number', ['id_scheduled' => $id_scheduled]);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace models;
|
|||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_contacts($id_scheduled)
|
||||
public function get_contacts(int $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];
|
||||
|
@ -49,7 +49,7 @@ namespace models;
|
|||
* @param int $id_scheduled : Scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_groups($id_scheduled)
|
||||
public function get_groups(int $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];
|
||||
|
|
|
@ -247,31 +247,6 @@ namespace models;
|
|||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 get_discussions_for_user(int $id_user)
|
||||
{
|
||||
$query = '
|
||||
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_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)
|
||||
|
@ -295,30 +270,4 @@ namespace models;
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue