mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-05-12 19:16:26 +02:00
Add unread messages support
This commit is contained in:
parent
cfde77a0c1
commit
88b00e4e9f
12 changed files with 249 additions and 15 deletions
controllers
|
@ -24,6 +24,20 @@ namespace controllers\internals;
|
|||
$this->model = $this->model ?? new \models\Received($this->bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the list of unread messages for a user
|
||||
* @param int $id_user : User id
|
||||
* @param ?int $nb_entry : Number of entry to return
|
||||
* @param ?int $page : Pagination, used to calcul offset, $nb_entry * $page
|
||||
* @return array : Entrys list
|
||||
*/
|
||||
public function list_unread_for_user (int $id_user, ?int $nb_entry = null, ?int $page = null)
|
||||
{
|
||||
return $this->get_model()->list_unread_for_user($id_user, $nb_entry, $nb_entry * $page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a received
|
||||
|
@ -31,16 +45,18 @@ namespace controllers\internals;
|
|||
* @param $text : Text of the message
|
||||
* @param string $origin : Number of the sender
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param string $status : Status of the received message
|
||||
* @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
|
||||
public function create ($at, string $text, string $origin, string $destination, string $status = 'unread', bool $command = false) : bool
|
||||
{
|
||||
$received = [
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
'destination' => $destination,
|
||||
'status' => $status,
|
||||
'command' => $command,
|
||||
];
|
||||
|
||||
|
@ -56,16 +72,18 @@ namespace controllers\internals;
|
|||
* @param $text : Text of the message
|
||||
* @param string $origin : Number of the sender
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param string $status : Status of the received message
|
||||
* @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
|
||||
public function update_for_user (int $id_user, int $id_received, $at, string $text, string $origin, string $destination, string $status = 'unread', bool $command = false) : bool
|
||||
{
|
||||
$received = [
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
'destination' => $destination,
|
||||
'status' => $status,
|
||||
'command' => $command,
|
||||
];
|
||||
|
||||
|
@ -73,6 +91,50 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a received message for a user to mark the message as read
|
||||
* @param int $id_user : user id
|
||||
* @param int $id_received : received id
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function mark_as_read_for_user (int $id_user, int $id_received) : bool
|
||||
{
|
||||
$received = [
|
||||
'status' => 'read',
|
||||
];
|
||||
|
||||
return (bool) $this->get_model()->update_for_user($id_user, $id_received, $received);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a received message for a user to mark the message as unread
|
||||
* @param int $id_user : user id
|
||||
* @param int $id_received : received id
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function mark_as_unread_for_user (int $id_user, int $id_received) : bool
|
||||
{
|
||||
$received = [
|
||||
'status' => 'unread',
|
||||
];
|
||||
|
||||
return (bool) $this->get_model()->update_for_user($id_user, $id_received, $received);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return number of unread messages for a user
|
||||
* @param int $id_user : User id
|
||||
* @return array
|
||||
*/
|
||||
public function count_unread_for_user(int $id_user)
|
||||
{
|
||||
return $this->get_model()->count_unread_for_user($id_user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return x last receiveds message for a user, order by date
|
||||
* @param int $id_user : User id
|
||||
|
|
|
@ -21,7 +21,6 @@ namespace controllers\publics;
|
|||
private $internal_contact;
|
||||
private $internal_group;
|
||||
private $internal_scheduled;
|
||||
private $internal_command;
|
||||
private $internal_event;
|
||||
|
||||
/**
|
||||
|
@ -39,7 +38,6 @@ namespace controllers\publics;
|
|||
$this->internal_contact = new \controllers\internals\Contact($bdd);
|
||||
$this->internal_group = new \controllers\internals\Group($bdd);
|
||||
$this->internal_scheduled = new \controllers\internals\Scheduled($bdd);
|
||||
$this->internal_command = new \controllers\internals\Command($bdd);
|
||||
$this->internal_event = new \controllers\internals\Event($bdd);
|
||||
|
||||
\controllers\internals\Tool::verifyconnect();
|
||||
|
@ -58,7 +56,7 @@ namespace controllers\publics;
|
|||
$nb_contacts = $this->internal_contact->count_for_user($id_user);
|
||||
$nb_groups = $this->internal_group->count_for_user($id_user);
|
||||
$nb_scheduleds = $this->internal_scheduled->count_for_user($id_user);
|
||||
$nb_commands = $this->internal_command->count_for_user($id_user);
|
||||
$nb_unreads = $this->internal_received->count_unread_for_user($id_user);
|
||||
$nb_sendeds = $this->internal_sended->count_for_user($id_user);
|
||||
$nb_receiveds = $this->internal_received->count_for_user($id_user);
|
||||
|
||||
|
@ -124,9 +122,9 @@ namespace controllers\publics;
|
|||
'nb_contacts' => $nb_contacts,
|
||||
'nb_groups' => $nb_groups,
|
||||
'nb_scheduleds' => $nb_scheduleds,
|
||||
'nb_commands' => $nb_commands,
|
||||
'nb_sendeds' => $nb_sendeds,
|
||||
'nb_receiveds' => $nb_receiveds,
|
||||
'nb_unreads' => $nb_unreads,
|
||||
'avg_sendeds' => $avg_sendeds,
|
||||
'avg_receiveds' => $avg_receiveds,
|
||||
'sendeds' => $sendeds,
|
||||
|
|
|
@ -107,6 +107,11 @@ namespace controllers\publics;
|
|||
|
||||
foreach ($receiveds as $received)
|
||||
{
|
||||
if ($received['status'] != 'read')
|
||||
{
|
||||
$this->internal_received->mark_as_read_for_user($id_user, $received['id']);
|
||||
}
|
||||
|
||||
$messages[] = [
|
||||
'date' => htmlspecialchars($received['at']),
|
||||
'text' => htmlspecialchars($received['text']),
|
||||
|
|
|
@ -49,6 +49,11 @@ namespace controllers\publics;
|
|||
|
||||
foreach ($receiveds as $key => $received)
|
||||
{
|
||||
if ($received['status'] != 'read')
|
||||
{
|
||||
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
|
||||
}
|
||||
|
||||
if (!$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $received['origin']))
|
||||
{
|
||||
continue;
|
||||
|
@ -59,6 +64,32 @@ namespace controllers\publics;
|
|||
|
||||
$this->render('received/list', ['receiveds' => $receiveds, 'page' => $page, 'limit' => $limit, 'nb_results' => \count($receiveds)]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return all unread receiveds messages
|
||||
* @param mixed $page
|
||||
*/
|
||||
public function list_unread($page = 0)
|
||||
{
|
||||
$page = (int) $page;
|
||||
$limit = 25;
|
||||
$receiveds = $this->internal_received->list_unread_for_user($_SESSION['user']['id'], $limit, $page);
|
||||
|
||||
foreach ($receiveds as $key => $received)
|
||||
{
|
||||
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
|
||||
|
||||
if (!$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $received['origin']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$receiveds[$key]['origin'] = $contact['name'].' ('.$received['origin'].')';
|
||||
}
|
||||
|
||||
$this->render('received/list_unread', ['receiveds' => $receiveds, 'page' => $page, 'limit' => $limit, 'nb_results' => \count($receiveds)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Receiveds
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue