profile_friends_and_groups.inc.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Helper file for friends and groups profiles.
  5. *
  6. * @package chamilo.social
  7. *
  8. * @author Julio Montoya <gugli100@gmail.com>
  9. */
  10. $cidReset = true;
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. api_block_anonymous_users();
  13. if (api_get_setting('allow_social_tool') != 'true') {
  14. api_not_allowed();
  15. }
  16. $views = ['friends', 'mygroups'];
  17. $user_id = (int) $_GET['user_id'];
  18. $userGroup = new UserGroup();
  19. if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
  20. // show all friends by user_id
  21. if ($_GET['view'] == 'friends') {
  22. echo '<div style="margin-top:20px;">';
  23. $list_path_friends = $list_path_normal_friends = $list_path_parents = [];
  24. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, SOCIALPARENT
  25. $friends = SocialManager::get_friends(
  26. $user_id,
  27. USER_RELATION_TYPE_FRIEND
  28. );
  29. $number_friends = count($friends);
  30. $friend_html = '';
  31. $friend_html .= '<div><h3>'.get_lang('SocialFriend').'</h3></div>';
  32. $friend_html .= '<div id="friend-container" class="social-friend-container">';
  33. $friend_html .= '<div id="friend-header" >';
  34. if ($number_friends == 1) {
  35. $friend_html .= '<div style="float:left;width:80%">'.$number_friends.' '.get_lang('Friend').'</div>';
  36. } else {
  37. $friend_html .= '<div style="float:left;width:80%">'.$number_friends.' '.get_lang('Friends').'</div>';
  38. }
  39. $friend_html .= '</div>'; // close div friend-header
  40. for ($k = 0; $k < $number_friends; $k++) {
  41. if (isset($friends[$k])) {
  42. $friend = $friends[$k];
  43. $name_user = api_get_person_name(
  44. $friend['firstName'],
  45. $friend['lastName']
  46. );
  47. $friend_html .= '<div id=div_'.$friend['friend_user_id'].' class="image_friend_network" ><span><center>';
  48. $userPicture = UserManager::getUserPicture($friend['friend_user_id']);
  49. $friend_html .= '<a href="profile.php?u='.$friend['friend_user_id'].'">';
  50. $friend_html .= '<img src="'.$userPicture.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" />';
  51. $friend_html .= '</center></span>';
  52. $friend_html .= '<center class="friend">'.$name_user.'</a></center>';
  53. $friend_html .= '</div>';
  54. }
  55. }
  56. echo $friend_html;
  57. echo '</div>';
  58. } else {
  59. // show all groups by user_id
  60. // MY GROUPS
  61. $results = $userGroup->get_groups_by_user($user_id, 0);
  62. $grid_my_groups = [];
  63. if (is_array($results) && count($results) > 0) {
  64. $i = 1;
  65. foreach ($results as $result) {
  66. $id = $result['id'];
  67. $url_open = '<a href="group_view.php?id='.$id.'">';
  68. $url_close = '</a>';
  69. $icon = '';
  70. $name = cut($result['name'], 20, true);
  71. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  72. $icon = Display::return_icon(
  73. 'social_group_admin.png',
  74. get_lang('Admin'),
  75. ['style' => 'vertical-align:middle;width:16px;height:16px;']
  76. );
  77. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  78. $icon = Display::return_icon(
  79. 'social_group_moderator.png',
  80. get_lang('Moderator'),
  81. ['style' => 'vertical-align:middle;width:16px;height:16px;']
  82. );
  83. }
  84. $count_users_group = count(
  85. $userGroup->get_all_users_by_group($id)
  86. );
  87. if ($count_users_group == 1) {
  88. $count_users_group = $count_users_group.' '.get_lang('Member');
  89. } else {
  90. $count_users_group = $count_users_group.' '.get_lang('Members');
  91. }
  92. $picture = $userGroup->get_picture_group(
  93. $result['id'],
  94. $result['picture'],
  95. 80
  96. );
  97. $item_name = '<div class="box_shared_profile_group_title">'.$url_open.api_xml_http_response_encode($name).$icon.$url_close.'</div>';
  98. $item_description = '';
  99. if (!empty($result['description'])) {
  100. $item_description = '<div class="box_shared_profile_group_description">
  101. <span class="social-groups-text2">'.
  102. api_xml_http_response_encode(get_lang('Description')).'</span><p class="social-groups-text4">'.
  103. cut(api_xml_http_response_encode($result['description']), 120, true).'</p></div>';
  104. }
  105. $result['picture_uri'] = '<div class="box_shared_profile_group_image">
  106. <img class="social-groups-image" src="'.$picture['file'].'" /></div>';
  107. $item_actions = '';
  108. if (api_get_user_id() == $user_id) {
  109. $item_actions = '<div class="box_shared_profile_group_actions"><a href="group_view.php?id='.$id.'">'.
  110. get_lang('SeeMore').$url_close.'</div>';
  111. }
  112. $grid_my_groups[] = [
  113. $item_name,
  114. $url_open.$result['picture_uri'].$url_close,
  115. $item_description.$item_actions,
  116. ];
  117. $i++;
  118. }
  119. }
  120. if (count($grid_my_groups) > 0) {
  121. echo '<div style="margin-top:20px">';
  122. echo '<div><h3>'.get_lang('MyGroups').'</h3></div>';
  123. $count_groups = 0;
  124. if (count($results) == 1) {
  125. $count_groups = count($results).' '.get_lang('Group');
  126. } else {
  127. $count_groups = count($results).' '.get_lang('Groups');
  128. }
  129. echo '<div>'.$count_groups.'</div>';
  130. foreach ($grid_my_groups as $group) {
  131. echo Display::panel($group[0], $group[1]);
  132. }
  133. echo '</div>';
  134. }
  135. }
  136. }