Add social stats fixes #1693

pull/2487/head
jmontoyaa 9 years ago
parent 78502cded4
commit 66f79fdcef
  1. 20
      main/admin/user_information.php
  2. 58
      main/inc/lib/social.lib.php

@ -255,6 +255,7 @@ $tbl_session = Database:: get_main_table(TABLE_MAIN_SESSION);
$tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE);
$tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
$socialInformation = '';
/**
* Show social activity
@ -262,25 +263,32 @@ $tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
if (api_get_setting('allow_social_tool') === 'true') {
$em = Database::getManager();
$userObject = $em->find('ChamiloUserBundle:User', $user['user_id']);
$header = ['Value' => 'CurrentData'];
$data = [];
// Calculate values
if (api_get_setting('allow_message_tool') === 'true') {
$messagesSent = \SocialManager::getCountMessagesSent($user['user_id']);
$messagesSent = SocialManager::getCountMessagesSent($user['user_id']);
$data[] = [get_lang('MessagesSent'), $messagesSent];
$messagesReceived = \SocialManager::getCountMessagesReceived($user['user_id']);
$messagesReceived = SocialManager::getCountMessagesReceived($user['user_id']);
$data[] = [get_lang('MessagesReceived'), $messagesReceived];
}
$wallMessagesPosted = \SocialManager::getCountWallPostedMessages($user['user_id']);
$wallMessagesPosted = SocialManager::getCountWallPostedMessages($user['user_id']);
$data[] = [get_lang('WallMessagesPosted'), $wallMessagesPosted];
$friends = SocialManager::getCountFriends($user['user_id']);
$data[] = [get_lang('Friends'), $friends];
$count = SocialManager::getCountInvitationSent($user['user_id']);
$data[] = [get_lang('InvitationSent'), $count];
$count = SocialManager::get_message_number_invitation_by_user_id($user['user_id']);
$data[] = [get_lang('InvitationReceived'), $count];
$socialInformation = Display::return_sortable_table(
$header,
'',
$data
);
}
/**

@ -91,6 +91,35 @@ class SocialManager extends UserManager
}
}
/**
* Get count of friends from user
*
* @param int $userId
* @return int
*/
public static function getCountFriends($userId)
{
$tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
$userId = (int) $userId;
if (empty($userId)) {
return 0;
}
$sql = 'SELECT count(friend_user_id) count
FROM '.$tbl_my_friend.'
WHERE
relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND
friend_user_id<>'.($userId).' AND
user_id='.($userId);
$res = Database::query($sql);
if (Database::num_rows($res)) {
$row = Database::fetch_array($res, 'ASSOC');
return (int) $row['count'];
}
return 0;
}
/**
* Gets friends id list
* @param int user id
@ -350,7 +379,6 @@ class SocialManager extends UserManager
*/
public static function get_list_invitation_sent_by_user_id($user_id)
{
$list_friend_invitation = array();
$tbl_message = Database::get_main_table(TABLE_MESSAGE);
$sql = 'SELECT user_receiver_id, send_date,title,content
FROM '.$tbl_message.'
@ -358,11 +386,35 @@ class SocialManager extends UserManager
user_sender_id = '.intval($user_id).' AND
msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
$res = Database::query($sql);
$list = array();
while ($row = Database::fetch_array($res, 'ASSOC')) {
$list_friend_invitation[$row['user_receiver_id']] = $row;
$list[$row['user_receiver_id']] = $row;
}
return $list_friend_invitation;
return $list;
}
/**
* Get count invitation sent by user
* @author Julio Montoya <gugli100@gmail.com>
* @param int user id
* @return array()
*/
public static function getCountInvitationSent($user_id)
{
$tbl_message = Database::get_main_table(TABLE_MESSAGE);
$sql = 'SELECT count(user_receiver_id) count
FROM '.$tbl_message.'
WHERE
user_sender_id = '.intval($user_id).' AND
msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
$res = Database::query($sql);
if (Database::num_rows($res)) {
$row = Database::fetch_array($res, 'ASSOC');
return (int) $row['count'];
}
return 0;
}
/**

Loading…
Cancel
Save