Skip to content

Commit

Permalink
Use ajax calls to get the new message label and user online label see…
Browse files Browse the repository at this point in the history
… BT#12052
  • Loading branch information
jmontoyaa committed Jan 9, 2017
1 parent 58e956c commit 6c8ec09
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 45 deletions.
33 changes: 33 additions & 0 deletions main/inc/ajax/message.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@
$action = $_GET['a'];

switch ($action) {
case 'get_count_message':
$userId = api_get_user_id();
$total_invitations = 0;
$group_pending_invitations = 0;

// Setting notifications
$count_unread_message = 0;
if (api_get_setting('allow_message_tool') == 'true') {
// get count unread message and total invitations
$count_unread_message = MessageManager::get_number_of_messages(true);
}

if (api_get_setting('allow_social_tool') == 'true') {
$number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(
$userId
);
$usergroup = new UserGroup();
$group_pending_invitations = $usergroup->get_groups_by_user(
$userId,
GROUP_USER_PERMISSION_PENDING_INVITATION,
false
);
if (!empty($group_pending_invitations)) {
$group_pending_invitations = count($group_pending_invitations);
} else {
$group_pending_invitations = 0;
}
$total_invitations = intval($number_of_new_messages_of_friend) + $group_pending_invitations + intval($count_unread_message);
}
$total_invitations = !empty($total_invitations) ? Display::badge($total_invitations) : '';

echo $total_invitations;
break;
case 'send_message':
$subject = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : null;
$messageContent = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : null;
Expand Down
3 changes: 3 additions & 0 deletions main/inc/ajax/online.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
$action = $_GET['a'];

switch ($action) {
case 'get_users_online':
echo returnNotificationMenu();
break;
case 'load_online_user':
$images_to_show = MAX_ONLINE_USERS;
$page = intval($_REQUEST['online_page_nr']);
Expand Down
9 changes: 4 additions & 5 deletions main/inc/lib/banner.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,10 @@ function returnNotificationMenu()
// Display the who's online of the platform
if ($number &&
(api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
(api_get_setting('showonline', 'users') == 'true' && $user_id)
)
{
$html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_self" title="'.get_lang('UsersOnline').'" >'.
Display::return_icon('user.png', get_lang('UsersOnline'), array(), ICON_SIZE_TINY).' '.$number.'</a></li>';
(api_get_setting('showonline', 'users') == 'true' && $user_id)
) {
$html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_self" title="'.get_lang('UsersOnline').'" >'.
Display::return_icon('user.png', get_lang('UsersOnline'), array(), ICON_SIZE_TINY).' '.$number.'</a></li>';
}

// Display the who's online for the course
Expand Down
33 changes: 0 additions & 33 deletions main/inc/lib/template.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,9 +922,6 @@ private function set_header_parameters($sendHeaders)

$this->assign('bug_notification', $rightFloatMenu);

$notification = returnNotificationMenu();
$this->assign('notification_menu', $notification);

$resize = '';
if (api_get_setting('accessibility_font_resize') == 'true') {
$resize .= '<div class="resize_font">';
Expand Down Expand Up @@ -990,36 +987,6 @@ private function set_header_parameters($sendHeaders)
$menu = menuArray();
$this->assign('menu', $menu);

// Setting notifications
$count_unread_message = 0;
if (api_get_setting('allow_message_tool') == 'true') {
// get count unread message and total invitations
$count_unread_message = MessageManager::get_number_of_messages(true);
}

$total_invitations = 0;
if (api_get_setting('allow_social_tool') == 'true') {
$number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(
api_get_user_id()
);
$usergroup = new UserGroup();
$group_pending_invitations = $usergroup->get_groups_by_user(
api_get_user_id(),
GROUP_USER_PERMISSION_PENDING_INVITATION,
false
);
if (!empty($group_pending_invitations)) {
$group_pending_invitations = count($group_pending_invitations);
} else {
$group_pending_invitations = 0;
}
$total_invitations = intval($number_of_new_messages_of_friend) + $group_pending_invitations + intval($count_unread_message);
}
$total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : null);

$this->assign('user_notifications', $total_invitations);


// Block Breadcrumb
$breadcrumb = return_breadcrumb($interbreadcrumb, $language_file, $nameTools);
$this->assign('breadcrumb', $breadcrumb);
Expand Down
3 changes: 2 additions & 1 deletion main/inc/lib/userportal.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,8 @@ public function return_profile_block()

if (api_get_setting('allow_social_tool') == 'true') {
$total_invitations = Display::badge($total_invitations);
$profile_content .= '<li class="invitations-social"><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.Display::return_icon('invitations.png',get_lang('PendingInvitations'),null,ICON_SIZE_SMALL).get_lang('PendingInvitations').$total_invitations.'</a></li>';
$profile_content .= '<li class="invitations-social"><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.
Display::return_icon('invitations.png',get_lang('PendingInvitations'),null,ICON_SIZE_SMALL).get_lang('PendingInvitations').$total_invitations.'</a></li>';
}

if (isset($_configuration['allow_my_files_link_in_homepage']) && $_configuration['allow_my_files_link_in_homepage']) {
Expand Down
26 changes: 21 additions & 5 deletions main/template/default/layout/menu.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,30 @@
<div class="collapse navbar-collapse" id="menuone">
<ul class="nav navbar-nav">
{% for item in menu %}
<li class="{{ item.current }}"><a href="{{ item.url }}" target="{{ item.target }}" title="{{ item.title }}">{{ item.title }}</a></li>
<li class="{{ item.current }}">
<a href="{{ item.url }}" target="{{ item.target }}" title="{{ item.title }}">{{ item.title }}
</a>
</li>
{% endfor %}
</ul>
{% if _u.logged == 1 %}
<ul class="nav navbar-nav navbar-right">
{% if user_notifications is not null %}
<li><a href="{{ message_url }}">{{ user_notifications }}</a></li>
{% endif %}
<script>
$(document).ready(function() {
$.ajax({
type: "GET",
url: "{{ _p.web_main }}inc/ajax/message.ajax.php?a=get_count_message",
success: function(data) {
$("#count_message").html(data);
}
});
});
</script>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="{{ message_url }}">
<span id="count_message"></span>
</a>
</li>
{% if _u.status != 6 %}
<li class="dropdown avatar-user">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Expand Down
13 changes: 12 additions & 1 deletion main/template/default/layout/page_header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,20 @@
{{ plugin_header_right }}
</div>
{% endif %}
<script>
$(document).ready(function() {
$.ajax({
type: "GET",
url: "{{ _p.web_main }}inc/ajax/online.ajax.php?a=get_users_online",
success: function(data) {
$("#online_notification").html(data);
}
});
});
</script>
<div class="section-notifications">
<ul id="notifications" class="nav nav-pills pull-right">
{{ notification_menu }}
<span id="online_notification"></span>
</ul>
</div>
{{ accessibility }}
Expand Down

0 comments on commit 6c8ec09

Please sign in to comment.