2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
/*
|
2019-11-10 17:48:54 +01:00
|
|
|
* This file is part of RaspiSMS.
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-11-10 17:48:54 +01:00
|
|
|
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-11-10 17:48:54 +01:00
|
|
|
* This source file is subject to the GPL-3.0 license that is bundled
|
2019-10-30 00:30:39 +01:00
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
namespace controllers\internals;
|
|
|
|
|
2019-11-14 02:02:50 +01:00
|
|
|
class Sended extends StandardController
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
2019-11-14 02:02:50 +01:00
|
|
|
protected $model = false;
|
2019-10-29 18:36:25 +01:00
|
|
|
|
|
|
|
/**
|
2019-11-14 02:02:50 +01:00
|
|
|
* Get the model for the Controller
|
|
|
|
* @return \descartes\Model
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-14 02:02:50 +01:00
|
|
|
protected function get_model () : \descartes\Model
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
2019-11-14 02:02:50 +01:00
|
|
|
$this->model = $this->model ?? new \models\Sended($this->$bdd);
|
|
|
|
return $this->model;
|
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
2019-11-14 02:02:50 +01:00
|
|
|
* 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
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-14 02:02:50 +01:00
|
|
|
public function create ($at, string $text, string $origin, string $destination, bool $flash = false, ?string $status = null) : bool
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
2019-11-14 02:02:50 +01:00
|
|
|
$sended = [
|
|
|
|
'at' => $at,
|
|
|
|
'text' => $text,
|
|
|
|
'origin' => $origin,
|
|
|
|
'destination' => $destination,
|
|
|
|
'flash' => $flash,
|
|
|
|
'status' => $status,
|
|
|
|
];
|
|
|
|
|
|
|
|
return (bool) $this->get_model()->insert($sended);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
/**
|
2019-11-14 02:02:50 +01:00
|
|
|
* 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
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-14 02:02:50 +01:00
|
|
|
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
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
2019-11-14 02:02:50 +01:00
|
|
|
$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);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2019-11-14 02:02:50 +01:00
|
|
|
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
2019-11-14 02:02:50 +01:00
|
|
|
* 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
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-14 02:02:50 +01:00
|
|
|
public function update_status_for_user (int $id_user, int $id_sended, string $status) : bool
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-14 02:02:50 +01:00
|
|
|
$sended = [
|
|
|
|
'status' => $status,
|
|
|
|
];
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-14 02:02:50 +01:00
|
|
|
return (bool) $this->get_model()->update_for_user($id_user, $id_sended, $sended);
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-11-14 02:02:50 +01:00
|
|
|
* 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
|
2019-10-29 14:57:13 +01:00
|
|
|
*/
|
2019-11-14 02:02:50 +01:00
|
|
|
public function get_lasts_by_date_for_user(int $id_user, int $nb_entry)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-14 02:02:50 +01:00
|
|
|
return $this->get_model()->get_lasts_by_date_for_user($id_user, $nb_entry);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2019-11-07 16:17:18 +01:00
|
|
|
|
2019-11-14 02:02:50 +01:00
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
/**
|
2019-11-14 02:02:50 +01:00
|
|
|
* Return sendeds for a destination and a user
|
|
|
|
* @param int $id_user : User id
|
|
|
|
* @param string $origin : Number who sent the message
|
2019-11-07 16:17:18 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-11-14 02:02:50 +01:00
|
|
|
public function gets_by_destination_for_user(int $id_user, string $origin)
|
2019-11-07 16:17:18 +01:00
|
|
|
{
|
2019-11-14 02:02:50 +01:00
|
|
|
return $this->get_model()->gets_by_destination_for_user($id_user, $origin);
|
2019-11-07 16:17:18 +01:00
|
|
|
}
|
|
|
|
|
2019-11-10 17:36:42 +01:00
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
/**
|
2019-11-14 02:02:50 +01:00
|
|
|
* 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
|
2019-11-07 16:17:18 +01:00
|
|
|
*/
|
2019-11-14 02:02:50 +01:00
|
|
|
public function count_by_day_since_for_user(int $id_user, $date)
|
2019-11-07 16:17:18 +01:00
|
|
|
{
|
2019-11-14 02:02:50 +01:00
|
|
|
return $this->get_model()->count_by_day_since_for_user($id_user, $date);
|
2019-11-07 16:17:18 +01:00
|
|
|
}
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|