Added last_id to notification ball

Former-commit-id: f7095e633ce5799cf79bd20393e13e5b6233bf4c
This commit is contained in:
fermin831 2019-02-11 13:05:31 +01:00
parent d5d58e5b2b
commit e6dc69e3be
3 changed files with 50 additions and 6 deletions

View File

@ -319,7 +319,11 @@ config_check();
).'</a>'; ).'</a>';
} }
$table->data[0]['notifications'] = notifications_print_ball(); $notifications_numbers = notifications_get_counters();
$table->data[0]['notifications'] = notifications_print_ball(
$notifications_numbers['notifications'],
$notifications_numbers['last_id']
);
// Logout // Logout
$table->data[0][5] = '<a class="white" href="'.ui_get_full_url('index.php?bye=bye').'">'; $table->data[0][5] = '<a class="white" href="'.ui_get_full_url('index.php?bye=bye').'">';

View File

@ -417,6 +417,7 @@ function messages_get_count_sent(string $user='')
* (ASC = Ascending, DESC = Descending). * (ASC = Ascending, DESC = Descending).
* @param boolean $incl_read Include read messages in return. * @param boolean $incl_read Include read messages in return.
* @param boolean $incl_source_info Include source info. * @param boolean $incl_source_info Include source info.
* @param integer $limit Maximum number of result in the query.
* *
* @return integer The number of messages this user has * @return integer The number of messages this user has
*/ */
@ -424,7 +425,8 @@ function messages_get_overview(
string $order='status', string $order='status',
string $order_dir='ASC', string $order_dir='ASC',
bool $incl_read=true, bool $incl_read=true,
bool $incl_source_info=false bool $incl_source_info=false,
int $limit=0
) { ) {
global $config; global $config;
@ -478,13 +480,15 @@ function messages_get_overview(
AND (up.id_usuario="%s" OR nu.id_user="%s" OR ng.id_group=0) AND (up.id_usuario="%s" OR nu.id_user="%s" OR ng.id_group=0)
) t ) t
%s %s
ORDER BY %s', ORDER BY %s
%s',
$source_fields, $source_fields,
$source_join, $source_join,
$config['id_user'], $config['id_user'],
$config['id_user'], $config['id_user'],
$read, $read,
$order $order,
($limit !== 0) ? ' LIMIT '.$limit : ''
); );
return db_get_all_rows_sql($sql); return db_get_all_rows_sql($sql);

View File

@ -519,7 +519,37 @@ function notifications_set_user_label_status($source, $user, $label, $value)
'id_source' => $source, 'id_source' => $source,
] ]
); );
}
/**
* Get the counters of notification. Usefull to print the header notification
* ball.
*
* @return array With the fields:
* 'notifications' => Total new notifications,
* 'last_id' => Id of last read value. Usefull to make comparisons.
*/
function notifications_get_counters()
{
$num_notifications = 0;
$last_id = 0;
$last_message = messages_get_overview(
'timestamp',
'DESC',
false,
false,
1
);
if (!empty($last_message)) {
$num_notifications = messages_get_count();
$last_id = $last_message[0]['id_mensaje'];
}
return [
'notifications' => $num_notifications,
'last_id' => $last_id,
];
} }
@ -531,21 +561,27 @@ function notifications_set_user_label_status($source, $user, $label, $value)
/** /**
* Print the notification ball to see unread messages. * Print the notification ball to see unread messages.
* *
* @param integer $num_notifications Number of messages shown
* in notification ball.
* @param integer $last_id Id of last message shown
* in the notification ball.
*
* @return string with HTML code of notification ball. * @return string with HTML code of notification ball.
*/ */
function notifications_print_ball() function notifications_print_ball($num_notifications, $last_id)
{ {
$num_notifications = messages_get_count();
$class_status = ($num_notifications == 0) ? 'notification-ball-no-messages' : 'notification-ball-new-messages'; $class_status = ($num_notifications == 0) ? 'notification-ball-no-messages' : 'notification-ball-new-messages';
return sprintf( return sprintf(
'<div '<div
onclick="addNotifications(event)" onclick="addNotifications(event)"
class="notification-ball %s" class="notification-ball %s"
id="notification-ball-header" id="notification-ball-header"
last_id="%s"
> >
%s %s
</div>', </div>',
$class_status, $class_status,
$last_id,
$num_notifications $num_notifications
); );
} }