groups.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. *
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (api_get_setting('allow_social_tool') !== 'true') {
  12. api_not_allowed();
  13. }
  14. $join_url = '';
  15. $this_section = SECTION_SOCIAL;
  16. $allowed_views = ['mygroups', 'newest', 'pop'];
  17. $content = null;
  18. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  19. if ($_GET['view'] === 'mygroups') {
  20. $interbreadcrumb[] = ['url' => 'groups.php', 'name' => get_lang('Groups')];
  21. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('MyGroups')];
  22. } elseif ($_GET['view'] === 'newest') {
  23. $interbreadcrumb[] = ['url' => 'groups.php', 'name' => get_lang('Groups')];
  24. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Newest')];
  25. } else {
  26. $interbreadcrumb[] = ['url' => 'groups.php', 'name' => get_lang('Groups')];
  27. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Popular')];
  28. }
  29. } else {
  30. $interbreadcrumb[] = ['url' => 'groups.php', 'name' => get_lang('Groups')];
  31. if (!isset($_GET['id'])) {
  32. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('GroupList')];
  33. }
  34. }
  35. // getting group information
  36. $relation_group_title = '';
  37. $my_group_role = 0;
  38. $usergroup = new UserGroup();
  39. $create_thread_link = '';
  40. $show_menu = 'browse_groups';
  41. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  42. $show_menu = $_GET['view'];
  43. }
  44. $social_right_content = null;
  45. // My groups
  46. $results = $usergroup->get_groups_by_user(api_get_user_id(), 0);
  47. $grid_my_groups = [];
  48. $my_group_list = [];
  49. if (is_array($results) && count($results) > 0) {
  50. foreach ($results as $result) {
  51. $id = $result['id'];
  52. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  53. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  54. $my_group_list[] = $id;
  55. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  56. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  57. $name .= ' '.Display::return_icon(
  58. 'social_group_admin.png',
  59. get_lang('Admin'),
  60. ['style' => 'vertical-align:middle']
  61. );
  62. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  63. $name .= ' '.Display::return_icon(
  64. 'social_group_moderator.png',
  65. get_lang('Moderator'),
  66. ['style' => 'vertical-align:middle']
  67. );
  68. }
  69. $url = '<a href="group_view.php?id='.$id.'">'.$name.'</a>';
  70. $count_users_group = count(
  71. $usergroup->get_users_by_group(
  72. $id,
  73. false,
  74. [
  75. GROUP_USER_PERMISSION_ADMIN,
  76. GROUP_USER_PERMISSION_READER,
  77. GROUP_USER_PERMISSION_MODERATOR,
  78. ],
  79. 0,
  80. 1000
  81. )
  82. );
  83. if ($count_users_group == 1) {
  84. $count_users_group = $count_users_group.' '.get_lang('Member');
  85. } else {
  86. $count_users_group = $count_users_group.' '.get_lang('Members');
  87. }
  88. $picture = $usergroup->get_picture_group(
  89. $result['id'],
  90. $result['picture'],
  91. 80
  92. );
  93. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  94. $members = Display::returnFontAwesomeIcon('user').$count_users_group;
  95. $html = '<div class="row">';
  96. $html .= '<div class="col-md-2">';
  97. $html .= $result['picture'];
  98. $html .= '</div>';
  99. $html .= '<div class="col-md-10">';
  100. $html .= '<div class="title-groups">';
  101. $html .= Display::tag('h5', $url);
  102. $html .= '</div>';
  103. $html .= '<div class="members-groups">'.$members.'</div>';
  104. if ($result['description'] != '') {
  105. $html .= '<div class="description-groups">'.cut($result['description'], 100, true).'</div>';
  106. } else {
  107. $html .= '';
  108. }
  109. $html .= '</div>';
  110. $html .= '</div>';
  111. $grid_item_2 = $html;
  112. $grid_my_groups[] = [$grid_item_2];
  113. }
  114. }
  115. // Newest groups
  116. $results = $usergroup->get_groups_by_age(4, false);
  117. $grid_newest_groups = [];
  118. foreach ($results as $result) {
  119. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  120. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  121. $id = $result['id'];
  122. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  123. $count_users_group = count(
  124. $usergroup->get_users_by_group(
  125. $id,
  126. false,
  127. [GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR],
  128. 0,
  129. 1000
  130. )
  131. );
  132. if ($count_users_group == 1) {
  133. $count_users_group = $count_users_group.' '.get_lang('Member');
  134. } else {
  135. $count_users_group = $count_users_group.' '.get_lang('Members');
  136. }
  137. $url = '<a href="group_view.php?id='.$id.'">'.$name.'</a>';
  138. $picture = $usergroup->get_picture_group($result['id'], $result['picture'], 80);
  139. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  140. $members = Display::returnFontAwesomeIcon('user').$count_users_group;
  141. $html = '<div class="row">';
  142. $html .= '<div class="col-md-2">';
  143. $html .= $result['picture'];
  144. $html .= '</div>';
  145. $html .= '<div class="col-md-10">';
  146. $html .= '<div class="title-groups">';
  147. $html .= Display::tag('h5', $url);
  148. $html .= '</div>';
  149. $html .= '<div class="members-groups">'.$members.'</div>';
  150. if ($result['description'] != '') {
  151. $html .= '<div class="description-groups">'.cut($result['description'], 100, true).'</div>';
  152. }
  153. // Avoiding my groups
  154. if (!in_array($id, $my_group_list)) {
  155. $html .= '<a class="btn btn-primary" href="group_view.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.
  156. get_lang('JoinGroup').'</a> ';
  157. }
  158. $html .= '<div class="group-actions" >'.$join_url.'</div>';
  159. $html .= '</div>';
  160. $html .= '</div>';
  161. $grid_item_2 = $html;
  162. $grid_newest_groups[] = [$grid_item_2];
  163. }
  164. // Pop groups
  165. $results = $usergroup->get_groups_by_popularity(4, false);
  166. $grid_pop_groups = [];
  167. if (is_array($results) && count($results) > 0) {
  168. foreach ($results as $result) {
  169. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  170. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  171. $id = $result['id'];
  172. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  173. $count_users_group = count(
  174. $usergroup->get_users_by_group(
  175. $id,
  176. false,
  177. [
  178. GROUP_USER_PERMISSION_ADMIN,
  179. GROUP_USER_PERMISSION_READER,
  180. GROUP_USER_PERMISSION_MODERATOR,
  181. ],
  182. 0,
  183. 1000
  184. )
  185. );
  186. if ($count_users_group == 1) {
  187. $count_users_group = $count_users_group.' '.get_lang('Member');
  188. } else {
  189. $count_users_group = $count_users_group.' '.get_lang('Members');
  190. }
  191. $url = '<a href="group_view.php?id='.$id.'">'.$name.'</a>';
  192. $picture = $usergroup->get_picture_group($result['id'], $result['picture'], 80);
  193. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  194. $html = '<div class="row">';
  195. $html .= '<div class="col-md-2">';
  196. $html .= $result['picture'];
  197. $html .= '</div>';
  198. $html .= '<div class="col-md-10">';
  199. $html .= '<div class="title-groups">';
  200. $html .= Display::tag('h5', $url);
  201. $html .= '</div>';
  202. $html .= '<div class="members-groups">'.$members.'</div>';
  203. if ($result['description'] != '') {
  204. $html .= '<div class="description-groups">'.cut($result['description'], 100, true).'</div>';
  205. } else {
  206. $html .= '';
  207. }
  208. // Avoiding my groups
  209. if (!in_array($id, $my_group_list)) {
  210. $html .= '<a class="btn btn-primary" href="group_view.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.
  211. get_lang('JoinGroup').'</a> ';
  212. }
  213. $html .= '<div class="group-actions" >'.$join_url.'</div>';
  214. $html .= '</div>';
  215. $html .= '</div>';
  216. $grid_item_2 = $html;
  217. $grid_pop_groups[] = [$grid_item_2];
  218. }
  219. }
  220. // Display groups (newest, mygroups, pop)
  221. $query_vars = [];
  222. $newest_content = $popular_content = $my_group_content = null;
  223. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  224. $view_group = $_GET['view'];
  225. switch ($view_group) {
  226. case 'mygroups':
  227. if (count($grid_my_groups) > 0) {
  228. $my_group_content = Display::return_sortable_grid(
  229. 'mygroups',
  230. [],
  231. $grid_my_groups,
  232. ['hide_navigation' => true, 'per_page' => 2],
  233. $query_vars,
  234. false,
  235. [true, true, true, false]
  236. );
  237. }
  238. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  239. $create_group_item =
  240. '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  241. get_lang('CreateASocialGroup').'</a>';
  242. } else {
  243. if (api_is_allowed_to_edit(null, true)) {
  244. $create_group_item =
  245. '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  246. get_lang('CreateASocialGroup').'</a>';
  247. }
  248. }
  249. break;
  250. case 'newest':
  251. if (count($grid_newest_groups) > 0) {
  252. $newest_content = Display::return_sortable_grid(
  253. 'newest',
  254. [],
  255. $grid_newest_groups,
  256. ['hide_navigation' => true, 'per_page' => 100],
  257. $query_vars,
  258. false,
  259. [true, true, true, false]
  260. );
  261. }
  262. break;
  263. default:
  264. if (count($grid_pop_groups) > 0) {
  265. $popular_content = Display::return_sortable_grid(
  266. 'popular',
  267. [],
  268. $grid_pop_groups,
  269. ['hide_navigation' => true, 'per_page' => 100],
  270. $query_vars,
  271. false,
  272. [true, true, true, true, true]
  273. );
  274. }
  275. break;
  276. }
  277. } else {
  278. $my_group_content = null;
  279. if (count($grid_my_groups) > 0) {
  280. $my_group_content = Display::return_sortable_grid(
  281. 'mygroups',
  282. [],
  283. $grid_my_groups,
  284. ['hide_navigation' => true, 'per_page' => 2],
  285. $query_vars,
  286. false,
  287. [true, true, true, false]
  288. );
  289. } else {
  290. $my_group_content = '<span class="muted">'.get_lang('GroupNone').'</span>';
  291. }
  292. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  293. $create_group_item =
  294. '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  295. get_lang('CreateASocialGroup').'</a>';
  296. } else {
  297. if (api_is_allowed_to_edit(null, true)) {
  298. $create_group_item =
  299. '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.
  300. get_lang('CreateASocialGroup').'</a>';
  301. }
  302. }
  303. if (count($grid_newest_groups) > 0) {
  304. $newest_content = Display::return_sortable_grid(
  305. 'mygroups',
  306. [],
  307. $grid_newest_groups,
  308. ['hide_navigation' => true, 'per_page' => 100],
  309. $query_vars,
  310. false,
  311. [true, true, true, false]
  312. );
  313. } else {
  314. $newest_content = '<div class="muted">'.get_lang('GroupNone').'</div>';
  315. }
  316. if (count($grid_pop_groups) > 0) {
  317. $popular_content = Display::return_sortable_grid(
  318. 'mygroups',
  319. [],
  320. $grid_pop_groups,
  321. ['hide_navigation' => true, 'per_page' => 100],
  322. $query_vars,
  323. false,
  324. [true, true, true, true, true]
  325. );
  326. } else {
  327. $popular_content = '<div class="muted">'.get_lang('GroupNone').'</div>';
  328. }
  329. }
  330. if (!empty($create_group_item)) {
  331. $social_right_content .= Display::page_subheader($create_group_item);
  332. }
  333. $headers = [get_lang('Newest'), get_lang('Popular'), get_lang('MyGroups')];
  334. $social_right_content .= Display::tabs(
  335. $headers,
  336. [$newest_content, $popular_content, $my_group_content],
  337. 'tab_browse'
  338. );
  339. $tpl = new Template(null);
  340. // Block Social Avatar
  341. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), $show_menu);
  342. $show_menu = 'browse_groups';
  343. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  344. $show_menu = $_GET['view'];
  345. }
  346. $social_menu_block = SocialManager::show_social_menu($show_menu);
  347. $templateName = 'social/groups.tpl';
  348. $tpl->setHelp('Groups');
  349. $tpl->assign('social_menu_block', $social_menu_block);
  350. $tpl->assign('social_right_content', $social_right_content);
  351. $social_layout = $tpl->get_template($templateName);
  352. $tpl->display($social_layout);