Added last_id to notification ball
Former-commit-id: f7095e633ce5799cf79bd20393e13e5b6233bf4c
This commit is contained in:
parent
d5d58e5b2b
commit
e6dc69e3be
|
@ -319,7 +319,11 @@ config_check();
|
|||
).'</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
|
||||
$table->data[0][5] = '<a class="white" href="'.ui_get_full_url('index.php?bye=bye').'">';
|
||||
|
|
|
@ -417,6 +417,7 @@ function messages_get_count_sent(string $user='')
|
|||
* (ASC = Ascending, DESC = Descending).
|
||||
* @param boolean $incl_read Include read messages in return.
|
||||
* @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
|
||||
*/
|
||||
|
@ -424,7 +425,8 @@ function messages_get_overview(
|
|||
string $order='status',
|
||||
string $order_dir='ASC',
|
||||
bool $incl_read=true,
|
||||
bool $incl_source_info=false
|
||||
bool $incl_source_info=false,
|
||||
int $limit=0
|
||||
) {
|
||||
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)
|
||||
) t
|
||||
%s
|
||||
ORDER BY %s',
|
||||
ORDER BY %s
|
||||
%s',
|
||||
$source_fields,
|
||||
$source_join,
|
||||
$config['id_user'],
|
||||
$config['id_user'],
|
||||
$read,
|
||||
$order
|
||||
$order,
|
||||
($limit !== 0) ? ' LIMIT '.$limit : ''
|
||||
);
|
||||
|
||||
return db_get_all_rows_sql($sql);
|
||||
|
|
|
@ -519,7 +519,37 @@ function notifications_set_user_label_status($source, $user, $label, $value)
|
|||
'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.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
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';
|
||||
return sprintf(
|
||||
'<div
|
||||
onclick="addNotifications(event)"
|
||||
class="notification-ball %s"
|
||||
id="notification-ball-header"
|
||||
last_id="%s"
|
||||
>
|
||||
%s
|
||||
</div>',
|
||||
$class_status,
|
||||
$last_id,
|
||||
$num_notifications
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue