groups.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. $cidReset = true;
  8. $language_file = array('userInfo');
  9. //require_once '../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. $join_url = '';
  12. if (api_get_setting('social.allow_social_tool') != 'true') {
  13. api_not_allowed();
  14. }
  15. $join_url = '';
  16. $this_section = SECTION_SOCIAL;
  17. $allowed_views = array('mygroups','newest','pop');
  18. $content = null;
  19. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  20. if ($_GET['view'] == 'mygroups') {
  21. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  22. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('MyGroups'));
  23. } else if ( $_GET['view'] == 'newest') {
  24. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  25. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Newest'));
  26. } else {
  27. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  28. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Popular'));
  29. }
  30. } else {
  31. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  32. if (!isset($_GET['id'])) {
  33. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('GroupList'));
  34. }
  35. }
  36. // getting group information
  37. $relation_group_title = '';
  38. $my_group_role = 0;
  39. $usergroup = new UserGroup();
  40. $create_thread_link = '';
  41. $show_menu = 'browse_groups';
  42. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  43. $show_menu = $_GET['view'];
  44. }
  45. $social_right_content = null;
  46. // My groups
  47. $results = $usergroup->get_groups_by_user(api_get_user_id(), 0);
  48. $grid_my_groups = array();
  49. $my_group_list = array();
  50. if (is_array($results) && count($results) > 0) {
  51. foreach ($results as $result) {
  52. $id = $result['id'];
  53. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  54. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  55. $my_group_list[] = $id;
  56. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  57. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  58. $name .= ' '.Display::return_icon('social_group_admin.png', get_lang('Admin'), array('style'=>'vertical-align:middle'));
  59. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  60. $name .= ' '.Display::return_icon('social_group_moderator.png', get_lang('Moderator'), array('style'=>'vertical-align:middle'));
  61. }
  62. $url = '<a href="group_view.php?id='.$id.'">' . $name . '</a>';
  63. $count_users_group = count($usergroup->get_users_by_group($id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000));
  64. if ($count_users_group == 1 ) {
  65. $count_users_group = $count_users_group.' '.get_lang('Member');
  66. } else {
  67. $count_users_group = $count_users_group.' '.get_lang('Members');
  68. }
  69. $picture = $usergroup->get_picture_group($result['id'], $result['picture'],80);
  70. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  71. $members = Display::returnFontAwesomeIcon('user').$count_users_group;
  72. $html = '<div class="row">';
  73. $html .= '<div class="col-md-2">';
  74. $html .= $result['picture'];
  75. $html .= '</div>';
  76. $html .= '<div class="col-md-10">';
  77. $html .= '<div class="title-groups">';
  78. $html .= Display::tag('h5', $url);
  79. $html .= '</div>';
  80. $html .= '<div class="members-groups">' . $members . '</div>';
  81. if ($result['description'] != '') {
  82. $html .= '<div class="description-groups">' . cut($result['description'],100,true) . '</div>';
  83. } else {
  84. $html .= '';
  85. }
  86. $html .= '</div>';
  87. $html .= '</div>';
  88. $grid_item_2 = $html;
  89. $grid_my_groups[]= array($grid_item_2);
  90. }
  91. }
  92. // Newest groups
  93. $results = $usergroup->get_groups_by_age(4,false);
  94. $grid_newest_groups = array();
  95. foreach ($results as $result) {
  96. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  97. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  98. $id = $result['id'];
  99. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  100. $count_users_group = count($usergroup->get_users_by_group($id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000));
  101. if ($count_users_group == 1 ) {
  102. $count_users_group = $count_users_group.' '.get_lang('Member');
  103. } else {
  104. $count_users_group = $count_users_group.' '.get_lang('Members');
  105. }
  106. $url = '<a href="group_view.php?id='.$id.'">' . $name . '</a>';
  107. $picture = $usergroup->get_picture_group($result['id'], $result['picture'],80);
  108. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  109. $members = Display::returnFontAwesomeIcon('user').$count_users_group;
  110. $html = '<div class="row">';
  111. $html .= '<div class="col-md-2">';
  112. $html .= $result['picture'];
  113. $html .= '</div>';
  114. $html .= '<div class="col-md-10">';
  115. $html .= '<div class="title-groups">';
  116. $html .= Display::tag('h5', $url);
  117. $html .= '</div>';
  118. $html .= '<div class="members-groups">' . $members . '</div>';
  119. if ($result['description'] != '') {
  120. $html .= '<div class="description-groups">' . cut($result['description'],100,true) . '</div>';
  121. } else {
  122. $html .= '';
  123. }
  124. //Avoiding my groups
  125. if (!in_array($id,$my_group_list)) {
  126. $html .= '<a class="btn" href="group_view.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  127. }
  128. $html .= '<div class="group-actions" >'.$join_url.'</div>';
  129. $html .= '</div>';
  130. $html .= '</div>';
  131. $grid_item_2 = $html;
  132. $grid_newest_groups[]= array($grid_item_2);
  133. }
  134. // Pop groups
  135. $results = $usergroup->get_groups_by_popularity(4,false);
  136. $grid_pop_groups = array();
  137. if (is_array($results) && count($results) > 0) {
  138. foreach ($results as $result) {
  139. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  140. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  141. $id = $result['id'];
  142. $name = cut($result['name'],GROUP_TITLE_LENGTH,true);
  143. $count_users_group = count($usergroup->get_users_by_group($id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000));
  144. if ($count_users_group == 1 ) {
  145. $count_users_group = $count_users_group.' '.get_lang('Member');
  146. } else {
  147. $count_users_group = $count_users_group.' '.get_lang('Members');
  148. }
  149. $url = '<a href="group_view.php?id='.$id.'">' . $name . '</a>';
  150. $picture = $usergroup->get_picture_group($result['id'], $result['picture'],80);
  151. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  152. $html = '<div class="row">';
  153. $html .= '<div class="col-md-2">';
  154. $html .= $result['picture'];
  155. $html .= '</div>';
  156. $html .= '<div class="col-md-10">';
  157. $html .= '<div class="title-groups">';
  158. $html .= Display::tag('h5', $url);
  159. $html .= '</div>';
  160. $html .= '<div class="members-groups">' . $members . '</div>';
  161. if ($result['description'] != '') {
  162. $html .= '<div class="description-groups">' . cut($result['description'],100,true) . '</div>';
  163. } else {
  164. $html .= '';
  165. }
  166. //Avoiding my groups
  167. if (!in_array($id,$my_group_list)) {
  168. $html .= '<a class="btn" href="group_view.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  169. }
  170. $html .= '<div class="group-actions" >'.$join_url.'</div>';
  171. $html .= '</div>';
  172. $html .= '</div>';
  173. $grid_item_2 = $html;
  174. $grid_pop_groups[]= array($grid_item_2);
  175. }
  176. }
  177. // Display groups (newest, mygroups, pop)
  178. $query_vars = array();
  179. $newest_content = $popular_content = $my_group_content = null;
  180. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  181. $view_group = $_GET['view'];
  182. switch ($view_group) {
  183. case 'mygroups':
  184. if (count($grid_my_groups) > 0) {
  185. $my_group_content = Display::return_sortable_grid('mygroups', array(), $grid_my_groups, array('hide_navigation'=>true, 'per_page' => 2), $query_vars, false, array(true, true, true,false));
  186. }
  187. if (api_get_setting(
  188. 'social.allow_students_to_create_groups_in_social'
  189. ) == 'true'
  190. ) {
  191. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  192. get_lang('CreateASocialGroup').'</a>';
  193. } else {
  194. if (api_is_allowed_to_edit(null,true)) {
  195. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  196. get_lang('CreateASocialGroup').'</a>';
  197. }
  198. }
  199. break;
  200. case 'newest':
  201. if (count($grid_newest_groups) > 0) {
  202. $newest_content = Display::return_sortable_grid('newest', array(), $grid_newest_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
  203. }
  204. break;
  205. default:
  206. if (count($grid_pop_groups) > 0) {
  207. $popular_content = Display::return_sortable_grid('popular', array(), $grid_pop_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,true,true));
  208. }
  209. break;
  210. }
  211. } else {
  212. $my_group_content = null;
  213. if (count($grid_my_groups) > 0) {
  214. $my_group_content = Display::return_sortable_grid('mygroups', array(), $grid_my_groups, array('hide_navigation'=>true, 'per_page' => 2), $query_vars, false, array(true, true, true,false));
  215. } else {
  216. $my_group_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  217. }
  218. if (api_get_setting(
  219. 'social.allow_students_to_create_groups_in_social'
  220. ) == 'true'
  221. ) {
  222. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  223. get_lang('CreateASocialGroup').'</a>';
  224. } else {
  225. if (api_is_allowed_to_edit(null,true)) {
  226. $create_group_item = '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  227. }
  228. }
  229. if (count($grid_newest_groups) > 0) {
  230. $newest_content = Display::return_sortable_grid('mygroups', array(), $grid_newest_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
  231. } else {
  232. $newest_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  233. }
  234. if (count($grid_pop_groups) > 0) {
  235. $popular_content = Display::return_sortable_grid('mygroups', array(), $grid_pop_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,true,true));
  236. } else {
  237. $popular_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  238. }
  239. }
  240. if (!empty($create_group_item)) {
  241. $social_right_content .= Display::page_subheader($create_group_item);
  242. }
  243. $headers = array(get_lang('Newest'), get_lang('Popular'), get_lang('MyGroups'));
  244. $social_right_content .= Display::tabs($headers, array($newest_content, $popular_content, $my_group_content),'tab_browse');
  245. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show_message' && isset($_REQUEST['msg']) && $_REQUEST['msg'] == 'topic_deleted') {
  246. Display::return_message(get_lang('Deleted'), 'success');
  247. }
  248. $tpl = \Chamilo\CoreBundle\Framework\Container::getTwig();
  249. // Block Social Avatar
  250. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), $show_menu);
  251. $show_menu = 'browse_groups';
  252. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  253. $show_menu = $_GET['view'];
  254. }
  255. $social_menu_block = SocialManager::show_social_menu($show_menu);
  256. //$tpl->setHelp('Groups');
  257. $tpl->addGlobal('social_menu_block', $social_menu_block);
  258. $tpl->addGlobal('social_right_content', $social_right_content);
  259. echo $tpl->render('@template_style/social/groups.html.twig');