Browse Source

Better Fix for WhoisOnline page - Refs #8433

José Loguercio 8 years ago
parent
commit
b1bffb4e49

+ 1 - 0
app/Resources/public/css/base.css

@@ -5297,6 +5297,7 @@ div#chat-remote-video video {
   font-size: 12px;
   padding-top: 10px;
   line-height: 15px;
+  min-height: 80px;
 }
 #whoisonline .items-user .toolbar .btn, #whoisonline .items-user .items-user-status{
   margin-bottom: 5px;

+ 4 - 7
main/inc/ajax/online.ajax.php

@@ -6,16 +6,13 @@ $action = $_GET['a'];
 
 switch ($action) {
     case 'load_online_user':
-        if (isset($_SESSION['who_is_online_counter'])) {
-            $_SESSION['who_is_online_counter']++;
-        } else {
-            $_SESSION['who_is_online_counter'] = 2;
-        }
-        $images_to_show = 9;
+
+        $images_to_show = MAX_ONLINE_USERS;
 
         $page = intval($_REQUEST['online_page_nr']);
         $max_page = ceil(who_is_online_count()/$images_to_show);
-        $page_rows = ($page-1)*9;
+
+        $page_rows = ($page - 1) * MAX_ONLINE_USERS;
 
         if (!empty($max_page) && $page <= $max_page) {
             if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {

+ 3 - 0
main/inc/lib/api.lib.php

@@ -606,6 +606,9 @@ define('RESOURCE_GRADEBOOK', 'gradebook');
 
 define('ADD_THEMATIC_PLAN', 6);
 
+// Max online users to show per page
+define('MAX_ONLINE_USERS', 8);
+
 // Make sure the CHAMILO_LOAD_WYSIWYG constant is defined
 // To remove CKeditor libs from HTML, set this constant to true before loading
 if (!defined('CHAMILO_LOAD_WYSIWYG')) {

+ 9 - 1
main/inc/lib/online.inc.php

@@ -205,9 +205,17 @@ function user_is_online($user_id)
     return false;
 
 }
+
 /**
  * Gives a list of people online now (and in the last $valid minutes)
- * @return  array       For each line, a list of user IDs and login dates, or FALSE on error or empty results
+ *
+ * @param $from
+ * @param $number_of_items
+ * @param null $column
+ * @param null $direction
+ * @param null $time_limit
+ * @param bool $friends
+ * @return  array|bool For each line, a list of user IDs and login dates, or FALSE on error or empty results
  */
 function who_is_online($from, $number_of_items, $column = null, $direction = null, $time_limit = null, $friends = false)
 {

+ 3 - 20
main/inc/lib/social.lib.php

@@ -1013,28 +1013,23 @@ class SocialManager extends UserManager
     public static function display_user_list($user_list, $wrap = true)
     {
         $html = null;
+
         if (isset($_GET['id']) or count($user_list) < 1) {
             return false;
         }
-        $column_size = '12';
-        $add_row = false;
-        if (api_is_anonymous()) {
-            $add_row = true;
-        }
+
         $course_url = '';
         if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
             $course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
         }
 
-        $html .= '<div class="row">';
-
         foreach ($user_list as $uid) {
             $user_info = api_get_user_info($uid, $checkIfUserOnline = true);
             $lastname = $user_info['lastname'];
             $firstname =  $user_info['firstname'];
             $completeName = $firstname.', '.$lastname;
 
-            $user_rol = $user_info['status'] == 1 ? Display::return_icon('teacher.png',get_lang('Teacher'),null,ICON_SIZE_TINY) : Display::return_icon('user.png',get_lang('Student'),null,ICON_SIZE_TINY);
+            $user_rol = $user_info['status'] == 1 ? Display::return_icon('teacher.png', get_lang('Teacher'), null, ICON_SIZE_TINY) : Display::return_icon('user.png', get_lang('Student'), null, ICON_SIZE_TINY);
             $status_icon_chat = null;
             if ($user_info['user_is_online_in_chat'] == 1) {
                 $status_icon_chat = Display::return_icon('online.png', get_lang('Online'));
@@ -1074,18 +1069,6 @@ class SocialManager extends UserManager
                       </div>';
 
         }
-        $counter = $_SESSION['who_is_online_counter'];
-
-        if ($wrap) {
-            $html .= '</div>';
-        }
-        if (count($user_list) >= 9) {
-            $html .= '<div class="col-md-'.$column_size.'">
-                        <a class="btn btn-large btn-default" id="link_load_more_items" data_link="'.$counter.'" >'.get_lang('More').'</a></div>';
-        }
-        if ($wrap && $add_row) {
-            $html .= '</div>';
-        }
 
         return $html;
     }

+ 12 - 8
main/template/default/social/whoisonline.tpl

@@ -14,7 +14,12 @@
                 </div>
             </div>
             <div id="whoisonline">
-                {{ whoisonline }}
+                <div id="user-list" class="row">
+                    {{ whoisonline }}
+                </div>
+                <div class="col-md-12">
+                    <a class="btn btn-large btn-default" id="link_load_more_items" data_link="2" >{{ 'More' | get_lang }}</a>
+                </div>
             </div>
         </div>
     </div>
@@ -23,18 +28,17 @@
             $("#link_load_more_items").click(function() {
                 page = $("#link_load_more_items").attr("data_link");
                 $.ajax({
-                    beforeSend: function(objeto) {
-                        $("#display_response_id").html("'.addslashes(get_lang('Loading')).'");
+                    beforeSend: function() {
+                        $("#link_load_more_items").html("{{ 'Loading' | get_lang }} <em class='fa fa-spinner fa-pulse fa-fw'></em>");
                     },
                     type: "GET",
                     url: "main/inc/ajax/online.ajax.php?a=load_online_user",
-                    data: "online_page_nr="+page,
+                    data: "online_page_nr=" + page,
                     success: function(data) {
-                        $("#display_response_id").html("");
                         if (data != "end") {
-                            $("#link_load_more_items").remove();
-                            var last = $("#online_grid_container li:last");
-                            last.after(data);
+                            $("#link_load_more_items").attr("data_link", parseInt(page) + 1);
+                            $("#user-list").append(data);
+                            $("#link_load_more_items").html("{{ 'More' | get_lang }}");
                         } else {
                             $("#link_load_more_items").remove();
                         }

+ 3 - 12
whoisonline.php

@@ -15,7 +15,6 @@ if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
     api_protect_course_script(true);
 }
 
-$_SESSION['who_is_online_counter'] = 2;
 $this_section = SECTION_SOCIAL;
 // table definitions
 
@@ -29,19 +28,11 @@ if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) ||
 ) {
 
     if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
-        $user_list = who_is_online_in_this_course(0, 9, api_get_user_id(), api_get_setting('time_limit_whosonline'), $_GET['cidReq']);
+        $user_list = who_is_online_in_this_course(0, MAX_ONLINE_USERS, api_get_user_id(), api_get_setting('time_limit_whosonline'), $_GET['cidReq']);
     } else {
-        $user_list = who_is_online(0, 9);
+        $user_list = who_is_online(0, MAX_ONLINE_USERS);
     }
-    /* if (!isset($_GET['id'])) {
-        if (api_get_setting('allow_social_tool') == 'true') {
-            if (!api_is_anonymous()) {
-                //this include the social menu div
-                $social_left_content = SocialManager::show_social_menu('whoisonline');
-            }
-        }
-    }
-*/
+
     if ($user_list) {
         if (!isset($_GET['id'])) {
             if (api_get_setting('allow_social_tool') == 'true') {