| Total Complexity | 225 |
| Total Lines | 2031 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
Complex classes like SocialManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SocialManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class SocialManager extends UserManager |
||
| 22 | { |
||
| 23 | const DEFAULT_WALL_POSTS = 10; |
||
| 24 | const DEFAULT_SCROLL_NEW_POST = 5; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Constructor. |
||
| 28 | */ |
||
| 29 | public function __construct() |
||
| 30 | { |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Allow to see contacts list. |
||
| 35 | * |
||
| 36 | * @author isaac flores paz |
||
| 37 | * |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | public static function show_list_type_friends() |
||
| 41 | { |
||
| 42 | $table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); |
||
| 43 | $sql = 'SELECT id, title FROM '.$table.' |
||
| 44 | WHERE id<>6 |
||
| 45 | ORDER BY id ASC'; |
||
| 46 | $result = Database::query($sql); |
||
| 47 | $friend_relation_list = []; |
||
| 48 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
||
| 49 | $friend_relation_list[] = $row; |
||
| 50 | } |
||
| 51 | $count_list = count($friend_relation_list); |
||
| 52 | if (0 == $count_list) { |
||
| 53 | $friend_relation_list[] = get_lang('Unknown'); |
||
| 54 | } else { |
||
| 55 | return $friend_relation_list; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Get the kind of relation between contacts. |
||
| 61 | * |
||
| 62 | * @param int $user_id user id |
||
| 63 | * @param int $user_friend user friend id |
||
| 64 | * @param bool $includeRH include the RH relationship |
||
| 65 | * |
||
| 66 | * @return int |
||
| 67 | * |
||
| 68 | * @author isaac flores paz |
||
| 69 | */ |
||
| 70 | public static function get_relation_between_contacts($user_id, $user_friend, $includeRH = false) |
||
| 71 | { |
||
| 72 | $table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); |
||
| 73 | $userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 74 | if (false == $includeRH) { |
||
|
|
|||
| 75 | $sql = 'SELECT rt.id as id |
||
| 76 | FROM '.$table.' rt |
||
| 77 | WHERE rt.id = ( |
||
| 78 | SELECT uf.relation_type |
||
| 79 | FROM '.$userRelUserTable.' uf |
||
| 80 | WHERE |
||
| 81 | user_id='.((int) $user_id).' AND |
||
| 82 | friend_user_id='.((int) $user_friend).' AND |
||
| 83 | uf.relation_type <> '.UserRelUser::USER_RELATION_TYPE_RRHH.' |
||
| 84 | LIMIT 1 |
||
| 85 | )'; |
||
| 86 | } else { |
||
| 87 | $sql = 'SELECT rt.id as id |
||
| 88 | FROM '.$table.' rt |
||
| 89 | WHERE rt.id = ( |
||
| 90 | SELECT uf.relation_type |
||
| 91 | FROM '.$userRelUserTable.' uf |
||
| 92 | WHERE |
||
| 93 | user_id='.((int) $user_id).' AND |
||
| 94 | friend_user_id='.((int) $user_friend).' |
||
| 95 | LIMIT 1 |
||
| 96 | )'; |
||
| 97 | } |
||
| 98 | $res = Database::query($sql); |
||
| 99 | if (Database::num_rows($res) > 0) { |
||
| 100 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 101 | |||
| 102 | return (int) $row['id']; |
||
| 103 | } else { |
||
| 104 | if (api_get_configuration_value('social_make_teachers_friend_all')) { |
||
| 105 | $adminsList = UserManager::get_all_administrators(); |
||
| 106 | foreach ($adminsList as $admin) { |
||
| 107 | if (api_get_user_id() == $admin['user_id']) { |
||
| 108 | return UserRelUser::USER_RELATION_TYPE_GOODFRIEND; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | $targetUserCoursesList = CourseManager::get_courses_list_by_user_id( |
||
| 112 | $user_id, |
||
| 113 | true, |
||
| 114 | false |
||
| 115 | ); |
||
| 116 | $currentUserId = api_get_user_id(); |
||
| 117 | foreach ($targetUserCoursesList as $course) { |
||
| 118 | $teachersList = CourseManager::get_teacher_list_from_course_code($course['code']); |
||
| 119 | foreach ($teachersList as $teacher) { |
||
| 120 | if ($currentUserId == $teacher['user_id']) { |
||
| 121 | return UserRelUser::USER_RELATION_TYPE_GOODFRIEND; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } else { |
||
| 126 | return UserRelUser::USER_UNKNOWN; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Gets friends id list. |
||
| 133 | * |
||
| 134 | * @param int user id |
||
| 135 | * @param int group id |
||
| 136 | * @param string name to search |
||
| 137 | * @param bool true will load firstname, lastname, and image name |
||
| 138 | * |
||
| 139 | * @return array |
||
| 140 | * |
||
| 141 | * @author Julio Montoya <[email protected]> Cleaning code, function renamed, $load_extra_info option added |
||
| 142 | * @author isaac flores paz |
||
| 143 | */ |
||
| 144 | public static function get_friends( |
||
| 145 | $user_id, |
||
| 146 | $id_group = null, |
||
| 147 | $search_name = null, |
||
| 148 | $load_extra_info = true |
||
| 149 | ) { |
||
| 150 | $user_id = (int) $user_id; |
||
| 151 | |||
| 152 | $tbl_my_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 153 | $tbl_my_user = Database::get_main_table(TABLE_MAIN_USER); |
||
| 154 | $sql = 'SELECT friend_user_id FROM '.$tbl_my_friend.' |
||
| 155 | WHERE |
||
| 156 | relation_type NOT IN ('.UserRelUser::USER_RELATION_TYPE_DELETED.', '.UserRelUser::USER_RELATION_TYPE_RRHH.') AND |
||
| 157 | friend_user_id<>'.$user_id.' AND |
||
| 158 | user_id='.$user_id; |
||
| 159 | if (isset($id_group) && $id_group > 0) { |
||
| 160 | $sql .= ' AND relation_type='.$id_group; |
||
| 161 | } |
||
| 162 | if (isset($search_name)) { |
||
| 163 | $search_name = trim($search_name); |
||
| 164 | $search_name = str_replace(' ', '', $search_name); |
||
| 165 | $sql .= ' AND friend_user_id IN ( |
||
| 166 | SELECT user_id FROM '.$tbl_my_user.' |
||
| 167 | WHERE |
||
| 168 | firstName LIKE "%'.Database::escape_string($search_name).'%" OR |
||
| 169 | lastName LIKE "%'.Database::escape_string($search_name).'%" OR |
||
| 170 | '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' LIKE concat("%","'.Database::escape_string($search_name).'","%") |
||
| 171 | ) '; |
||
| 172 | } |
||
| 173 | |||
| 174 | $res = Database::query($sql); |
||
| 175 | $list = []; |
||
| 176 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 177 | if ($load_extra_info) { |
||
| 178 | $userInfo = api_get_user_info($row['friend_user_id']); |
||
| 179 | $list[] = [ |
||
| 180 | 'friend_user_id' => $row['friend_user_id'], |
||
| 181 | 'firstName' => $userInfo['firstName'], |
||
| 182 | 'lastName' => $userInfo['lastName'], |
||
| 183 | 'username' => $userInfo['username'], |
||
| 184 | 'image' => $userInfo['avatar'], |
||
| 185 | 'user_info' => $userInfo, |
||
| 186 | ]; |
||
| 187 | } else { |
||
| 188 | $list[] = $row; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | return $list; |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Get number of messages sent to other users. |
||
| 197 | * |
||
| 198 | * @param int $userId |
||
| 199 | * |
||
| 200 | * @return int |
||
| 201 | */ |
||
| 202 | public static function getCountMessagesSent($userId) |
||
| 203 | { |
||
| 204 | $userId = (int) $userId; |
||
| 205 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 206 | $sql = 'SELECT COUNT(*) FROM '.$table.' |
||
| 207 | WHERE |
||
| 208 | user_sender_id='.$userId.' AND |
||
| 209 | msg_status < 5'; |
||
| 210 | $res = Database::query($sql); |
||
| 211 | $row = Database::fetch_row($res); |
||
| 212 | |||
| 213 | return $row[0]; |
||
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Get number of messages received from other users. |
||
| 218 | * |
||
| 219 | * @param int $receiver_id |
||
| 220 | * |
||
| 221 | * @return int |
||
| 222 | */ |
||
| 223 | public static function getCountMessagesReceived($receiver_id) |
||
| 224 | { |
||
| 225 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 226 | $sql = 'SELECT COUNT(*) FROM '.$table.' |
||
| 227 | WHERE |
||
| 228 | user_receiver_id='.intval($receiver_id).' AND |
||
| 229 | msg_status < 4'; |
||
| 230 | $res = Database::query($sql); |
||
| 231 | $row = Database::fetch_row($res); |
||
| 232 | |||
| 233 | return $row[0]; |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Get number of messages posted on own wall. |
||
| 238 | * |
||
| 239 | * @param int $userId |
||
| 240 | * |
||
| 241 | * @return int |
||
| 242 | */ |
||
| 243 | public static function getCountWallPostedMessages($userId) |
||
| 244 | { |
||
| 245 | $userId = (int) $userId; |
||
| 246 | |||
| 247 | if (empty($userId)) { |
||
| 248 | return 0; |
||
| 249 | } |
||
| 250 | |||
| 251 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 252 | $sql = 'SELECT COUNT(*) |
||
| 253 | FROM '.$table.' |
||
| 254 | WHERE |
||
| 255 | user_sender_id='.$userId.' AND |
||
| 256 | (msg_status = '.MESSAGE_STATUS_WALL.' OR |
||
| 257 | msg_status = '.MESSAGE_STATUS_WALL_POST.') AND |
||
| 258 | parent_id = 0'; |
||
| 259 | $res = Database::query($sql); |
||
| 260 | $row = Database::fetch_row($res); |
||
| 261 | |||
| 262 | return $row[0]; |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Get invitation list received by user. |
||
| 267 | * |
||
| 268 | * @author isaac flores paz |
||
| 269 | * |
||
| 270 | * @param int $userId |
||
| 271 | * @param int $limit |
||
| 272 | * |
||
| 273 | * @return array |
||
| 274 | */ |
||
| 275 | public static function get_list_invitation_of_friends_by_user_id($userId, $limit = 0) |
||
| 276 | { |
||
| 277 | $userId = (int) $userId; |
||
| 278 | $limit = (int) $limit; |
||
| 279 | |||
| 280 | if (empty($userId)) { |
||
| 281 | return []; |
||
| 282 | } |
||
| 283 | |||
| 284 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 285 | $sql = 'SELECT user_sender_id, send_date, title, content |
||
| 286 | FROM '.$table.' |
||
| 287 | WHERE |
||
| 288 | user_receiver_id = '.$userId.' AND |
||
| 289 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 290 | if (null != $limit && $limit > 0) { |
||
| 291 | $sql .= ' LIMIT '.$limit; |
||
| 292 | } |
||
| 293 | $res = Database::query($sql); |
||
| 294 | $list = []; |
||
| 295 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 296 | $list[] = $row; |
||
| 297 | } |
||
| 298 | |||
| 299 | return $list; |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Get invitation list sent by user. |
||
| 304 | * |
||
| 305 | * @author Julio Montoya <[email protected]> |
||
| 306 | * |
||
| 307 | * @param int $userId |
||
| 308 | * |
||
| 309 | * @return array |
||
| 310 | */ |
||
| 311 | public static function get_list_invitation_sent_by_user_id($userId) |
||
| 312 | { |
||
| 313 | $userId = (int) $userId; |
||
| 314 | |||
| 315 | if (empty($userId)) { |
||
| 316 | return []; |
||
| 317 | } |
||
| 318 | |||
| 319 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 320 | $sql = 'SELECT user_receiver_id, send_date,title,content |
||
| 321 | FROM '.$table.' |
||
| 322 | WHERE |
||
| 323 | user_sender_id = '.$userId.' AND |
||
| 324 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 325 | $res = Database::query($sql); |
||
| 326 | $list = []; |
||
| 327 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 328 | $list[$row['user_receiver_id']] = $row; |
||
| 329 | } |
||
| 330 | |||
| 331 | return $list; |
||
| 332 | } |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Get count invitation sent by user. |
||
| 336 | * |
||
| 337 | * @author Julio Montoya <[email protected]> |
||
| 338 | * |
||
| 339 | * @param int $userId |
||
| 340 | * |
||
| 341 | * @return int |
||
| 342 | */ |
||
| 343 | public static function getCountInvitationSent($userId) |
||
| 344 | { |
||
| 345 | $userId = (int) $userId; |
||
| 346 | |||
| 347 | if (empty($userId)) { |
||
| 348 | return 0; |
||
| 349 | } |
||
| 350 | |||
| 351 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 352 | $sql = 'SELECT count(user_receiver_id) count |
||
| 353 | FROM '.$table.' |
||
| 354 | WHERE |
||
| 355 | user_sender_id = '.$userId.' AND |
||
| 356 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 357 | $res = Database::query($sql); |
||
| 358 | if (Database::num_rows($res)) { |
||
| 359 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 360 | |||
| 361 | return (int) $row['count']; |
||
| 362 | } |
||
| 363 | |||
| 364 | return 0; |
||
| 365 | } |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Accepts invitation. |
||
| 369 | * |
||
| 370 | * @param int $user_send_id |
||
| 371 | * @param int $user_receiver_id |
||
| 372 | * |
||
| 373 | * @return bool |
||
| 374 | * |
||
| 375 | * @author isaac flores paz |
||
| 376 | * @author Julio Montoya <[email protected]> Cleaning code |
||
| 377 | */ |
||
| 378 | public static function invitation_accepted($user_send_id, $user_receiver_id) |
||
| 379 | { |
||
| 380 | if (empty($user_send_id) || empty($user_receiver_id)) { |
||
| 381 | return false; |
||
| 382 | } |
||
| 383 | |||
| 384 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 385 | $sql = "UPDATE $table |
||
| 386 | SET msg_status = ".MESSAGE_STATUS_INVITATION_ACCEPTED." |
||
| 387 | WHERE |
||
| 388 | user_sender_id = ".((int) $user_send_id)." AND |
||
| 389 | user_receiver_id=".((int) $user_receiver_id)." AND |
||
| 390 | msg_status = ".MESSAGE_STATUS_INVITATION_PENDING; |
||
| 391 | Database::query($sql); |
||
| 392 | |||
| 393 | return true; |
||
| 394 | } |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Denies invitation. |
||
| 398 | * |
||
| 399 | * @param int user sender id |
||
| 400 | * @param int user receiver id |
||
| 401 | * |
||
| 402 | * @return bool |
||
| 403 | * |
||
| 404 | * @author isaac flores paz |
||
| 405 | * @author Julio Montoya <[email protected]> Cleaning code |
||
| 406 | */ |
||
| 407 | public static function invitation_denied($user_send_id, $user_receiver_id) |
||
| 408 | { |
||
| 409 | if (empty($user_send_id) || empty($user_receiver_id)) { |
||
| 410 | return false; |
||
| 411 | } |
||
| 412 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 413 | $sql = 'DELETE FROM '.$table.' |
||
| 414 | WHERE |
||
| 415 | user_sender_id = '.((int) $user_send_id).' AND |
||
| 416 | user_receiver_id='.((int) $user_receiver_id).' AND |
||
| 417 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 418 | Database::query($sql); |
||
| 419 | |||
| 420 | return true; |
||
| 421 | } |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Get user's feeds. |
||
| 425 | * |
||
| 426 | * @param int $user User ID |
||
| 427 | * @param int $limit Limit of posts per feed |
||
| 428 | * |
||
| 429 | * @return string HTML section with all feeds included |
||
| 430 | * |
||
| 431 | * @author Yannick Warnier |
||
| 432 | * |
||
| 433 | * @since Dokeos 1.8.6.1 |
||
| 434 | */ |
||
| 435 | public static function getUserRssFeed($user, $limit = 5) |
||
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Shows the avatar block in social pages. |
||
| 488 | * |
||
| 489 | * @param string $show highlight link possible values: |
||
| 490 | * group_add, |
||
| 491 | * home, |
||
| 492 | * messages, |
||
| 493 | * messages_inbox, |
||
| 494 | * messages_compose, |
||
| 495 | * messages_outbox, |
||
| 496 | * invitations, |
||
| 497 | * shared_profile, |
||
| 498 | * friends, |
||
| 499 | * groups search |
||
| 500 | * @param int $group_id |
||
| 501 | * @param int $user_id |
||
| 502 | */ |
||
| 503 | public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0) |
||
| 566 | } |
||
| 567 | |||
| 568 | /** |
||
| 569 | * Displays a sortable table with the list of online users. |
||
| 570 | * |
||
| 571 | * @param array $user_list The list of users to be shown |
||
| 572 | * @param bool $wrap Whether we want the function to wrap the spans list in a div or not |
||
| 573 | * |
||
| 574 | * @return string HTML block or null if and ID was defined |
||
| 575 | * @assert (null) === false |
||
| 576 | */ |
||
| 577 | public static function display_user_list($user_list, $wrap = true) |
||
| 578 | { |
||
| 579 | $html = ''; |
||
| 580 | |||
| 581 | if (isset($_GET['id']) || count($user_list) < 1) { |
||
| 582 | return false; |
||
| 583 | } |
||
| 584 | |||
| 585 | $course_url = ''; |
||
| 586 | if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) { |
||
| 587 | $course_url = '&cidReq='.Security::remove_XSS($_GET['cidReq']); |
||
| 588 | } |
||
| 589 | |||
| 590 | $hide = api_get_configuration_value('hide_complete_name_in_whoisonline'); |
||
| 591 | foreach ($user_list as $uid) { |
||
| 592 | $user_info = api_get_user_info($uid, true); |
||
| 593 | $lastname = $user_info['lastname']; |
||
| 594 | $firstname = $user_info['firstname']; |
||
| 595 | $completeName = $firstname.', '.$lastname; |
||
| 596 | $user_rol = 1 == $user_info['status'] ? Display::return_icon('teacher.png', get_lang('Trainer'), null, ICON_SIZE_TINY) : Display::return_icon('user.png', get_lang('Learner'), null, ICON_SIZE_TINY); |
||
| 597 | $status_icon_chat = null; |
||
| 598 | if (isset($user_info['user_is_online_in_chat']) && 1 == $user_info['user_is_online_in_chat']) { |
||
| 599 | $status_icon_chat = Display::return_icon('online.png', get_lang('Online')); |
||
| 600 | } else { |
||
| 601 | $status_icon_chat = Display::return_icon('offline.png', get_lang('Offline')); |
||
| 602 | } |
||
| 603 | |||
| 604 | $userPicture = $user_info['avatar']; |
||
| 605 | $officialCode = ''; |
||
| 606 | if ('true' === api_get_setting('show_official_code_whoisonline')) { |
||
| 607 | $officialCode .= '<div class="items-user-official-code"> |
||
| 608 | <p style="min-height: 30px;" title="'.get_lang('Code').'">'.$user_info['official_code'].'</p></div>'; |
||
| 609 | } |
||
| 610 | |||
| 611 | if (true === $hide) { |
||
| 612 | $completeName = ''; |
||
| 613 | $firstname = ''; |
||
| 614 | $lastname = ''; |
||
| 615 | } |
||
| 616 | |||
| 617 | $img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">'; |
||
| 618 | |||
| 619 | $url = null; |
||
| 620 | // Anonymous users can't have access to the profile |
||
| 621 | if (!api_is_anonymous()) { |
||
| 622 | if ('true' === api_get_setting('allow_social_tool')) { |
||
| 623 | $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url; |
||
| 624 | } else { |
||
| 625 | $url = '?id='.$uid.$course_url; |
||
| 626 | } |
||
| 627 | } else { |
||
| 628 | $url = null; |
||
| 629 | } |
||
| 630 | $name = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>'; |
||
| 631 | |||
| 632 | $html .= '<div class="col-xs-6 col-md-2"> |
||
| 633 | <div class="items-user"> |
||
| 634 | <div class="items-user-avatar"><a href="'.$url.'">'.$img.'</a></div> |
||
| 635 | <div class="items-user-name"> |
||
| 636 | '.$name.' |
||
| 637 | </div> |
||
| 638 | '.$officialCode.' |
||
| 639 | <div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div> |
||
| 640 | </div> |
||
| 641 | </div>'; |
||
| 642 | } |
||
| 643 | |||
| 644 | return $html; |
||
| 645 | } |
||
| 646 | |||
| 647 | /** |
||
| 648 | * @param string $content |
||
| 649 | * @param string $span_count |
||
| 650 | * |
||
| 651 | * @return string |
||
| 652 | */ |
||
| 653 | public static function social_wrapper_div($content, $span_count) |
||
| 654 | { |
||
| 655 | $span_count = (int) $span_count; |
||
| 656 | $html = '<div class="span'.$span_count.'">'; |
||
| 657 | $html .= '<div class="well_border">'; |
||
| 658 | $html .= $content; |
||
| 659 | $html .= '</div></div>'; |
||
| 660 | |||
| 661 | return $html; |
||
| 662 | } |
||
| 663 | |||
| 664 | /** |
||
| 665 | * Dummy function. |
||
| 666 | */ |
||
| 667 | public static function get_plugins($place = SOCIAL_CENTER_PLUGIN) |
||
| 690 | } |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Gets all messages from someone's wall (within specific limits). |
||
| 694 | * |
||
| 695 | * @param int $userId id of wall shown |
||
| 696 | * @param int|string $parentId id message (Post main) |
||
| 697 | * @param int|array $groupId |
||
| 698 | * @param int|array $friendId |
||
| 699 | * @param string $startDate Date from which we want to show the messages, in UTC time |
||
| 700 | * @param int $start Limit for the number of parent messages we want to show |
||
| 701 | * @param int $length Wall message query offset |
||
| 702 | * @param bool $getCount |
||
| 703 | * @param array $threadList |
||
| 704 | * |
||
| 705 | * @return array|int |
||
| 706 | * |
||
| 707 | * @author Yannick Warnier |
||
| 708 | */ |
||
| 709 | public static function getWallMessages( |
||
| 899 | } |
||
| 900 | |||
| 901 | /** |
||
| 902 | * @return array |
||
| 903 | */ |
||
| 904 | public static function getAttachmentPreviewList(Message $message) |
||
| 905 | { |
||
| 906 | $list = []; |
||
| 907 | //if (empty($message['group_id'])) { |
||
| 908 | $files = $message->getAttachments(); |
||
| 909 | if ($files) { |
||
| 910 | $repo = Container::getMessageAttachmentRepository(); |
||
| 911 | /** @var MessageAttachment $file */ |
||
| 912 | foreach ($files as $file) { |
||
| 913 | $url = $repo->getResourceFileUrl($file); |
||
| 914 | $display = Display::fileHtmlGuesser($file->getFilename(), $url); |
||
| 915 | $list[] = $display; |
||
| 916 | } |
||
| 917 | } |
||
| 918 | /*} else { |
||
| 919 | $list = MessageManager::getAttachmentLinkList($messageId, 0); |
||
| 920 | }*/ |
||
| 921 | |||
| 922 | return $list; |
||
| 923 | } |
||
| 924 | |||
| 925 | /** |
||
| 926 | * @param array $message |
||
| 927 | * |
||
| 928 | * @return string |
||
| 929 | */ |
||
| 930 | public static function getPostAttachment($message) |
||
| 931 | { |
||
| 932 | $previews = self::getAttachmentPreviewList($message); |
||
| 933 | |||
| 934 | if (empty($previews)) { |
||
| 935 | return ''; |
||
| 936 | } |
||
| 937 | |||
| 938 | return implode('', $previews); |
||
| 939 | } |
||
| 940 | |||
| 941 | /** |
||
| 942 | * @param array $messages |
||
| 943 | * |
||
| 944 | * @return array |
||
| 945 | */ |
||
| 946 | public static function formatWallMessages($messages) |
||
| 972 | } |
||
| 973 | |||
| 974 | /** |
||
| 975 | * verify if Url Exist - Using Curl. |
||
| 976 | * |
||
| 977 | * @param $uri url |
||
| 978 | * |
||
| 979 | * @return bool |
||
| 980 | */ |
||
| 981 | public static function verifyUrl($uri) |
||
| 982 | { |
||
| 983 | $curl = curl_init($uri); |
||
| 984 | curl_setopt($curl, CURLOPT_FAILONERROR, true); |
||
| 985 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
||
| 986 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
| 987 | curl_setopt($curl, CURLOPT_TIMEOUT, 15); |
||
| 988 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); |
||
| 989 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
||
| 990 | curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); |
||
| 991 | $response = curl_exec($curl); |
||
| 992 | curl_close($curl); |
||
| 993 | if (!empty($response)) { |
||
| 994 | return true; |
||
| 995 | } |
||
| 996 | |||
| 997 | return false; |
||
| 998 | } |
||
| 999 | |||
| 1000 | /** |
||
| 1001 | * Generate the social block for a user. |
||
| 1002 | * |
||
| 1003 | * @param int $userId The user id |
||
| 1004 | * @param string $groupBlock Optional. Highlight link possible values: |
||
| 1005 | * group_add, home, messages, messages_inbox, messages_compose, |
||
| 1006 | * messages_outbox, invitations, shared_profile, friends, groups, search |
||
| 1007 | * @param int $groupId Optional. Group ID |
||
| 1008 | * @param bool $show_full_profile |
||
| 1009 | * |
||
| 1010 | * @return string The HTML code with the social block |
||
| 1011 | */ |
||
| 1012 | public static function setSocialUserBlock( |
||
| 1130 | } |
||
| 1131 | |||
| 1132 | /** |
||
| 1133 | * @param int $user_id |
||
| 1134 | * @param $link_shared |
||
| 1135 | * @param bool $showLinkToChat |
||
| 1136 | * |
||
| 1137 | * @return string |
||
| 1138 | */ |
||
| 1139 | public static function listMyFriendsBlock($user_id, $link_shared = '', $showLinkToChat = false) |
||
| 1140 | { |
||
| 1141 | //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT |
||
| 1142 | $friends = self::get_friends($user_id, UserRelUser::USER_RELATION_TYPE_FRIEND); |
||
| 1143 | $numberFriends = count($friends); |
||
| 1144 | $friendHtml = ''; |
||
| 1145 | |||
| 1146 | if (!empty($numberFriends)) { |
||
| 1147 | $friendHtml .= '<div class="list-group contact-list">'; |
||
| 1148 | $j = 1; |
||
| 1149 | |||
| 1150 | usort( |
||
| 1151 | $friends, |
||
| 1152 | function ($a, $b) { |
||
| 1153 | return strcmp($b['user_info']['user_is_online_in_chat'], $a['user_info']['user_is_online_in_chat']); |
||
| 1154 | } |
||
| 1155 | ); |
||
| 1156 | |||
| 1157 | foreach ($friends as $friend) { |
||
| 1158 | if ($j > $numberFriends) { |
||
| 1159 | break; |
||
| 1160 | } |
||
| 1161 | $name_user = api_get_person_name($friend['firstName'], $friend['lastName']); |
||
| 1162 | $user_info_friend = api_get_user_info($friend['friend_user_id'], true); |
||
| 1163 | |||
| 1164 | $statusIcon = Display::return_icon('statusoffline.png', get_lang('Offline')); |
||
| 1165 | $status = 0; |
||
| 1166 | if (!empty($user_info_friend['user_is_online_in_chat'])) { |
||
| 1167 | $statusIcon = Display::return_icon('statusonline.png', get_lang('Online')); |
||
| 1168 | $status = 1; |
||
| 1169 | } |
||
| 1170 | |||
| 1171 | $friendAvatarMedium = UserManager::getUserPicture( |
||
| 1172 | $friend['friend_user_id'], |
||
| 1173 | USER_IMAGE_SIZE_MEDIUM |
||
| 1174 | ); |
||
| 1175 | $friendAvatarSmall = UserManager::getUserPicture( |
||
| 1176 | $friend['friend_user_id'], |
||
| 1177 | USER_IMAGE_SIZE_SMALL |
||
| 1178 | ); |
||
| 1179 | $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>'; |
||
| 1180 | |||
| 1181 | $relation = self::get_relation_between_contacts( |
||
| 1182 | $friend['friend_user_id'], |
||
| 1183 | api_get_user_id() |
||
| 1184 | ); |
||
| 1185 | |||
| 1186 | if ($showLinkToChat) { |
||
| 1187 | $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">'; |
||
| 1188 | $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
||
| 1189 | $friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
||
| 1190 | } else { |
||
| 1191 | $link_shared = empty($link_shared) ? '' : '&'.$link_shared; |
||
| 1192 | $friendHtml .= '<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'" class="list-group-item">'; |
||
| 1193 | $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
||
| 1194 | $friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
||
| 1195 | } |
||
| 1196 | |||
| 1197 | $friendHtml .= '</a>'; |
||
| 1198 | |||
| 1199 | $j++; |
||
| 1200 | } |
||
| 1201 | $friendHtml .= '</div>'; |
||
| 1202 | } else { |
||
| 1203 | $friendHtml = Display::return_message(get_lang('No friends in your contact list'), 'warning'); |
||
| 1204 | } |
||
| 1205 | |||
| 1206 | return $friendHtml; |
||
| 1207 | } |
||
| 1208 | |||
| 1209 | /** |
||
| 1210 | * @param string $urlForm |
||
| 1211 | * |
||
| 1212 | * @return string |
||
| 1213 | */ |
||
| 1214 | public static function getWallForm($urlForm) |
||
| 1259 | } |
||
| 1260 | |||
| 1261 | /** |
||
| 1262 | * @param string $message |
||
| 1263 | * @param string $content |
||
| 1264 | * |
||
| 1265 | * @return string |
||
| 1266 | */ |
||
| 1267 | public static function wrapPost($message, $content) |
||
| 1268 | { |
||
| 1269 | $class = ''; |
||
| 1270 | if (MESSAGE_STATUS_PROMOTED === (int) $message['msg_status']) { |
||
| 1271 | $class = 'promoted_post'; |
||
| 1272 | } |
||
| 1273 | |||
| 1274 | return Display::panel($content, '', |
||
| 1275 | '', |
||
| 1276 | 'default', |
||
| 1277 | '', |
||
| 1278 | 'post_'.$message['id'], |
||
| 1279 | null, |
||
| 1280 | $class |
||
| 1281 | ); |
||
| 1282 | } |
||
| 1283 | |||
| 1284 | /** |
||
| 1285 | * Get HTML code block for user skills. |
||
| 1286 | * |
||
| 1287 | * @param int $userId The user ID |
||
| 1288 | * @param string $orientation |
||
| 1289 | * |
||
| 1290 | * @return string |
||
| 1291 | */ |
||
| 1292 | public static function getSkillBlock($userId, $orientation = 'horizontal') |
||
| 1293 | { |
||
| 1294 | if (false === SkillModel::isAllowed($userId, false)) { |
||
| 1295 | return ''; |
||
| 1296 | } |
||
| 1297 | |||
| 1298 | $skill = new SkillModel(); |
||
| 1299 | $ranking = $skill->getUserSkillRanking($userId); |
||
| 1300 | |||
| 1301 | $template = new Template(null, false, false, false, false, false); |
||
| 1302 | $template->assign('ranking', $ranking); |
||
| 1303 | $template->assign('orientation', $orientation); |
||
| 1304 | $template->assign('skills', $skill->getUserSkillsTable($userId, 0, 0, false)['skills']); |
||
| 1305 | $template->assign('user_id', $userId); |
||
| 1306 | $template->assign('show_skills_report_link', api_is_student() || api_is_student_boss() || api_is_drh()); |
||
| 1307 | |||
| 1308 | $skillBlock = $template->get_template('social/skills_block.tpl'); |
||
| 1309 | |||
| 1310 | return $template->fetch($skillBlock); |
||
| 1311 | } |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * @param int $user_id |
||
| 1315 | * @param bool $isArray |
||
| 1316 | * |
||
| 1317 | * @return string|array |
||
| 1318 | */ |
||
| 1319 | public static function getExtraFieldBlock($user_id, $isArray = false) |
||
| 1575 | } |
||
| 1576 | |||
| 1577 | /** |
||
| 1578 | * @param int $countPost |
||
| 1579 | * @param array $htmlHeadXtra |
||
| 1580 | */ |
||
| 1581 | public static function getScrollJs($countPost, &$htmlHeadXtra) |
||
| 1582 | { |
||
| 1583 | // $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php'; |
||
| 1584 | $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php'; |
||
| 1585 | $javascriptDir = api_get_path(LIBRARY_PATH).'javascript/'; |
||
| 1586 | $locale = api_get_language_isocode(); |
||
| 1587 | |||
| 1588 | // Add Jquery scroll pagination plugin |
||
| 1589 | //$htmlHeadXtra[] = api_get_js('jscroll/jquery.jscroll.js'); |
||
| 1590 | // Add Jquery Time ago plugin |
||
| 1591 | //$htmlHeadXtra[] = api_get_asset('jquery-timeago/jquery.timeago.js'); |
||
| 1592 | $timeAgoLocaleDir = $javascriptDir.'jquery-timeago/locales/jquery.timeago.'.$locale.'.js'; |
||
| 1593 | if (file_exists($timeAgoLocaleDir)) { |
||
| 1594 | $htmlHeadXtra[] = api_get_js('jquery-timeago/locales/jquery.timeago.'.$locale.'.js'); |
||
| 1595 | } |
||
| 1596 | |||
| 1597 | if ($countPost > self::DEFAULT_WALL_POSTS) { |
||
| 1598 | $htmlHeadXtra[] = '<script> |
||
| 1599 | $(function() { |
||
| 1600 | var container = $("#wallMessages"); |
||
| 1601 | container.jscroll({ |
||
| 1602 | loadingHtml: "<div class=\"well_border\">'.get_lang('Loading').' </div>", |
||
| 1603 | nextSelector: "a.nextPage:last", |
||
| 1604 | contentSelector: "", |
||
| 1605 | callback: timeAgo |
||
| 1606 | }); |
||
| 1607 | }); |
||
| 1608 | </script>'; |
||
| 1609 | } |
||
| 1610 | |||
| 1611 | $htmlHeadXtra[] = '<script> |
||
| 1612 | function deleteMessage(id) |
||
| 1613 | { |
||
| 1614 | $.ajax({ |
||
| 1615 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 1616 | success: function (result) { |
||
| 1617 | if (result) { |
||
| 1618 | $("#message_" + id).parent().parent().parent().parent().html(result); |
||
| 1619 | } |
||
| 1620 | } |
||
| 1621 | }); |
||
| 1622 | } |
||
| 1623 | |||
| 1624 | function deleteComment(id) |
||
| 1625 | { |
||
| 1626 | $.ajax({ |
||
| 1627 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 1628 | success: function (result) { |
||
| 1629 | if (result) { |
||
| 1630 | $("#message_" + id).parent().parent().parent().html(result); |
||
| 1631 | } |
||
| 1632 | } |
||
| 1633 | }); |
||
| 1634 | } |
||
| 1635 | |||
| 1636 | function submitComment(messageId) |
||
| 1637 | { |
||
| 1638 | var data = $("#form_comment_"+messageId).serializeArray(); |
||
| 1639 | $.ajax({ |
||
| 1640 | type : "POST", |
||
| 1641 | url: "'.$socialAjaxUrl.'?a=send_comment" + "&id=" + messageId, |
||
| 1642 | data: data, |
||
| 1643 | success: function (result) { |
||
| 1644 | if (result) { |
||
| 1645 | $("#post_" + messageId + " textarea").val(""); |
||
| 1646 | $("#post_" + messageId + " .sub-mediapost").prepend(result); |
||
| 1647 | $("#post_" + messageId + " .sub-mediapost").append( |
||
| 1648 | $(\'<div id=result_\' + messageId +\'>'.addslashes(get_lang('Saved.')).'</div>\') |
||
| 1649 | ); |
||
| 1650 | |||
| 1651 | $("#result_" + messageId + "").fadeIn("fast", function() { |
||
| 1652 | $("#result_" + messageId + "").delay(1000).fadeOut("fast", function() { |
||
| 1653 | $(this).remove(); |
||
| 1654 | }); |
||
| 1655 | }); |
||
| 1656 | } |
||
| 1657 | } |
||
| 1658 | }); |
||
| 1659 | } |
||
| 1660 | |||
| 1661 | $(function() { |
||
| 1662 | timeAgo(); |
||
| 1663 | |||
| 1664 | /*$(".delete_message").on("click", function() { |
||
| 1665 | var id = $(this).attr("id"); |
||
| 1666 | id = id.split("_")[1]; |
||
| 1667 | $.ajax({ |
||
| 1668 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 1669 | success: function (result) { |
||
| 1670 | if (result) { |
||
| 1671 | $("#message_" + id).parent().parent().parent().parent().html(result); |
||
| 1672 | } |
||
| 1673 | } |
||
| 1674 | }); |
||
| 1675 | }); |
||
| 1676 | |||
| 1677 | |||
| 1678 | $(".delete_comment").on("click", function() { |
||
| 1679 | var id = $(this).attr("id"); |
||
| 1680 | id = id.split("_")[1]; |
||
| 1681 | $.ajax({ |
||
| 1682 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 1683 | success: function (result) { |
||
| 1684 | if (result) { |
||
| 1685 | $("#message_" + id).parent().parent().parent().html(result); |
||
| 1686 | } |
||
| 1687 | } |
||
| 1688 | }); |
||
| 1689 | }); |
||
| 1690 | */ |
||
| 1691 | }); |
||
| 1692 | |||
| 1693 | function timeAgo() { |
||
| 1694 | $(".timeago").timeago(); |
||
| 1695 | } |
||
| 1696 | </script>'; |
||
| 1697 | } |
||
| 1698 | |||
| 1699 | /** |
||
| 1700 | * @param int $userId |
||
| 1701 | * @param int $countPost |
||
| 1702 | * |
||
| 1703 | * @return string |
||
| 1704 | */ |
||
| 1705 | public static function getAutoExtendLink($userId, $countPost) |
||
| 1706 | { |
||
| 1707 | $userId = (int) $userId; |
||
| 1708 | $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php'; |
||
| 1709 | $socialAutoExtendLink = ''; |
||
| 1710 | if ($countPost > self::DEFAULT_WALL_POSTS) { |
||
| 1711 | $socialAutoExtendLink = Display::url( |
||
| 1712 | get_lang('See more'), |
||
| 1713 | $socialAjaxUrl.'?u='.$userId.'&a=list_wall_message&start='. |
||
| 1714 | self::DEFAULT_WALL_POSTS.'&length='.self::DEFAULT_SCROLL_NEW_POST, |
||
| 1715 | [ |
||
| 1716 | 'class' => 'nextPage next', |
||
| 1717 | ] |
||
| 1718 | ); |
||
| 1719 | } |
||
| 1720 | |||
| 1721 | return $socialAutoExtendLink; |
||
| 1722 | } |
||
| 1723 | |||
| 1724 | /** |
||
| 1725 | * @param int $userId |
||
| 1726 | * |
||
| 1727 | * @return array |
||
| 1728 | */ |
||
| 1729 | public static function getThreadList($userId) |
||
| 1730 | { |
||
| 1731 | return []; |
||
| 1732 | $forumCourseId = api_get_configuration_value('global_forums_course_id'); |
||
| 1733 | |||
| 1734 | $threads = []; |
||
| 1735 | if (!empty($forumCourseId)) { |
||
| 1736 | $courseInfo = api_get_course_info_by_id($forumCourseId); |
||
| 1737 | /*getNotificationsPerUser($userId, true, $forumCourseId); |
||
| 1738 | $notification = Session::read('forum_notification'); |
||
| 1739 | Session::erase('forum_notification');*/ |
||
| 1740 | |||
| 1741 | $threadUrlBase = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
||
| 1742 | 'cid' => $courseInfo['real_id'], |
||
| 1743 | ]).'&'; |
||
| 1744 | if (isset($notification['thread']) && !empty($notification['thread'])) { |
||
| 1745 | $threadList = array_filter(array_unique($notification['thread'])); |
||
| 1746 | $repo = Container::getForumThreadRepository(); |
||
| 1747 | foreach ($threadList as $threadId) { |
||
| 1748 | /** @var CForumThread $thread */ |
||
| 1749 | $thread = $repo->find($threadId); |
||
| 1750 | if ($thread) { |
||
| 1751 | $threadUrl = $threadUrlBase.http_build_query([ |
||
| 1752 | 'forum' => $thread->getForum()->getIid(), |
||
| 1753 | 'thread' => $thread->getIid(), |
||
| 1754 | ]); |
||
| 1755 | $threads[] = [ |
||
| 1756 | 'id' => $threadId, |
||
| 1757 | 'url' => Display::url( |
||
| 1758 | $thread->getThreadTitle(), |
||
| 1759 | $threadUrl |
||
| 1760 | ), |
||
| 1761 | 'name' => Display::url( |
||
| 1762 | $thread->getThreadTitle(), |
||
| 1763 | $threadUrl |
||
| 1764 | ), |
||
| 1765 | 'description' => '', |
||
| 1766 | ]; |
||
| 1767 | } |
||
| 1768 | } |
||
| 1769 | } |
||
| 1770 | } |
||
| 1771 | |||
| 1772 | return $threads; |
||
| 1773 | } |
||
| 1774 | |||
| 1775 | /** |
||
| 1776 | * @param int $userId |
||
| 1777 | * |
||
| 1778 | * @return string |
||
| 1779 | */ |
||
| 1780 | public static function getGroupBlock($userId) |
||
| 1781 | { |
||
| 1782 | $threadList = self::getThreadList($userId); |
||
| 1783 | $userGroup = new UserGroupModel(); |
||
| 1784 | |||
| 1785 | $forumCourseId = api_get_configuration_value('global_forums_course_id'); |
||
| 1786 | $courseInfo = null; |
||
| 1787 | if (!empty($forumCourseId)) { |
||
| 1788 | $courseInfo = api_get_course_info_by_id($forumCourseId); |
||
| 1789 | } |
||
| 1790 | |||
| 1791 | $social_group_block = ''; |
||
| 1792 | if (!empty($courseInfo)) { |
||
| 1793 | if (!empty($threadList)) { |
||
| 1794 | $social_group_block .= '<div class="list-group">'; |
||
| 1795 | foreach ($threadList as $group) { |
||
| 1796 | $social_group_block .= ' <li class="list-group-item">'; |
||
| 1797 | $social_group_block .= $group['name']; |
||
| 1798 | $social_group_block .= '</li>'; |
||
| 1799 | } |
||
| 1800 | $social_group_block .= '</div>'; |
||
| 1801 | } |
||
| 1802 | |||
| 1803 | $social_group_block .= Display::url( |
||
| 1804 | get_lang('See all communities'), |
||
| 1805 | api_get_path(WEB_CODE_PATH).'forum/index.php?cid='.$courseInfo['real_id'] |
||
| 1806 | ); |
||
| 1807 | |||
| 1808 | if (!empty($social_group_block)) { |
||
| 1809 | $social_group_block = Display::panelCollapse( |
||
| 1810 | get_lang('My communities'), |
||
| 1811 | $social_group_block, |
||
| 1812 | 'sm-groups', |
||
| 1813 | null, |
||
| 1814 | 'grups-acordion', |
||
| 1815 | 'groups-collapse' |
||
| 1816 | ); |
||
| 1817 | } |
||
| 1818 | } else { |
||
| 1819 | // Load my groups |
||
| 1820 | $results = $userGroup->get_groups_by_user( |
||
| 1821 | $userId, |
||
| 1822 | [ |
||
| 1823 | GROUP_USER_PERMISSION_ADMIN, |
||
| 1824 | GROUP_USER_PERMISSION_READER, |
||
| 1825 | GROUP_USER_PERMISSION_MODERATOR, |
||
| 1826 | GROUP_USER_PERMISSION_HRM, |
||
| 1827 | ] |
||
| 1828 | ); |
||
| 1829 | |||
| 1830 | $myGroups = []; |
||
| 1831 | if (!empty($results)) { |
||
| 1832 | foreach ($results as $result) { |
||
| 1833 | $id = $result['id']; |
||
| 1834 | $result['description'] = Security::remove_XSS($result['description'], STUDENT, true); |
||
| 1835 | $result['name'] = Security::remove_XSS($result['name'], STUDENT, true); |
||
| 1836 | |||
| 1837 | $group_url = "group_view.php?id=$id"; |
||
| 1838 | |||
| 1839 | $link = Display::url( |
||
| 1840 | api_ucwords(cut($result['name'], 40, true)), |
||
| 1841 | $group_url |
||
| 1842 | ); |
||
| 1843 | |||
| 1844 | $result['name'] = $link; |
||
| 1845 | |||
| 1846 | $picture = $userGroup->get_picture_group( |
||
| 1847 | $id, |
||
| 1848 | $result['picture'], |
||
| 1849 | null, |
||
| 1850 | GROUP_IMAGE_SIZE_BIG |
||
| 1851 | ); |
||
| 1852 | |||
| 1853 | $result['picture'] = '<img class="img-responsive" src="'.$picture.'" />'; |
||
| 1854 | $group_actions = '<div class="group-more"><a class="btn btn-default" href="groups.php?#tab_browse-2">'. |
||
| 1855 | get_lang('See more').'</a></div>'; |
||
| 1856 | $group_info = '<div class="description"><p>'.cut($result['description'], 120, true)."</p></div>"; |
||
| 1857 | $myGroups[] = [ |
||
| 1858 | 'url' => Display::url( |
||
| 1859 | $result['picture'], |
||
| 1860 | $group_url |
||
| 1861 | ), |
||
| 1862 | 'name' => $result['name'], |
||
| 1863 | 'description' => $group_info.$group_actions, |
||
| 1864 | ]; |
||
| 1865 | } |
||
| 1866 | |||
| 1867 | $social_group_block .= '<div class="list-group">'; |
||
| 1868 | foreach ($myGroups as $group) { |
||
| 1869 | $social_group_block .= ' <li class="list-group-item">'; |
||
| 1870 | $social_group_block .= $group['name']; |
||
| 1871 | $social_group_block .= '</li>'; |
||
| 1872 | } |
||
| 1873 | $social_group_block .= '</div>'; |
||
| 1874 | |||
| 1875 | $form = new FormValidator( |
||
| 1876 | 'find_groups_form', |
||
| 1877 | 'get', |
||
| 1878 | api_get_path(WEB_CODE_PATH).'social/search.php?search_type=2', |
||
| 1879 | null, |
||
| 1880 | null, |
||
| 1881 | FormValidator::LAYOUT_BOX_NO_LABEL |
||
| 1882 | ); |
||
| 1883 | $form->addHidden('search_type', 2); |
||
| 1884 | |||
| 1885 | $form->addText( |
||
| 1886 | 'q', |
||
| 1887 | get_lang('Search'), |
||
| 1888 | false, |
||
| 1889 | [ |
||
| 1890 | 'aria-label' => get_lang('Search'), |
||
| 1891 | 'custom' => true, |
||
| 1892 | 'placeholder' => get_lang('Search'), |
||
| 1893 | ] |
||
| 1894 | ); |
||
| 1895 | |||
| 1896 | $social_group_block .= $form->returnForm(); |
||
| 1897 | |||
| 1898 | if (!empty($social_group_block)) { |
||
| 1899 | $social_group_block = Display::panelCollapse( |
||
| 1900 | get_lang('My groups'), |
||
| 1901 | $social_group_block, |
||
| 1902 | 'sm-groups', |
||
| 1903 | null, |
||
| 1904 | 'grups-acordion', |
||
| 1905 | 'groups-collapse' |
||
| 1906 | ); |
||
| 1907 | } |
||
| 1908 | } |
||
| 1909 | } |
||
| 1910 | |||
| 1911 | return $social_group_block; |
||
| 1912 | } |
||
| 1913 | |||
| 1914 | /** |
||
| 1915 | * @param string $selected |
||
| 1916 | * |
||
| 1917 | * @return string |
||
| 1918 | */ |
||
| 1919 | public static function getHomeProfileTabs($selected = 'home') |
||
| 1961 | } |
||
| 1962 | |||
| 1963 | /** |
||
| 1964 | * Returns the formatted header message post. |
||
| 1965 | * |
||
| 1966 | * @param int $authorInfo |
||
| 1967 | * @param int $receiverInfo |
||
| 1968 | * @param array $message Message data |
||
| 1969 | * |
||
| 1970 | * @return string $html The formatted header message post |
||
| 1971 | */ |
||
| 1972 | private static function headerMessagePost($authorInfo, $receiverInfo, $message) |
||
| 2052 | } |
||
| 2053 | } |
||
| 2054 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.