| Total Complexity | 396 |
| Total Lines | 3626 |
| Duplicated Lines | 0 % |
| Changes | 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 |
||
| 16 | class SocialManager extends UserManager |
||
| 17 | { |
||
| 18 | const DEFAULT_WALL_POSTS = 10; |
||
| 19 | const DEFAULT_SCROLL_NEW_POST = 5; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Constructor. |
||
| 23 | */ |
||
| 24 | public function __construct() |
||
| 25 | { |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Allow to see contacts list. |
||
| 30 | * |
||
| 31 | * @author isaac flores paz |
||
| 32 | * |
||
| 33 | * @return array |
||
| 34 | */ |
||
| 35 | public static function show_list_type_friends() |
||
| 36 | { |
||
| 37 | $table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); |
||
| 38 | $sql = 'SELECT id, title FROM '.$table.' |
||
| 39 | WHERE id<>6 |
||
| 40 | ORDER BY id ASC'; |
||
| 41 | $result = Database::query($sql); |
||
| 42 | $friend_relation_list = []; |
||
| 43 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
||
| 44 | $friend_relation_list[] = $row; |
||
| 45 | } |
||
| 46 | $count_list = count($friend_relation_list); |
||
| 47 | if ($count_list == 0) { |
||
| 48 | $friend_relation_list[] = get_lang('Unknown'); |
||
| 49 | } else { |
||
| 50 | return $friend_relation_list; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Get relation type contact by name. |
||
| 56 | * |
||
| 57 | * @param string names of the kind of relation |
||
| 58 | * |
||
| 59 | * @return int |
||
| 60 | * |
||
| 61 | * @author isaac flores paz |
||
| 62 | */ |
||
| 63 | public static function get_relation_type_by_name($relation_type_name) |
||
| 64 | { |
||
| 65 | $list_type_friend = self::show_list_type_friends(); |
||
| 66 | foreach ($list_type_friend as $value_type_friend) { |
||
| 67 | if (strtolower($value_type_friend['title']) == $relation_type_name) { |
||
| 68 | return $value_type_friend['id']; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get the kind of relation between contacts. |
||
| 75 | * |
||
| 76 | * @param int user id |
||
| 77 | * @param int user friend id |
||
| 78 | * @param string |
||
| 79 | * |
||
| 80 | * @return int |
||
| 81 | * |
||
| 82 | * @author isaac flores paz |
||
| 83 | */ |
||
| 84 | public static function get_relation_between_contacts($user_id, $user_friend) |
||
| 85 | { |
||
| 86 | $table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); |
||
| 87 | $userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 88 | $sql = 'SELECT rt.id as id |
||
| 89 | FROM '.$table.' rt |
||
| 90 | WHERE rt.id = ( |
||
| 91 | SELECT uf.relation_type |
||
| 92 | FROM '.$userRelUserTable.' uf |
||
| 93 | WHERE |
||
| 94 | user_id='.((int) $user_id).' AND |
||
| 95 | friend_user_id='.((int) $user_friend).' AND |
||
| 96 | uf.relation_type <> '.USER_RELATION_TYPE_RRHH.' |
||
| 97 | LIMIT 1 |
||
| 98 | )'; |
||
| 99 | $res = Database::query($sql); |
||
| 100 | if (Database::num_rows($res) > 0) { |
||
| 101 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 102 | |||
| 103 | return $row['id']; |
||
| 104 | } else { |
||
| 105 | return USER_UNKNOWN; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Get count of friends from user. |
||
| 111 | * |
||
| 112 | * @param int $userId |
||
| 113 | * |
||
| 114 | * @return int |
||
| 115 | */ |
||
| 116 | public static function getCountFriends($userId) |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Gets friends id list. |
||
| 142 | * |
||
| 143 | * @param int user id |
||
| 144 | * @param int group id |
||
| 145 | * @param string name to search |
||
| 146 | * @param bool true will load firstname, lastname, and image name |
||
| 147 | * |
||
| 148 | * @return array |
||
| 149 | * |
||
| 150 | * @author Julio Montoya <[email protected]> Cleaning code, function renamed, $load_extra_info option added |
||
| 151 | * @author isaac flores paz |
||
| 152 | */ |
||
| 153 | public static function get_friends( |
||
| 154 | $user_id, |
||
| 155 | $id_group = null, |
||
| 156 | $search_name = null, |
||
| 157 | $load_extra_info = true |
||
| 158 | ) { |
||
| 159 | $user_id = (int) $user_id; |
||
| 160 | |||
| 161 | $tbl_my_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 162 | $tbl_my_user = Database::get_main_table(TABLE_MAIN_USER); |
||
| 163 | $sql = 'SELECT friend_user_id FROM '.$tbl_my_friend.' |
||
| 164 | WHERE |
||
| 165 | relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND |
||
| 166 | friend_user_id<>'.$user_id.' AND |
||
| 167 | user_id='.$user_id; |
||
| 168 | if (isset($id_group) && $id_group > 0) { |
||
| 169 | $sql .= ' AND relation_type='.$id_group; |
||
| 170 | } |
||
| 171 | if (isset($search_name)) { |
||
| 172 | $search_name = trim($search_name); |
||
| 173 | $search_name = str_replace(' ', '', $search_name); |
||
| 174 | $sql .= ' AND friend_user_id IN ( |
||
| 175 | SELECT user_id FROM '.$tbl_my_user.' |
||
| 176 | WHERE |
||
| 177 | firstName LIKE "%'.Database::escape_string($search_name).'%" OR |
||
| 178 | lastName LIKE "%'.Database::escape_string($search_name).'%" OR |
||
| 179 | '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' LIKE concat("%","'.Database::escape_string($search_name).'","%") |
||
| 180 | ) '; |
||
| 181 | } |
||
| 182 | |||
| 183 | $res = Database::query($sql); |
||
| 184 | $list = []; |
||
| 185 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 186 | if ($load_extra_info) { |
||
| 187 | $userInfo = api_get_user_info($row['friend_user_id']); |
||
| 188 | $list[] = [ |
||
| 189 | 'friend_user_id' => $row['friend_user_id'], |
||
| 190 | 'firstName' => $userInfo['firstName'], |
||
| 191 | 'lastName' => $userInfo['lastName'], |
||
| 192 | 'username' => $userInfo['username'], |
||
| 193 | 'image' => $userInfo['avatar'], |
||
| 194 | 'user_info' => $userInfo, |
||
| 195 | ]; |
||
| 196 | } else { |
||
| 197 | $list[] = $row; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | return $list; |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * get web path of user invitate. |
||
| 206 | * |
||
| 207 | * @author isaac flores paz |
||
| 208 | * @author Julio Montoya setting variable array |
||
| 209 | * |
||
| 210 | * @param int user id |
||
| 211 | * |
||
| 212 | * @return array |
||
| 213 | */ |
||
| 214 | public static function get_list_web_path_user_invitation_by_user_id($user_id) |
||
| 215 | { |
||
| 216 | $list_ids = self::get_list_invitation_of_friends_by_user_id($user_id); |
||
| 217 | $list = []; |
||
| 218 | foreach ($list_ids as $values_ids) { |
||
| 219 | $list[] = UserManager::get_user_picture_path_by_id( |
||
| 220 | $values_ids['user_sender_id'], |
||
| 221 | 'web' |
||
| 222 | ); |
||
| 223 | } |
||
| 224 | |||
| 225 | return $list; |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Sends an invitation to contacts. |
||
| 230 | * |
||
| 231 | * @param int user id |
||
| 232 | * @param int user friend id |
||
| 233 | * @param string title of the message |
||
| 234 | * @param string content of the message |
||
| 235 | * |
||
| 236 | * @return bool |
||
| 237 | * |
||
| 238 | * @author isaac flores paz |
||
| 239 | * @author Julio Montoya <[email protected]> Cleaning code |
||
| 240 | */ |
||
| 241 | public static function send_invitation_friend( |
||
| 242 | $user_id, |
||
| 243 | $friend_id, |
||
| 244 | $message_title, |
||
| 245 | $message_content |
||
| 246 | ) { |
||
| 247 | $tbl_message = Database::get_main_table(TABLE_MESSAGE); |
||
| 248 | $user_id = (int) $user_id; |
||
| 249 | $friend_id = (int) $friend_id; |
||
| 250 | |||
| 251 | //Just in case we replace the and \n and \n\r while saving in the DB |
||
| 252 | $message_content = str_replace(["\n", "\n\r"], '<br />', $message_content); |
||
| 253 | |||
| 254 | $clean_message_content = Database::escape_string($message_content); |
||
| 255 | $now = api_get_utc_datetime(); |
||
| 256 | $sql = 'SELECT COUNT(*) AS count FROM '.$tbl_message.' |
||
| 257 | WHERE |
||
| 258 | user_sender_id='.$user_id.' AND |
||
| 259 | user_receiver_id='.$friend_id.' AND |
||
| 260 | msg_status IN('.MESSAGE_STATUS_INVITATION_PENDING.', '.MESSAGE_STATUS_INVITATION_ACCEPTED.', '.MESSAGE_STATUS_INVITATION_DENIED.'); |
||
| 261 | '; |
||
| 262 | $res_exist = Database::query($sql); |
||
| 263 | $row_exist = Database::fetch_array($res_exist, 'ASSOC'); |
||
| 264 | |||
| 265 | if ($row_exist['count'] == 0) { |
||
| 266 | $params = [ |
||
| 267 | 'user_sender_id' => $user_id, |
||
| 268 | 'user_receiver_id' => $friend_id, |
||
| 269 | 'msg_status' => MESSAGE_STATUS_INVITATION_PENDING, |
||
| 270 | 'send_date' => $now, |
||
| 271 | 'title' => $message_title, |
||
| 272 | 'content' => $message_content, |
||
| 273 | 'group_id' => 0, |
||
| 274 | 'parent_id' => 0, |
||
| 275 | 'update_date' => $now, |
||
| 276 | ]; |
||
| 277 | $messageId = Database::insert($tbl_message, $params); |
||
| 278 | |||
| 279 | $senderInfo = api_get_user_info($user_id); |
||
| 280 | $notification = new Notification(); |
||
| 281 | $notification->saveNotification( |
||
| 282 | $messageId, |
||
|
|
|||
| 283 | Notification::NOTIFICATION_TYPE_INVITATION, |
||
| 284 | [$friend_id], |
||
| 285 | $message_title, |
||
| 286 | $message_content, |
||
| 287 | $senderInfo |
||
| 288 | ); |
||
| 289 | |||
| 290 | return true; |
||
| 291 | } else { |
||
| 292 | // invitation already exist |
||
| 293 | $sql = 'SELECT COUNT(*) AS count, id FROM '.$tbl_message.' |
||
| 294 | WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7'; |
||
| 295 | $res_if_exist = Database::query($sql); |
||
| 296 | $row_if_exist = Database::fetch_array($res_if_exist, 'ASSOC'); |
||
| 297 | if ($row_if_exist['count'] == 1) { |
||
| 298 | $sql = 'UPDATE '.$tbl_message.' SET |
||
| 299 | msg_status=5, content = "'.$clean_message_content.'" |
||
| 300 | WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7 '; |
||
| 301 | Database::query($sql); |
||
| 302 | |||
| 303 | return true; |
||
| 304 | } else { |
||
| 305 | return false; |
||
| 306 | } |
||
| 307 | } |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Get number messages of the inbox. |
||
| 312 | * |
||
| 313 | * @author isaac flores paz |
||
| 314 | * |
||
| 315 | * @param int $userId user receiver id |
||
| 316 | * |
||
| 317 | * @return int |
||
| 318 | */ |
||
| 319 | public static function get_message_number_invitation_by_user_id($userId) |
||
| 320 | { |
||
| 321 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 322 | $userId = (int) $userId; |
||
| 323 | $sql = 'SELECT COUNT(*) as count_message_in_box FROM '.$table.' |
||
| 324 | WHERE |
||
| 325 | user_receiver_id='.$userId.' AND |
||
| 326 | msg_status='.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 327 | $res = Database::query($sql); |
||
| 328 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 329 | if ($row) { |
||
| 330 | return (int) $row['count_message_in_box']; |
||
| 331 | } |
||
| 332 | |||
| 333 | return 0; |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Get number of messages sent to other users. |
||
| 338 | * |
||
| 339 | * @param int $userId |
||
| 340 | * |
||
| 341 | * @return int |
||
| 342 | */ |
||
| 343 | public static function getCountMessagesSent($userId) |
||
| 344 | { |
||
| 345 | $userId = (int) $userId; |
||
| 346 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 347 | $sql = 'SELECT COUNT(*) FROM '.$table.' |
||
| 348 | WHERE |
||
| 349 | user_sender_id='.$userId.' AND |
||
| 350 | msg_status < 5'; |
||
| 351 | $res = Database::query($sql); |
||
| 352 | $row = Database::fetch_row($res); |
||
| 353 | |||
| 354 | return $row[0]; |
||
| 355 | } |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Get number of messages received from other users. |
||
| 359 | * |
||
| 360 | * @param int $receiver_id |
||
| 361 | * |
||
| 362 | * @return int |
||
| 363 | */ |
||
| 364 | public static function getCountMessagesReceived($receiver_id) |
||
| 375 | } |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Get number of messages posted on own wall. |
||
| 379 | * |
||
| 380 | * @param int $userId |
||
| 381 | * |
||
| 382 | * @return int |
||
| 383 | */ |
||
| 384 | public static function getCountWallPostedMessages($userId) |
||
| 404 | } |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Get invitation list received by user. |
||
| 408 | * |
||
| 409 | * @author isaac flores paz |
||
| 410 | * |
||
| 411 | * @param int $userId |
||
| 412 | * @param int $limit |
||
| 413 | * |
||
| 414 | * @return array |
||
| 415 | */ |
||
| 416 | public static function get_list_invitation_of_friends_by_user_id($userId, $limit = 0) |
||
| 417 | { |
||
| 418 | $userId = (int) $userId; |
||
| 419 | $limit = (int) $limit; |
||
| 420 | |||
| 421 | if (empty($userId)) { |
||
| 422 | return []; |
||
| 423 | } |
||
| 424 | |||
| 425 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 426 | $sql = 'SELECT user_sender_id, send_date, title, content |
||
| 427 | FROM '.$table.' |
||
| 428 | WHERE |
||
| 429 | user_receiver_id = '.$userId.' AND |
||
| 430 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 431 | if ($limit != null && $limit > 0) { |
||
| 432 | $sql .= ' LIMIT '.$limit; |
||
| 433 | } |
||
| 434 | $res = Database::query($sql); |
||
| 435 | $list = []; |
||
| 436 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 437 | $list[] = $row; |
||
| 438 | } |
||
| 439 | |||
| 440 | return $list; |
||
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Get invitation list sent by user. |
||
| 445 | * |
||
| 446 | * @author Julio Montoya <[email protected]> |
||
| 447 | * |
||
| 448 | * @param int $userId |
||
| 449 | * |
||
| 450 | * @return array |
||
| 451 | */ |
||
| 452 | public static function get_list_invitation_sent_by_user_id($userId) |
||
| 453 | { |
||
| 454 | $userId = (int) $userId; |
||
| 455 | |||
| 456 | if (empty($userId)) { |
||
| 457 | return []; |
||
| 458 | } |
||
| 459 | |||
| 460 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 461 | $sql = 'SELECT user_receiver_id, send_date,title,content |
||
| 462 | FROM '.$table.' |
||
| 463 | WHERE |
||
| 464 | user_sender_id = '.$userId.' AND |
||
| 465 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 466 | $res = Database::query($sql); |
||
| 467 | $list = []; |
||
| 468 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 469 | $list[$row['user_receiver_id']] = $row; |
||
| 470 | } |
||
| 471 | |||
| 472 | return $list; |
||
| 473 | } |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Get count invitation sent by user. |
||
| 477 | * |
||
| 478 | * @author Julio Montoya <[email protected]> |
||
| 479 | * |
||
| 480 | * @param int $userId |
||
| 481 | * |
||
| 482 | * @return int |
||
| 483 | */ |
||
| 484 | public static function getCountInvitationSent($userId) |
||
| 485 | { |
||
| 486 | $userId = (int) $userId; |
||
| 487 | |||
| 488 | if (empty($userId)) { |
||
| 489 | return 0; |
||
| 490 | } |
||
| 491 | |||
| 492 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 493 | $sql = 'SELECT count(user_receiver_id) count |
||
| 494 | FROM '.$table.' |
||
| 495 | WHERE |
||
| 496 | user_sender_id = '.$userId.' AND |
||
| 497 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 498 | $res = Database::query($sql); |
||
| 499 | if (Database::num_rows($res)) { |
||
| 500 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 501 | |||
| 502 | return (int) $row['count']; |
||
| 503 | } |
||
| 504 | |||
| 505 | return 0; |
||
| 506 | } |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Accepts invitation. |
||
| 510 | * |
||
| 511 | * @param int $user_send_id |
||
| 512 | * @param int $user_receiver_id |
||
| 513 | * |
||
| 514 | * @return bool |
||
| 515 | * |
||
| 516 | * @author isaac flores paz |
||
| 517 | * @author Julio Montoya <[email protected]> Cleaning code |
||
| 518 | */ |
||
| 519 | public static function invitation_accepted($user_send_id, $user_receiver_id) |
||
| 520 | { |
||
| 521 | if (empty($user_send_id) || empty($user_receiver_id)) { |
||
| 522 | return false; |
||
| 523 | } |
||
| 524 | |||
| 525 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 526 | $sql = "UPDATE $table |
||
| 527 | SET msg_status = ".MESSAGE_STATUS_INVITATION_ACCEPTED." |
||
| 528 | WHERE |
||
| 529 | user_sender_id = ".((int) $user_send_id)." AND |
||
| 530 | user_receiver_id=".((int) $user_receiver_id)." AND |
||
| 531 | msg_status = ".MESSAGE_STATUS_INVITATION_PENDING; |
||
| 532 | Database::query($sql); |
||
| 533 | |||
| 534 | return true; |
||
| 535 | } |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Denies invitation. |
||
| 539 | * |
||
| 540 | * @param int user sender id |
||
| 541 | * @param int user receiver id |
||
| 542 | * |
||
| 543 | * @return bool |
||
| 544 | * |
||
| 545 | * @author isaac flores paz |
||
| 546 | * @author Julio Montoya <[email protected]> Cleaning code |
||
| 547 | */ |
||
| 548 | public static function invitation_denied($user_send_id, $user_receiver_id) |
||
| 549 | { |
||
| 550 | if (empty($user_send_id) || empty($user_receiver_id)) { |
||
| 551 | return false; |
||
| 552 | } |
||
| 553 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 554 | $sql = 'DELETE FROM '.$table.' |
||
| 555 | WHERE |
||
| 556 | user_sender_id = '.((int) $user_send_id).' AND |
||
| 557 | user_receiver_id='.((int) $user_receiver_id).' AND |
||
| 558 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 559 | Database::query($sql); |
||
| 560 | |||
| 561 | return true; |
||
| 562 | } |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Allow attaching to group. |
||
| 566 | * |
||
| 567 | * @author Isaac Flores Paz |
||
| 568 | * |
||
| 569 | * @param int $id_friend_qualify User to qualify |
||
| 570 | * @param int $type_qualify Kind of rating |
||
| 571 | * |
||
| 572 | * @deprecated 2017-03 |
||
| 573 | */ |
||
| 574 | public static function qualify_friend($id_friend_qualify, $type_qualify) |
||
| 575 | { |
||
| 576 | $table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 577 | $user_id = api_get_user_id(); |
||
| 578 | $sql = 'UPDATE '.$table.' SET relation_type='.((int) $type_qualify).' |
||
| 579 | WHERE user_id = '.$user_id.' AND friend_user_id='.(int) $id_friend_qualify; |
||
| 580 | Database::query($sql); |
||
| 581 | } |
||
| 582 | |||
| 583 | /** |
||
| 584 | * Get user's feeds. |
||
| 585 | * |
||
| 586 | * @param int $user User ID |
||
| 587 | * @param int $limit Limit of posts per feed |
||
| 588 | * |
||
| 589 | * @return string HTML section with all feeds included |
||
| 590 | * |
||
| 591 | * @author Yannick Warnier |
||
| 592 | * |
||
| 593 | * @since Dokeos 1.8.6.1 |
||
| 594 | */ |
||
| 595 | public static function getUserRssFeed($user, $limit = 5) |
||
| 644 | } |
||
| 645 | |||
| 646 | /** |
||
| 647 | * Sends invitations to friends. |
||
| 648 | * |
||
| 649 | * @param int $userId |
||
| 650 | * @param string $subject |
||
| 651 | * @param string $content |
||
| 652 | * |
||
| 653 | * @return bool |
||
| 654 | */ |
||
| 655 | public static function sendInvitationToUser($userId, $subject = '', $content = '') |
||
| 656 | { |
||
| 657 | $user_info = api_get_user_info($userId); |
||
| 658 | $success = get_lang('MessageSentTo'); |
||
| 659 | $success .= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']); |
||
| 660 | |||
| 661 | if (isset($subject) && isset($content) && isset($userId)) { |
||
| 662 | $result = MessageManager::send_message($userId, $subject, $content); |
||
| 663 | |||
| 664 | if ($result) { |
||
| 665 | Display::addFlash( |
||
| 666 | Display::return_message($success, 'normal', false) |
||
| 667 | ); |
||
| 668 | } else { |
||
| 669 | Display::addFlash( |
||
| 670 | Display::return_message(get_lang('ErrorSendingMessage'), 'error', false) |
||
| 671 | ); |
||
| 672 | } |
||
| 673 | |||
| 674 | return false; |
||
| 675 | } elseif (isset($userId) && !isset($subject)) { |
||
| 676 | if (isset($userId) && $userId > 0) { |
||
| 677 | $count = self::send_invitation_friend( |
||
| 678 | api_get_user_id(), |
||
| 679 | $userId, |
||
| 680 | get_lang('Invitation'), |
||
| 681 | $content |
||
| 682 | ); |
||
| 683 | |||
| 684 | if ($count) { |
||
| 685 | Display::addFlash( |
||
| 686 | Display::return_message( |
||
| 687 | api_htmlentities(get_lang('InvitationHasBeenSent')), |
||
| 688 | 'normal', |
||
| 689 | false |
||
| 690 | ) |
||
| 691 | ); |
||
| 692 | } else { |
||
| 693 | Display::addFlash( |
||
| 694 | Display::return_message( |
||
| 695 | api_htmlentities(get_lang('YouAlreadySentAnInvitation')), |
||
| 696 | 'warning', |
||
| 697 | false |
||
| 698 | ) |
||
| 699 | ); |
||
| 700 | } |
||
| 701 | } |
||
| 702 | } |
||
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Helper functions definition. |
||
| 707 | */ |
||
| 708 | public static function get_logged_user_course_html($my_course, $count) |
||
| 709 | { |
||
| 710 | $result = ''; |
||
| 711 | $count = (int) $count; |
||
| 712 | |||
| 713 | // Table definitions |
||
| 714 | $main_user_table = Database::get_main_table(TABLE_MAIN_USER); |
||
| 715 | $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
||
| 716 | $course_directory = $my_course['course_info']['directory']; |
||
| 717 | $course_title = $my_course['course_info']['title']; |
||
| 718 | $course_visibility = $my_course['course_info']['visibility']; |
||
| 719 | |||
| 720 | $user_in_course_status = CourseManager::getUserInCourseStatus( |
||
| 721 | api_get_user_id(), |
||
| 722 | $my_course['course_info']['real_id'] |
||
| 723 | ); |
||
| 724 | |||
| 725 | $course_path = api_get_path(SYS_COURSE_PATH).$course_directory; // course path |
||
| 726 | if (api_get_setting('course_images_in_courses_list') === 'true') { |
||
| 727 | if (file_exists($course_path.'/course-pic85x85.png')) { |
||
| 728 | $image = $my_course['course_info']['course_image']; |
||
| 729 | $imageCourse = Display::img($image, $course_title, ['class' => 'img-course']); |
||
| 730 | } else { |
||
| 731 | $imageCourse = Display::return_icon( |
||
| 732 | 'session_default_small.png', |
||
| 733 | $course_title, |
||
| 734 | ['class' => 'img-course'] |
||
| 735 | ); |
||
| 736 | } |
||
| 737 | } else { |
||
| 738 | $imageCourse = Display::return_icon( |
||
| 739 | 'course.png', |
||
| 740 | get_lang('Course'), |
||
| 741 | ['class' => 'img-default'] |
||
| 742 | ); |
||
| 743 | } |
||
| 744 | |||
| 745 | //display course entry |
||
| 746 | if (api_get_setting('course_images_in_courses_list') === 'true') { |
||
| 747 | $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:65px;">'; |
||
| 748 | } else { |
||
| 749 | $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:44px;">'; |
||
| 750 | } |
||
| 751 | $result .= $imageCourse; |
||
| 752 | |||
| 753 | //show a hyperlink to the course, unless the course is closed and user is not course admin |
||
| 754 | if ($course_visibility != COURSE_VISIBILITY_HIDDEN && |
||
| 755 | ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) |
||
| 756 | ) { |
||
| 757 | $result .= '<span class="title">'.$course_title.'<span>'; |
||
| 758 | } else { |
||
| 759 | $result .= $course_title.' '.get_lang('CourseClosed'); |
||
| 760 | } |
||
| 761 | |||
| 762 | $result .= '</li>'; |
||
| 763 | $session = ''; |
||
| 764 | if (!empty($my_course['session_name']) && !empty($my_course['id_session'])) { |
||
| 765 | // Request for the name of the general coach |
||
| 766 | $sql = 'SELECT lastname, firstname |
||
| 767 | FROM '.$tbl_session.' ts |
||
| 768 | LEFT JOIN '.$main_user_table.' tu |
||
| 769 | ON ts.id_coach = tu.user_id |
||
| 770 | WHERE ts.id='.(int) $my_course['id_session'].' LIMIT 1'; |
||
| 771 | $rs = Database::query($sql); |
||
| 772 | $sessioncoach = Database::store_result($rs); |
||
| 773 | $sessioncoach = $sessioncoach[0]; |
||
| 774 | |||
| 775 | $session = []; |
||
| 776 | $session['title'] = $my_course['session_name']; |
||
| 777 | if ($my_course['access_start_date'] == '0000-00-00') { |
||
| 778 | $session['dates'] = get_lang('WithoutTimeLimits'); |
||
| 779 | if (api_get_setting('show_session_coach') === 'true') { |
||
| 780 | $session['coach'] = get_lang('GeneralCoach').': '. |
||
| 781 | api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); |
||
| 782 | } |
||
| 783 | } else { |
||
| 784 | $session['dates'] = ' - '.get_lang('From').' '.$my_course['access_start_date'].' '.get_lang('To').' '.$my_course['access_end_date']; |
||
| 785 | if (api_get_setting('show_session_coach') === 'true') { |
||
| 786 | $session['coach'] = get_lang('GeneralCoach').': '. |
||
| 787 | api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); |
||
| 788 | } |
||
| 789 | } |
||
| 790 | } |
||
| 791 | |||
| 792 | $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0; |
||
| 793 | $output = [ |
||
| 794 | $my_course['user_course_cat'], |
||
| 795 | $result, |
||
| 796 | $my_course['id_session'], |
||
| 797 | $session, |
||
| 798 | ]; |
||
| 799 | |||
| 800 | return $output; |
||
| 801 | } |
||
| 802 | |||
| 803 | /** |
||
| 804 | * Shows the avatar block in social pages. |
||
| 805 | * |
||
| 806 | * @param string $show highlight link possible values: |
||
| 807 | * group_add, |
||
| 808 | * home, |
||
| 809 | * messages, |
||
| 810 | * messages_inbox, |
||
| 811 | * messages_compose, |
||
| 812 | * messages_outbox, |
||
| 813 | * invitations, |
||
| 814 | * shared_profile, |
||
| 815 | * friends, |
||
| 816 | * groups search |
||
| 817 | * @param int $group_id |
||
| 818 | * @param int $userId |
||
| 819 | */ |
||
| 820 | public static function getAvatarBlock($show = '', $group_id = 0, $userId = 0) |
||
| 896 | } |
||
| 897 | |||
| 898 | /** |
||
| 899 | * Shows the right menu of the Social Network tool. |
||
| 900 | * |
||
| 901 | * @param string $show highlight link possible values: |
||
| 902 | * group_add, |
||
| 903 | * home, |
||
| 904 | * messages, |
||
| 905 | * messages_inbox, |
||
| 906 | * messages_compose , |
||
| 907 | * messages_outbox, |
||
| 908 | * invitations, |
||
| 909 | * shared_profile, |
||
| 910 | * friends, |
||
| 911 | * groups search |
||
| 912 | * @param int $group_id group id |
||
| 913 | * @param int $user_id user id |
||
| 914 | * @param bool $show_full_profile show profile or not (show or hide the user image/information) |
||
| 915 | * @param bool $show_delete_account_button |
||
| 916 | */ |
||
| 917 | public static function getMenuSocial( |
||
| 1264 | } |
||
| 1265 | |||
| 1266 | /** |
||
| 1267 | * Shows the right menu of the Social Network tool. |
||
| 1268 | * |
||
| 1269 | * @param string $show highlight link possible values: |
||
| 1270 | * group_add, |
||
| 1271 | * home, |
||
| 1272 | * messages, |
||
| 1273 | * messages_inbox, |
||
| 1274 | * messages_compose , |
||
| 1275 | * messages_outbox, |
||
| 1276 | * invitations, |
||
| 1277 | * shared_profile, |
||
| 1278 | * friends, |
||
| 1279 | * groups search |
||
| 1280 | * @param int $group_id group id |
||
| 1281 | * @param int $user_id user id |
||
| 1282 | * @param bool $show_full_profile show profile or not (show or hide the user image/information) |
||
| 1283 | * @param bool $show_delete_account_button |
||
| 1284 | */ |
||
| 1285 | public static function show_social_menu( |
||
| 1286 | $show = '', |
||
| 1287 | $group_id = 0, |
||
| 1288 | $user_id = 0, |
||
| 1289 | $show_full_profile = false, |
||
| 1290 | $show_delete_account_button = false |
||
| 1291 | ) { |
||
| 1292 | $user_id = (int) $user_id; |
||
| 1293 | $group_id = (int) $group_id; |
||
| 1294 | |||
| 1295 | if (empty($user_id)) { |
||
| 1296 | $user_id = api_get_user_id(); |
||
| 1297 | } |
||
| 1298 | |||
| 1299 | $usergroup = new UserGroup(); |
||
| 1300 | $show_groups = [ |
||
| 1301 | 'groups', |
||
| 1302 | 'group_messages', |
||
| 1303 | 'messages_list', |
||
| 1304 | 'group_add', |
||
| 1305 | 'mygroups', |
||
| 1306 | 'group_edit', |
||
| 1307 | 'member_list', |
||
| 1308 | 'invite_friends', |
||
| 1309 | 'waiting_list', |
||
| 1310 | 'browse_groups', |
||
| 1311 | ]; |
||
| 1312 | |||
| 1313 | // get count unread message and total invitations |
||
| 1314 | $count_unread_message = MessageManager::getNumberOfMessages(true); |
||
| 1315 | $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null; |
||
| 1316 | |||
| 1317 | $number_of_new_messages_of_friend = self::get_message_number_invitation_by_user_id(api_get_user_id()); |
||
| 1318 | $group_pending_invitations = $usergroup->get_groups_by_user( |
||
| 1319 | api_get_user_id(), |
||
| 1320 | GROUP_USER_PERMISSION_PENDING_INVITATION, |
||
| 1321 | false |
||
| 1322 | ); |
||
| 1323 | $group_pending_invitations = count($group_pending_invitations); |
||
| 1324 | $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; |
||
| 1325 | $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : ''); |
||
| 1326 | |||
| 1327 | $filesIcon = Display::return_icon('sn-files.png', get_lang('MyFiles'), null, ICON_SIZE_SMALL); |
||
| 1328 | $friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), null, ICON_SIZE_SMALL); |
||
| 1329 | $groupsIcon = Display::return_icon('sn-groups.png', get_lang('SocialGroups'), null, ICON_SIZE_SMALL); |
||
| 1330 | $homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), null, ICON_SIZE_SMALL); |
||
| 1331 | $invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), null, ICON_SIZE_SMALL); |
||
| 1332 | $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), null, ICON_SIZE_SMALL); |
||
| 1333 | $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile')); |
||
| 1334 | $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), null, ICON_SIZE_SMALL); |
||
| 1335 | $portfolioIcon = Display::return_icon('wiki_task.png', get_lang('Portfolio')); |
||
| 1336 | $personalDataIcon = Display::return_icon('database.png', get_lang('PersonalDataReport')); |
||
| 1337 | |||
| 1338 | $forumCourseId = api_get_configuration_value('global_forums_course_id'); |
||
| 1339 | $groupUrl = api_get_path(WEB_CODE_PATH).'social/groups.php'; |
||
| 1340 | if (!empty($forumCourseId)) { |
||
| 1341 | $courseInfo = api_get_course_info_by_id($forumCourseId); |
||
| 1342 | if (!empty($courseInfo)) { |
||
| 1343 | $groupUrl = api_get_path(WEB_CODE_PATH).'forum/index.php?cidReq='.$courseInfo['code']; |
||
| 1344 | } |
||
| 1345 | } |
||
| 1346 | |||
| 1347 | $html = ''; |
||
| 1348 | $active = null; |
||
| 1349 | if (!in_array( |
||
| 1350 | $show, |
||
| 1351 | ['shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'] |
||
| 1352 | )) { |
||
| 1353 | $links = '<ul class="nav nav-pills nav-stacked">'; |
||
| 1354 | $active = $show === 'home' ? 'active' : null; |
||
| 1355 | $links .= ' |
||
| 1356 | <li class="home-icon '.$active.'"> |
||
| 1357 | <a href="'.api_get_path(WEB_CODE_PATH).'social/home.php"> |
||
| 1358 | '.$homeIcon.' '.get_lang('Home').' |
||
| 1359 | </a> |
||
| 1360 | </li>'; |
||
| 1361 | $active = $show == 'messages' ? 'active' : null; |
||
| 1362 | $links .= ' |
||
| 1363 | <li class="messages-icon '.$active.'"> |
||
| 1364 | <a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php"> |
||
| 1365 | '.$messagesIcon.' '.get_lang('Messages').$count_unread_message.' |
||
| 1366 | </a> |
||
| 1367 | </li>'; |
||
| 1368 | |||
| 1369 | // Invitations |
||
| 1370 | $active = $show == 'invitations' ? 'active' : null; |
||
| 1371 | $links .= ' |
||
| 1372 | <li class="invitations-icon '.$active.'"> |
||
| 1373 | <a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php"> |
||
| 1374 | '.$invitationsIcon.' '.get_lang('Invitations').$total_invitations.' |
||
| 1375 | </a> |
||
| 1376 | </li>'; |
||
| 1377 | |||
| 1378 | // Shared profile and groups |
||
| 1379 | $active = $show == 'shared_profile' ? 'active' : null; |
||
| 1380 | $links .= ' |
||
| 1381 | <li class="shared-profile-icon'.$active.'"> |
||
| 1382 | <a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php"> |
||
| 1383 | '.$sharedProfileIcon.' '.get_lang('ViewMySharedProfile').' |
||
| 1384 | </a> |
||
| 1385 | </li>'; |
||
| 1386 | $active = $show == 'friends' ? 'active' : null; |
||
| 1387 | $links .= ' |
||
| 1388 | <li class="friends-icon '.$active.'"> |
||
| 1389 | <a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php"> |
||
| 1390 | '.$friendsIcon.' '.get_lang('Friends').' |
||
| 1391 | </a> |
||
| 1392 | </li>'; |
||
| 1393 | $active = $show === 'browse_groups' ? 'active' : null; |
||
| 1394 | $links .= ' |
||
| 1395 | <li class="browse-groups-icon '.$active.'"> |
||
| 1396 | <a href="'.$groupUrl.'"> |
||
| 1397 | '.$groupsIcon.' '.get_lang('SocialGroups').' |
||
| 1398 | </a> |
||
| 1399 | </li>'; |
||
| 1400 | |||
| 1401 | // Search users |
||
| 1402 | $active = $show == 'search' ? 'active' : null; |
||
| 1403 | $links .= ' |
||
| 1404 | <li class="search-icon '.$active.'"> |
||
| 1405 | <a href="'.api_get_path(WEB_CODE_PATH).'social/search.php"> |
||
| 1406 | '.$searchIcon.' '.get_lang('Search').' |
||
| 1407 | </a> |
||
| 1408 | </li>'; |
||
| 1409 | |||
| 1410 | // My files |
||
| 1411 | $active = $show == 'myfiles' ? 'active' : null; |
||
| 1412 | |||
| 1413 | $myFiles = ' |
||
| 1414 | <li class="myfiles-icon '.$active.'"> |
||
| 1415 | <a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php"> |
||
| 1416 | '.$filesIcon.' '.get_lang('MyFiles').' |
||
| 1417 | </a> |
||
| 1418 | </li>'; |
||
| 1419 | |||
| 1420 | if (api_get_setting('allow_my_files') === 'false') { |
||
| 1421 | $myFiles = ''; |
||
| 1422 | } |
||
| 1423 | $links .= $myFiles; |
||
| 1424 | if (api_get_configuration_value('allow_portfolio_tool')) { |
||
| 1425 | $links .= ' |
||
| 1426 | <li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'"> |
||
| 1427 | <a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php"> |
||
| 1428 | '.$portfolioIcon.' '.get_lang('Portfolio').' |
||
| 1429 | </a> |
||
| 1430 | </li> |
||
| 1431 | '; |
||
| 1432 | } |
||
| 1433 | |||
| 1434 | if (!api_get_configuration_value('disable_gdpr')) { |
||
| 1435 | $active = $show == 'personal-data' ? 'active' : null; |
||
| 1436 | $personalData = ' |
||
| 1437 | <li class="personal-data-icon '.$active.'"> |
||
| 1438 | <a href="'.api_get_path(WEB_CODE_PATH).'social/personal_data.php"> |
||
| 1439 | '.$personalDataIcon.' '.get_lang('PersonalDataReport').' |
||
| 1440 | </a> |
||
| 1441 | </li>'; |
||
| 1442 | $links .= $personalData; |
||
| 1443 | $links .= '</ul>'; |
||
| 1444 | } |
||
| 1445 | |||
| 1446 | $html .= Display::panelCollapse( |
||
| 1447 | get_lang('SocialNetwork'), |
||
| 1448 | $links, |
||
| 1449 | 'social-network-menu', |
||
| 1450 | null, |
||
| 1451 | 'sn-sidebar', |
||
| 1452 | 'sn-sidebar-collapse' |
||
| 1453 | ); |
||
| 1454 | } |
||
| 1455 | |||
| 1456 | if (in_array($show, $show_groups) && !empty($group_id)) { |
||
| 1457 | $html .= $usergroup->show_group_column_information( |
||
| 1458 | $group_id, |
||
| 1459 | api_get_user_id(), |
||
| 1460 | $show |
||
| 1461 | ); |
||
| 1462 | } |
||
| 1463 | |||
| 1464 | if ($show === 'shared_profile') { |
||
| 1465 | $links = '<ul class="nav nav-pills nav-stacked">'; |
||
| 1466 | // My own profile |
||
| 1467 | if ($show_full_profile && $user_id == intval(api_get_user_id())) { |
||
| 1468 | $links .= ' |
||
| 1469 | <li class="home-icon '.$active.'"> |
||
| 1470 | <a href="'.api_get_path(WEB_CODE_PATH).'social/home.php"> |
||
| 1471 | '.$homeIcon.' '.get_lang('Home').' |
||
| 1472 | </a> |
||
| 1473 | </li> |
||
| 1474 | <li class="messages-icon '.$active.'"> |
||
| 1475 | <a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php"> |
||
| 1476 | '.$messagesIcon.' '.get_lang('Messages').$count_unread_message.' |
||
| 1477 | </a> |
||
| 1478 | </li>'; |
||
| 1479 | $active = $show === 'invitations' ? 'active' : null; |
||
| 1480 | $links .= ' |
||
| 1481 | <li class="invitations-icon'.$active.'"> |
||
| 1482 | <a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php"> |
||
| 1483 | '.$invitationsIcon.' '.get_lang('Invitations').$total_invitations.' |
||
| 1484 | </a> |
||
| 1485 | </li>'; |
||
| 1486 | |||
| 1487 | $links .= ' |
||
| 1488 | <li class="shared-profile-icon active"> |
||
| 1489 | <a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php"> |
||
| 1490 | '.$sharedProfileIcon.' '.get_lang('ViewMySharedProfile').' |
||
| 1491 | </a> |
||
| 1492 | </li> |
||
| 1493 | <li class="friends-icon"> |
||
| 1494 | <a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php"> |
||
| 1495 | '.$friendsIcon.' '.get_lang('Friends').' |
||
| 1496 | </a> |
||
| 1497 | </li>'; |
||
| 1498 | |||
| 1499 | $links .= '<li class="browse-groups-icon"> |
||
| 1500 | <a href="'.$groupUrl.'"> |
||
| 1501 | '.$groupsIcon.' '.get_lang('SocialGroups').' |
||
| 1502 | </a> |
||
| 1503 | </li>'; |
||
| 1504 | |||
| 1505 | $active = $show == 'search' ? 'active' : null; |
||
| 1506 | $links .= ' |
||
| 1507 | <li class="search-icon '.$active.'"> |
||
| 1508 | <a href="'.api_get_path(WEB_CODE_PATH).'social/search.php"> |
||
| 1509 | '.$searchIcon.' '.get_lang('Search').' |
||
| 1510 | </a> |
||
| 1511 | </li>'; |
||
| 1512 | $active = $show == 'myfiles' ? 'active' : null; |
||
| 1513 | |||
| 1514 | $myFiles = ' |
||
| 1515 | <li class="myfiles-icon '.$active.'"> |
||
| 1516 | <a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php"> |
||
| 1517 | '.$filesIcon.' '.get_lang('MyFiles').' |
||
| 1518 | </a> |
||
| 1519 | </li>'; |
||
| 1520 | |||
| 1521 | if (api_get_setting('allow_my_files') === 'false') { |
||
| 1522 | $myFiles = ''; |
||
| 1523 | } |
||
| 1524 | $links .= $myFiles; |
||
| 1525 | |||
| 1526 | if (api_get_configuration_value('allow_portfolio_tool')) { |
||
| 1527 | $links .= ' |
||
| 1528 | <li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'"> |
||
| 1529 | <a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php"> |
||
| 1530 | '.$portfolioIcon.' '.get_lang('Portfolio').' |
||
| 1531 | </a> |
||
| 1532 | </li> |
||
| 1533 | '; |
||
| 1534 | } |
||
| 1535 | } |
||
| 1536 | |||
| 1537 | // My friend profile. |
||
| 1538 | if ($user_id != api_get_user_id()) { |
||
| 1539 | $sendMessageText = get_lang('SendMessage'); |
||
| 1540 | $sendMessageIcon = Display::return_icon( |
||
| 1541 | 'new-message.png', |
||
| 1542 | $sendMessageText |
||
| 1543 | ); |
||
| 1544 | $sendMessageUrl = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?'.http_build_query([ |
||
| 1545 | 'a' => 'get_user_popup', |
||
| 1546 | 'user_id' => $user_id, |
||
| 1547 | ]); |
||
| 1548 | |||
| 1549 | $links .= '<li>'; |
||
| 1550 | $links .= Display::url( |
||
| 1551 | "$sendMessageIcon $sendMessageText", |
||
| 1552 | $sendMessageUrl, |
||
| 1553 | [ |
||
| 1554 | 'class' => 'ajax', |
||
| 1555 | 'title' => $sendMessageText, |
||
| 1556 | 'data-title' => $sendMessageText, |
||
| 1557 | ] |
||
| 1558 | ); |
||
| 1559 | $links .= '</li>'; |
||
| 1560 | |||
| 1561 | if (api_get_configuration_value('allow_portfolio_tool')) { |
||
| 1562 | $links .= ' |
||
| 1563 | <li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'"> |
||
| 1564 | <a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php?user='.$user_id.'"> |
||
| 1565 | '.$portfolioIcon.' '.get_lang('Portfolio').' |
||
| 1566 | </a> |
||
| 1567 | </li> |
||
| 1568 | '; |
||
| 1569 | } |
||
| 1570 | } |
||
| 1571 | |||
| 1572 | // Check if I already sent an invitation message |
||
| 1573 | $invitation_sent_list = self::get_list_invitation_sent_by_user_id(api_get_user_id()); |
||
| 1574 | |||
| 1575 | if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && |
||
| 1576 | count($invitation_sent_list[$user_id]) > 0 |
||
| 1577 | ) { |
||
| 1578 | $links .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">'. |
||
| 1579 | Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')) |
||
| 1580 | .' '.get_lang('YouAlreadySentAnInvitation').'</a></li>'; |
||
| 1581 | } else { |
||
| 1582 | if (!$show_full_profile) { |
||
| 1583 | $links .= '<li> |
||
| 1584 | <a class="btn-to-send-invitation" href="#" data-send-to="'.$user_id.'" title="'.get_lang('SendInvitation').'">'. |
||
| 1585 | Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')).' '.get_lang('SendInvitation'). |
||
| 1586 | '</a></li>'; |
||
| 1587 | } |
||
| 1588 | } |
||
| 1589 | |||
| 1590 | $links .= '</ul>'; |
||
| 1591 | $html .= Display::panelCollapse( |
||
| 1592 | get_lang('SocialNetwork'), |
||
| 1593 | $links, |
||
| 1594 | 'social-network-menu', |
||
| 1595 | null, |
||
| 1596 | 'sn-sidebar', |
||
| 1597 | 'sn-sidebar-collapse' |
||
| 1598 | ); |
||
| 1599 | |||
| 1600 | if ($show_full_profile && $user_id == intval(api_get_user_id())) { |
||
| 1601 | $personal_course_list = UserManager::get_personal_session_course_list($user_id); |
||
| 1602 | $course_list_code = []; |
||
| 1603 | $i = 1; |
||
| 1604 | if (is_array($personal_course_list)) { |
||
| 1605 | foreach ($personal_course_list as $my_course) { |
||
| 1606 | if ($i <= 10) { |
||
| 1607 | $course_list_code[] = ['code' => $my_course['code']]; |
||
| 1608 | } else { |
||
| 1609 | break; |
||
| 1610 | } |
||
| 1611 | $i++; |
||
| 1612 | } |
||
| 1613 | // To avoid repeated courses |
||
| 1614 | $course_list_code = array_unique_dimensional($course_list_code); |
||
| 1615 | } |
||
| 1616 | |||
| 1617 | // Announcements |
||
| 1618 | $my_announcement_by_user_id = intval($user_id); |
||
| 1619 | $announcements = []; |
||
| 1620 | foreach ($course_list_code as $course) { |
||
| 1621 | $course_info = api_get_course_info($course['code']); |
||
| 1622 | if (!empty($course_info)) { |
||
| 1623 | $content = AnnouncementManager::get_all_annoucement_by_user_course( |
||
| 1624 | $course_info['code'], |
||
| 1625 | $my_announcement_by_user_id |
||
| 1626 | ); |
||
| 1627 | |||
| 1628 | if (!empty($content)) { |
||
| 1629 | $url = Display::url( |
||
| 1630 | Display::return_icon( |
||
| 1631 | 'announcement.png', |
||
| 1632 | get_lang('Announcements') |
||
| 1633 | ).$course_info['name'].' ('.$content['count'].')', |
||
| 1634 | api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$course['code'] |
||
| 1635 | ); |
||
| 1636 | $announcements[] = Display::tag('li', $url); |
||
| 1637 | } |
||
| 1638 | } |
||
| 1639 | } |
||
| 1640 | if (!empty($announcements)) { |
||
| 1641 | $html .= '<div class="social_menu_items">'; |
||
| 1642 | $html .= '<ul>'; |
||
| 1643 | foreach ($announcements as $announcement) { |
||
| 1644 | $html .= $announcement; |
||
| 1645 | } |
||
| 1646 | $html .= '</ul>'; |
||
| 1647 | $html .= '</div>'; |
||
| 1648 | } |
||
| 1649 | } |
||
| 1650 | } |
||
| 1651 | |||
| 1652 | if ($show_delete_account_button) { |
||
| 1653 | $html .= '<div class="panel panel-default"><div class="panel-body">'; |
||
| 1654 | $html .= '<ul class="nav nav-pills nav-stacked"><li>'; |
||
| 1655 | $url = api_get_path(WEB_CODE_PATH).'auth/unsubscribe_account.php'; |
||
| 1656 | $html .= Display::url( |
||
| 1657 | Display::return_icon( |
||
| 1658 | 'delete.png', |
||
| 1659 | get_lang('Unsubscribe'), |
||
| 1660 | [], |
||
| 1661 | ICON_SIZE_TINY |
||
| 1662 | ).get_lang('Unsubscribe'), |
||
| 1663 | $url |
||
| 1664 | ); |
||
| 1665 | $html .= '</li></ul>'; |
||
| 1666 | $html .= '</div></div>'; |
||
| 1667 | } |
||
| 1668 | $html .= ''; |
||
| 1669 | |||
| 1670 | return $html; |
||
| 1671 | } |
||
| 1672 | |||
| 1673 | /** |
||
| 1674 | * Displays a sortable table with the list of online users. |
||
| 1675 | * |
||
| 1676 | * @param array $user_list The list of users to be shown |
||
| 1677 | * @param bool $wrap Whether we want the function to wrap the spans list in a div or not |
||
| 1678 | * |
||
| 1679 | * @return string HTML block or null if and ID was defined |
||
| 1680 | * @assert (null) === false |
||
| 1681 | */ |
||
| 1682 | public static function display_user_list($user_list, $wrap = true) |
||
| 1683 | { |
||
| 1684 | $html = ''; |
||
| 1685 | |||
| 1686 | if (isset($_GET['id']) || count($user_list) < 1) { |
||
| 1687 | return false; |
||
| 1688 | } |
||
| 1689 | |||
| 1690 | $course_url = ''; |
||
| 1691 | if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) { |
||
| 1692 | $course_url = '&cidReq='.Security::remove_XSS($_GET['cidReq']); |
||
| 1693 | } |
||
| 1694 | |||
| 1695 | $hide = api_get_configuration_value('hide_complete_name_in_whoisonline'); |
||
| 1696 | foreach ($user_list as $uid) { |
||
| 1697 | $user_info = api_get_user_info($uid, true); |
||
| 1698 | $lastname = $user_info['lastname']; |
||
| 1699 | $firstname = $user_info['firstname']; |
||
| 1700 | $completeName = $firstname.', '.$lastname; |
||
| 1701 | $user_rol = $user_info['status'] == 1 ? Display::return_icon('teacher.png', get_lang('Teacher'), null, ICON_SIZE_TINY) : Display::return_icon('user.png', get_lang('Student'), null, ICON_SIZE_TINY); |
||
| 1702 | $status_icon_chat = null; |
||
| 1703 | if (isset($user_info['user_is_online_in_chat']) && $user_info['user_is_online_in_chat'] == 1) { |
||
| 1704 | $status_icon_chat = Display::return_icon('online.png', get_lang('Online')); |
||
| 1705 | } else { |
||
| 1706 | $status_icon_chat = Display::return_icon('offline.png', get_lang('Offline')); |
||
| 1707 | } |
||
| 1708 | |||
| 1709 | $userPicture = $user_info['avatar']; |
||
| 1710 | $officialCode = ''; |
||
| 1711 | if (api_get_setting('show_official_code_whoisonline') == 'true') { |
||
| 1712 | $officialCode .= '<div class="items-user-official-code"><p style="min-height: 30px;" title="'.get_lang('OfficialCode').'">'.$user_info['official_code'].'</p></div>'; |
||
| 1713 | } |
||
| 1714 | |||
| 1715 | if ($hide === true) { |
||
| 1716 | $completeName = ''; |
||
| 1717 | $firstname = ''; |
||
| 1718 | $lastname = ''; |
||
| 1719 | } |
||
| 1720 | |||
| 1721 | $img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">'; |
||
| 1722 | |||
| 1723 | $url = null; |
||
| 1724 | // Anonymous users can't have access to the profile |
||
| 1725 | if (!api_is_anonymous()) { |
||
| 1726 | if (api_get_setting('allow_social_tool') === 'true') { |
||
| 1727 | $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url; |
||
| 1728 | } else { |
||
| 1729 | $url = '?id='.$uid.$course_url; |
||
| 1730 | } |
||
| 1731 | } else { |
||
| 1732 | $url = null; |
||
| 1733 | } |
||
| 1734 | $name = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>'; |
||
| 1735 | |||
| 1736 | $html .= '<div class="col-xs-6 col-md-2"> |
||
| 1737 | <div class="items-user"> |
||
| 1738 | <div class="items-user-avatar"><a href="'.$url.'">'.$img.'</a></div> |
||
| 1739 | <div class="items-user-name"> |
||
| 1740 | '.$name.' |
||
| 1741 | </div> |
||
| 1742 | '.$officialCode.' |
||
| 1743 | <div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div> |
||
| 1744 | </div> |
||
| 1745 | </div>'; |
||
| 1746 | } |
||
| 1747 | |||
| 1748 | return $html; |
||
| 1749 | } |
||
| 1750 | |||
| 1751 | /** |
||
| 1752 | * Display productions in who is online. |
||
| 1753 | * |
||
| 1754 | * @param int $user_id User id |
||
| 1755 | */ |
||
| 1756 | public static function display_productions($user_id) |
||
| 1757 | { |
||
| 1758 | $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web'); |
||
| 1759 | $sysdir = UserManager::getUserPathById($user_id, 'system'); |
||
| 1760 | $webdir = UserManager::getUserPathById($user_id, 'web'); |
||
| 1761 | |||
| 1762 | if (!is_dir($sysdir)) { |
||
| 1763 | mkdir($sysdir, api_get_permissions_for_new_directories(), true); |
||
| 1764 | } |
||
| 1765 | |||
| 1766 | $productions = UserManager::get_user_productions($user_id); |
||
| 1767 | |||
| 1768 | if (count($productions) > 0) { |
||
| 1769 | echo '<dt><strong>'.get_lang('Productions').'</strong></dt>'; |
||
| 1770 | echo '<dd><ul>'; |
||
| 1771 | foreach ($productions as $file) { |
||
| 1772 | // Only display direct file links to avoid browsing an empty directory |
||
| 1773 | if (is_file($sysdir.$file) && $file != $webdir_array['file']) { |
||
| 1774 | echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>'; |
||
| 1775 | } |
||
| 1776 | // Real productions are under a subdirectory by the User's id |
||
| 1777 | if (is_dir($sysdir.$file)) { |
||
| 1778 | $subs = scandir($sysdir.$file); |
||
| 1779 | foreach ($subs as $my => $sub) { |
||
| 1780 | if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) { |
||
| 1781 | echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>'; |
||
| 1782 | } |
||
| 1783 | } |
||
| 1784 | } |
||
| 1785 | } |
||
| 1786 | echo '</ul></dd>'; |
||
| 1787 | } |
||
| 1788 | } |
||
| 1789 | |||
| 1790 | /** |
||
| 1791 | * @param string $content |
||
| 1792 | * @param string $span_count |
||
| 1793 | * |
||
| 1794 | * @return string |
||
| 1795 | */ |
||
| 1796 | public static function social_wrapper_div($content, $span_count) |
||
| 1797 | { |
||
| 1798 | $span_count = (int) $span_count; |
||
| 1799 | $html = '<div class="span'.$span_count.'">'; |
||
| 1800 | $html .= '<div class="well_border">'; |
||
| 1801 | $html .= $content; |
||
| 1802 | $html .= '</div></div>'; |
||
| 1803 | |||
| 1804 | return $html; |
||
| 1805 | } |
||
| 1806 | |||
| 1807 | /** |
||
| 1808 | * Dummy function. |
||
| 1809 | */ |
||
| 1810 | public static function get_plugins($place = SOCIAL_CENTER_PLUGIN) |
||
| 1811 | { |
||
| 1812 | $content = ''; |
||
| 1813 | switch ($place) { |
||
| 1814 | case SOCIAL_CENTER_PLUGIN: |
||
| 1815 | $social_plugins = [1, 2]; |
||
| 1816 | if (is_array($social_plugins) && count($social_plugins) > 0) { |
||
| 1817 | $content .= '<div id="social-plugins">'; |
||
| 1818 | foreach ($social_plugins as $plugin) { |
||
| 1819 | $content .= '<div class="social-plugin-item">'; |
||
| 1820 | $content .= $plugin; |
||
| 1821 | $content .= '</div>'; |
||
| 1822 | } |
||
| 1823 | $content .= '</div>'; |
||
| 1824 | } |
||
| 1825 | break; |
||
| 1826 | case SOCIAL_LEFT_PLUGIN: |
||
| 1827 | break; |
||
| 1828 | case SOCIAL_RIGHT_PLUGIN: |
||
| 1829 | break; |
||
| 1830 | } |
||
| 1831 | |||
| 1832 | return $content; |
||
| 1833 | } |
||
| 1834 | |||
| 1835 | /** |
||
| 1836 | * Sends a message to someone's wall. |
||
| 1837 | * |
||
| 1838 | * @param int $userId id of author |
||
| 1839 | * @param int $friendId id where we send the message |
||
| 1840 | * @param string $messageContent of the message |
||
| 1841 | * @param int $messageId id parent |
||
| 1842 | * @param string $messageStatus status type of message |
||
| 1843 | * |
||
| 1844 | * @return int |
||
| 1845 | * |
||
| 1846 | * @author Yannick Warnier |
||
| 1847 | */ |
||
| 1848 | public static function sendWallMessage( |
||
| 1849 | $userId, |
||
| 1850 | $friendId, |
||
| 1851 | $messageContent, |
||
| 1852 | $messageId = 0, |
||
| 1853 | $messageStatus = '' |
||
| 1854 | ) { |
||
| 1855 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
| 1856 | $userId = (int) $userId; |
||
| 1857 | $friendId = (int) $friendId; |
||
| 1858 | $messageId = (int) $messageId; |
||
| 1859 | |||
| 1860 | if (empty($userId) || empty($friendId)) { |
||
| 1861 | return 0; |
||
| 1862 | } |
||
| 1863 | |||
| 1864 | // Just in case we replace the and \n and \n\r while saving in the DB |
||
| 1865 | $messageContent = str_replace(["\n", "\n\r"], '<br />', $messageContent); |
||
| 1866 | $now = api_get_utc_datetime(); |
||
| 1867 | |||
| 1868 | $attributes = [ |
||
| 1869 | 'user_sender_id' => $userId, |
||
| 1870 | 'user_receiver_id' => $friendId, |
||
| 1871 | 'msg_status' => $messageStatus, |
||
| 1872 | 'send_date' => $now, |
||
| 1873 | 'title' => '', |
||
| 1874 | 'content' => $messageContent, |
||
| 1875 | 'parent_id' => $messageId, |
||
| 1876 | 'group_id' => 0, |
||
| 1877 | 'update_date' => $now, |
||
| 1878 | ]; |
||
| 1879 | |||
| 1880 | return Database::insert($tblMessage, $attributes); |
||
| 1881 | } |
||
| 1882 | |||
| 1883 | /** |
||
| 1884 | * Send File attachment (jpg,png). |
||
| 1885 | * |
||
| 1886 | * @author Anibal Copitan |
||
| 1887 | * |
||
| 1888 | * @param int $userId id user |
||
| 1889 | * @param array $fileAttach |
||
| 1890 | * @param int $messageId id message (relation with main message) |
||
| 1891 | * @param string $fileComment description attachment file |
||
| 1892 | * |
||
| 1893 | * @return bool|int |
||
| 1894 | */ |
||
| 1895 | public static function sendWallMessageAttachmentFile( |
||
| 1896 | $userId, |
||
| 1897 | $fileAttach, |
||
| 1898 | $messageId, |
||
| 1899 | $fileComment = '' |
||
| 1900 | ) { |
||
| 1901 | $safeFileName = Database::escape_string($fileAttach['name']); |
||
| 1902 | |||
| 1903 | $extension = strtolower(substr(strrchr($safeFileName, '.'), 1)); |
||
| 1904 | $allowedTypes = api_get_supported_image_extensions(); |
||
| 1905 | |||
| 1906 | $allowedTypes[] = 'mp4'; |
||
| 1907 | $allowedTypes[] = 'webm'; |
||
| 1908 | $allowedTypes[] = 'ogg'; |
||
| 1909 | |||
| 1910 | if (in_array($extension, $allowedTypes)) { |
||
| 1911 | return MessageManager::saveMessageAttachmentFile($fileAttach, $fileComment, $messageId, $userId); |
||
| 1912 | } |
||
| 1913 | |||
| 1914 | return false; |
||
| 1915 | } |
||
| 1916 | |||
| 1917 | /** |
||
| 1918 | * Gets all messages from someone's wall (within specific limits). |
||
| 1919 | * |
||
| 1920 | * @param int $userId id of wall shown |
||
| 1921 | * @param int|string $parentId id message (Post main) |
||
| 1922 | * @param int|array $groupId |
||
| 1923 | * @param int|array $friendId |
||
| 1924 | * @param string $startDate Date from which we want to show the messages, in UTC time |
||
| 1925 | * @param int $start Limit for the number of parent messages we want to show |
||
| 1926 | * @param int $length Wall message query offset |
||
| 1927 | * @param bool $getCount |
||
| 1928 | * @param array $threadList |
||
| 1929 | * |
||
| 1930 | * @return array|int |
||
| 1931 | * |
||
| 1932 | * @author Yannick Warnier |
||
| 1933 | */ |
||
| 1934 | public static function getWallMessages( |
||
| 1935 | $userId, |
||
| 1936 | $parentId = 0, |
||
| 1937 | $groupId = 0, |
||
| 1938 | $friendId = 0, |
||
| 1939 | $startDate = '', |
||
| 1940 | $start = 0, |
||
| 1941 | $length = 10, |
||
| 1942 | $getCount = false, |
||
| 1943 | $threadList = [] |
||
| 1944 | ) { |
||
| 1945 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
| 1946 | |||
| 1947 | $parentId = (int) $parentId; |
||
| 1948 | $userId = (int) $userId; |
||
| 1949 | $start = (int) $start; |
||
| 1950 | $length = (int) $length; |
||
| 1951 | $startDate = Database::escape_string($startDate); |
||
| 1952 | |||
| 1953 | $select = " SELECT |
||
| 1954 | id, |
||
| 1955 | user_sender_id, |
||
| 1956 | user_receiver_id, |
||
| 1957 | send_date, |
||
| 1958 | content, |
||
| 1959 | parent_id, |
||
| 1960 | msg_status, |
||
| 1961 | group_id, |
||
| 1962 | '' as forum_id, |
||
| 1963 | '' as thread_id, |
||
| 1964 | '' as c_id |
||
| 1965 | "; |
||
| 1966 | |||
| 1967 | if ($getCount) { |
||
| 1968 | $select = ' SELECT count(id) count '; |
||
| 1969 | } |
||
| 1970 | |||
| 1971 | $sql = "$select |
||
| 1972 | FROM $tblMessage tm |
||
| 1973 | WHERE |
||
| 1974 | msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND '; |
||
| 1975 | |||
| 1976 | // My own posts |
||
| 1977 | $userReceiverCondition = ' ( |
||
| 1978 | user_receiver_id = '.$userId.' AND |
||
| 1979 | msg_status IN ('.MESSAGE_STATUS_WALL_POST.', '.MESSAGE_STATUS_WALL.') AND |
||
| 1980 | parent_id = '.$parentId.' |
||
| 1981 | )'; |
||
| 1982 | |||
| 1983 | // User condition |
||
| 1984 | $sql .= $userReceiverCondition; |
||
| 1985 | |||
| 1986 | // Get my group posts |
||
| 1987 | $groupCondition = ''; |
||
| 1988 | if (!empty($groupId)) { |
||
| 1989 | if (is_array($groupId)) { |
||
| 1990 | $groupId = array_map('intval', $groupId); |
||
| 1991 | $groupId = implode("','", $groupId); |
||
| 1992 | $groupCondition = " OR ( group_id IN ('$groupId') "; |
||
| 1993 | } else { |
||
| 1994 | $groupId = (int) $groupId; |
||
| 1995 | $groupCondition = " OR ( group_id = '$groupId' "; |
||
| 1996 | } |
||
| 1997 | $groupCondition .= ' AND msg_status IN ('.MESSAGE_STATUS_NEW.', '.MESSAGE_STATUS_UNREAD.')) '; |
||
| 1998 | } |
||
| 1999 | |||
| 2000 | $friendCondition = ''; |
||
| 2001 | // Get my friend posts |
||
| 2002 | if (!empty($friendId)) { |
||
| 2003 | if (is_array($friendId)) { |
||
| 2004 | $friendId = array_map('intval', $friendId); |
||
| 2005 | $friendId = implode("','", $friendId); |
||
| 2006 | $friendCondition = " OR ( user_receiver_id IN ('$friendId') "; |
||
| 2007 | } else { |
||
| 2008 | $friendId = (int) $friendId; |
||
| 2009 | $friendCondition = " OR ( user_receiver_id = '$friendId' "; |
||
| 2010 | } |
||
| 2011 | $friendCondition .= ' AND msg_status IN ('.MESSAGE_STATUS_WALL_POST.') AND parent_id = 0) '; |
||
| 2012 | } |
||
| 2013 | |||
| 2014 | if (!empty($groupCondition) || !empty($friendCondition)) { |
||
| 2015 | $sql .= " $groupCondition $friendCondition "; |
||
| 2016 | } |
||
| 2017 | |||
| 2018 | if (!empty($threadList)) { |
||
| 2019 | if ($getCount) { |
||
| 2020 | $select = ' SELECT count(iid) count '; |
||
| 2021 | } else { |
||
| 2022 | $select = " SELECT |
||
| 2023 | iid, |
||
| 2024 | poster_id, |
||
| 2025 | '' as user_receiver_id, |
||
| 2026 | post_date, |
||
| 2027 | post_text, |
||
| 2028 | '' as parent_id, |
||
| 2029 | ".MESSAGE_STATUS_FORUM.", |
||
| 2030 | '' as group_id, |
||
| 2031 | forum_id, |
||
| 2032 | thread_id, |
||
| 2033 | c_id |
||
| 2034 | "; |
||
| 2035 | } |
||
| 2036 | |||
| 2037 | $threadList = array_map('intval', $threadList); |
||
| 2038 | $threadList = implode("','", $threadList); |
||
| 2039 | $condition = " thread_id IN ('$threadList') "; |
||
| 2040 | $sql .= " |
||
| 2041 | UNION ( |
||
| 2042 | $select |
||
| 2043 | FROM c_forum_post |
||
| 2044 | WHERE $condition |
||
| 2045 | ) |
||
| 2046 | "; |
||
| 2047 | } |
||
| 2048 | |||
| 2049 | if ($getCount) { |
||
| 2050 | $res = Database::query($sql); |
||
| 2051 | $row = Database::fetch_array($res); |
||
| 2052 | |||
| 2053 | return (int) $row['count']; |
||
| 2054 | } |
||
| 2055 | |||
| 2056 | $sql .= ' ORDER BY send_date DESC '; |
||
| 2057 | $sql .= " LIMIT $start, $length "; |
||
| 2058 | |||
| 2059 | $messages = []; |
||
| 2060 | $res = Database::query($sql); |
||
| 2061 | $em = Database::getManager(); |
||
| 2062 | if (Database::num_rows($res) > 0) { |
||
| 2063 | $repo = $em->getRepository('ChamiloCourseBundle:CForumPost'); |
||
| 2064 | $repoThread = $em->getRepository('ChamiloCourseBundle:CForumThread'); |
||
| 2065 | $groups = []; |
||
| 2066 | $forums = []; |
||
| 2067 | $userGroup = new UserGroup(); |
||
| 2068 | $urlGroup = api_get_path(WEB_CODE_PATH).'social/group_view.php?id='; |
||
| 2069 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 2070 | $row['group_info'] = []; |
||
| 2071 | if (!empty($row['group_id'])) { |
||
| 2072 | if (!in_array($row['group_id'], $groups)) { |
||
| 2073 | $group = $userGroup->get($row['group_id']); |
||
| 2074 | $group['url'] = $urlGroup.$group['id']; |
||
| 2075 | $groups[$row['group_id']] = $group; |
||
| 2076 | $row['group_info'] = $group; |
||
| 2077 | } else { |
||
| 2078 | $row['group_info'] = $groups[$row['group_id']]; |
||
| 2079 | } |
||
| 2080 | } |
||
| 2081 | |||
| 2082 | // forums |
||
| 2083 | $row['post_title'] = ''; |
||
| 2084 | $row['forum_title'] = ''; |
||
| 2085 | $row['thread_url'] = ''; |
||
| 2086 | if ($row['msg_status'] == MESSAGE_STATUS_FORUM) { |
||
| 2087 | /** @var \Chamilo\CourseBundle\Entity\CForumPost $post */ |
||
| 2088 | $post = $repo->find($row['id']); |
||
| 2089 | /** @var \Chamilo\CourseBundle\Entity\CForumThread $thread */ |
||
| 2090 | $thread = $repoThread->find($row['thread_id']); |
||
| 2091 | if ($post && $thread) { |
||
| 2092 | $courseInfo = api_get_course_info_by_id($post->getCId()); |
||
| 2093 | $row['post_title'] = $post->getForumId(); |
||
| 2094 | $row['forum_title'] = $thread->getThreadTitle(); |
||
| 2095 | $row['thread_url'] = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
||
| 2096 | 'cidReq' => $courseInfo['code'], |
||
| 2097 | 'forum' => $post->getForumId(), |
||
| 2098 | 'thread' => $post->getThreadId(), |
||
| 2099 | 'post_id' => $post->getIid(), |
||
| 2100 | ]).'#post_id_'.$post->getIid(); |
||
| 2101 | } |
||
| 2102 | } |
||
| 2103 | |||
| 2104 | $messages[] = $row; |
||
| 2105 | } |
||
| 2106 | } |
||
| 2107 | |||
| 2108 | return $messages; |
||
| 2109 | } |
||
| 2110 | |||
| 2111 | /** |
||
| 2112 | * Gets all messages from someone's wall (within specific limits), formatted. |
||
| 2113 | * |
||
| 2114 | * @param int $userId USER ID of the person's wall |
||
| 2115 | * @param array $messageInfo |
||
| 2116 | * @param string $start Start date (from when we want the messages until today) |
||
| 2117 | * @param int $limit Limit to the number of messages we want |
||
| 2118 | * @param int $offset Wall messages offset |
||
| 2119 | * |
||
| 2120 | * @return string HTML formatted string to show messages |
||
| 2121 | */ |
||
| 2122 | public static function getWallPostComments( |
||
| 2123 | $userId, |
||
| 2124 | $messageInfo, |
||
| 2125 | $start = null, |
||
| 2126 | $limit = 10, |
||
| 2127 | $offset = 0 |
||
| 2128 | ) { |
||
| 2129 | $messageId = $messageInfo['id']; |
||
| 2130 | $messages = MessageManager::getMessagesByParent($messageInfo['id'], 0, $offset, $limit); |
||
| 2131 | $formattedList = '<div class="sub-mediapost row">'; |
||
| 2132 | $users = []; |
||
| 2133 | |||
| 2134 | // The messages are ordered by date descendant, for comments we need ascendant |
||
| 2135 | krsort($messages); |
||
| 2136 | foreach ($messages as $message) { |
||
| 2137 | $userIdLoop = $message['user_sender_id']; |
||
| 2138 | if (!isset($users[$userIdLoop])) { |
||
| 2139 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
| 2140 | } |
||
| 2141 | $media = self::processPostComment($message, $users); |
||
| 2142 | $formattedList .= $media; |
||
| 2143 | } |
||
| 2144 | |||
| 2145 | $formattedList .= '</div>'; |
||
| 2146 | $formattedList .= '<div class="mediapost-form">'; |
||
| 2147 | $formattedList .= '<form class="form-horizontal" id="form_comment_'.$messageId.'" name="post_comment" method="POST"> |
||
| 2148 | <div class="col-sm-9"> |
||
| 2149 | <label for="comment" class="hide">'.get_lang('SocialWriteNewComment').'</label> |
||
| 2150 | <input type="hidden" name = "messageId" value="'.$messageId.'" /> |
||
| 2151 | <textarea rows="3" class="form-control" placeholder="'.get_lang('SocialWriteNewComment').'" name="comment" rows="1" ></textarea> |
||
| 2152 | </div> |
||
| 2153 | <div class="col-sm-3"> |
||
| 2154 | <a onclick="submitComment('.$messageId.');" href="javascript:void(0);" name="social_wall_new_msg_submit" class="btn btn-default btn-post"> |
||
| 2155 | <em class="fa fa-pencil"></em> '.get_lang('Post').' |
||
| 2156 | </a> |
||
| 2157 | </div> |
||
| 2158 | </form>'; |
||
| 2159 | $formattedList .= '</div>'; |
||
| 2160 | |||
| 2161 | return $formattedList; |
||
| 2162 | } |
||
| 2163 | |||
| 2164 | /** |
||
| 2165 | * @param array $message |
||
| 2166 | * @param array $users |
||
| 2167 | * |
||
| 2168 | * @return string |
||
| 2169 | */ |
||
| 2170 | public static function processPostComment($message, $users = []) |
||
| 2171 | { |
||
| 2172 | if (empty($message)) { |
||
| 2173 | return false; |
||
| 2174 | } |
||
| 2175 | |||
| 2176 | $date = Display::dateToStringAgoAndLongDate($message['send_date']); |
||
| 2177 | $currentUserId = api_get_user_id(); |
||
| 2178 | $userIdLoop = $message['user_sender_id']; |
||
| 2179 | $receiverId = $message['user_receiver_id']; |
||
| 2180 | $urlImg = api_get_path(WEB_IMG_PATH); |
||
| 2181 | |||
| 2182 | if (!isset($users[$userIdLoop])) { |
||
| 2183 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
| 2184 | } |
||
| 2185 | |||
| 2186 | $iconStatus = ''; |
||
| 2187 | $userStatus = (int) $users[$userIdLoop]['status']; |
||
| 2188 | $isAdmin = self::is_admin($users[$userIdLoop]['id']); |
||
| 2189 | if ($userStatus === 5) { |
||
| 2190 | if ($users[$userIdLoop]['has_certificates']) { |
||
| 2191 | $iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_graduated.svg" width="22px" height="22px">'; |
||
| 2192 | } else { |
||
| 2193 | $iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_student.svg" width="22px" height="22px">'; |
||
| 2194 | } |
||
| 2195 | } else { |
||
| 2196 | if ($userStatus === 1) { |
||
| 2197 | if ($isAdmin) { |
||
| 2198 | $iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_admin.svg" width="22px" height="22px">'; |
||
| 2199 | } else { |
||
| 2200 | $iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_teacher.svg" width="22px" height="22px">'; |
||
| 2201 | } |
||
| 2202 | } |
||
| 2203 | } |
||
| 2204 | |||
| 2205 | $nameComplete = $users[$userIdLoop]['complete_name']; |
||
| 2206 | $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop; |
||
| 2207 | |||
| 2208 | $comment = '<div class="rep-post col-md-12">'; |
||
| 2209 | $comment .= '<div class="col-md-2 col-xs-2 social-post-answers">'; |
||
| 2210 | $comment .= '<div class="user-image pull-right">'; |
||
| 2211 | $comment .= '<a href="'.$url.'"> |
||
| 2212 | <img src="'.$users[$userIdLoop]['avatar'].'" |
||
| 2213 | alt="'.$users[$userIdLoop]['complete_name'].'" |
||
| 2214 | class="avatar-thumb"> |
||
| 2215 | </a>'; |
||
| 2216 | $comment .= '</div>'; |
||
| 2217 | $comment .= '</div>'; |
||
| 2218 | $comment .= '<div class="col-md-7 col-xs-7 social-post-answers">'; |
||
| 2219 | $comment .= '<div class="user-data">'; |
||
| 2220 | $comment .= $iconStatus; |
||
| 2221 | $comment .= '<div class="username"><a href="'.$url.'">'.$nameComplete.'</a> |
||
| 2222 | <span>'.Security::remove_XSS($message['content']).'</span> |
||
| 2223 | </div>'; |
||
| 2224 | $comment .= '<div>'.$date.'</div>'; |
||
| 2225 | $comment .= '<br />'; |
||
| 2226 | $comment .= '</div>'; |
||
| 2227 | $comment .= '</div>'; |
||
| 2228 | |||
| 2229 | $comment .= '<div class="col-md-3 col-xs-3 social-post-answers">'; |
||
| 2230 | $comment .= '<div class="pull-right btn-group btn-group-sm">'; |
||
| 2231 | |||
| 2232 | $comment .= MessageManager::getLikesButton( |
||
| 2233 | $message['id'], |
||
| 2234 | $currentUserId |
||
| 2235 | ); |
||
| 2236 | |||
| 2237 | $isOwnWall = $currentUserId == $userIdLoop || $currentUserId == $receiverId; |
||
| 2238 | if ($isOwnWall) { |
||
| 2239 | $comment .= Display::url( |
||
| 2240 | Display::returnFontAwesomeIcon('trash', '', true), |
||
| 2241 | 'javascript:void(0)', |
||
| 2242 | [ |
||
| 2243 | 'id' => 'message_'.$message['id'], |
||
| 2244 | 'title' => get_lang('SocialMessageDelete'), |
||
| 2245 | 'onclick' => 'deleteComment('.$message['id'].')', |
||
| 2246 | 'class' => 'btn btn-default', |
||
| 2247 | ] |
||
| 2248 | ); |
||
| 2249 | } |
||
| 2250 | $comment .= '</div>'; |
||
| 2251 | $comment .= '</div>'; |
||
| 2252 | $comment .= '</div>'; |
||
| 2253 | |||
| 2254 | return $comment; |
||
| 2255 | } |
||
| 2256 | |||
| 2257 | /** |
||
| 2258 | * @param array $message |
||
| 2259 | * |
||
| 2260 | * @return array |
||
| 2261 | */ |
||
| 2262 | public static function getAttachmentPreviewList($message) |
||
| 2263 | { |
||
| 2264 | $messageId = $message['id']; |
||
| 2265 | |||
| 2266 | $list = []; |
||
| 2267 | |||
| 2268 | if (empty($message['group_id'])) { |
||
| 2269 | $files = MessageManager::getAttachmentList($messageId); |
||
| 2270 | if ($files) { |
||
| 2271 | $downloadUrl = api_get_path(WEB_CODE_PATH).'social/download.php?message_id='.$messageId; |
||
| 2272 | foreach ($files as $row_file) { |
||
| 2273 | $url = $downloadUrl.'&attachment_id='.$row_file['id']; |
||
| 2274 | $display = Display::fileHtmlGuesser($row_file['filename'], $url); |
||
| 2275 | $list[] = $display; |
||
| 2276 | } |
||
| 2277 | } |
||
| 2278 | } else { |
||
| 2279 | $list = MessageManager::getAttachmentLinkList($messageId); |
||
| 2280 | } |
||
| 2281 | |||
| 2282 | return $list; |
||
| 2283 | } |
||
| 2284 | |||
| 2285 | /** |
||
| 2286 | * @param array $message |
||
| 2287 | * |
||
| 2288 | * @return string |
||
| 2289 | */ |
||
| 2290 | public static function getPostAttachment($message) |
||
| 2291 | { |
||
| 2292 | $previews = self::getAttachmentPreviewList($message); |
||
| 2293 | |||
| 2294 | if (empty($previews)) { |
||
| 2295 | return ''; |
||
| 2296 | } |
||
| 2297 | |||
| 2298 | return implode('', $previews); |
||
| 2299 | } |
||
| 2300 | |||
| 2301 | /** |
||
| 2302 | * @param array $messages |
||
| 2303 | * |
||
| 2304 | * @return array |
||
| 2305 | */ |
||
| 2306 | public static function formatWallMessages($messages) |
||
| 2307 | { |
||
| 2308 | $data = []; |
||
| 2309 | $users = []; |
||
| 2310 | foreach ($messages as $key => $message) { |
||
| 2311 | $userIdLoop = $message['user_sender_id']; |
||
| 2312 | $userFriendIdLoop = $message['user_receiver_id']; |
||
| 2313 | if (!isset($users[$userIdLoop])) { |
||
| 2314 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
| 2315 | } |
||
| 2316 | |||
| 2317 | if (!isset($users[$userFriendIdLoop])) { |
||
| 2318 | $users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop); |
||
| 2319 | } |
||
| 2320 | |||
| 2321 | $html = self::headerMessagePost( |
||
| 2322 | $users[$userIdLoop], |
||
| 2323 | $users[$userFriendIdLoop], |
||
| 2324 | $message |
||
| 2325 | ); |
||
| 2326 | |||
| 2327 | $data[$key] = $message; |
||
| 2328 | $data[$key]['html'] = $html; |
||
| 2329 | } |
||
| 2330 | |||
| 2331 | return $data; |
||
| 2332 | } |
||
| 2333 | |||
| 2334 | /** |
||
| 2335 | * get html data with OpenGrap passing the URL. |
||
| 2336 | * |
||
| 2337 | * @param $link url |
||
| 2338 | * |
||
| 2339 | * @return string data html |
||
| 2340 | */ |
||
| 2341 | public static function readContentWithOpenGraph($link) |
||
| 2367 | } |
||
| 2368 | |||
| 2369 | /** |
||
| 2370 | * verify if Url Exist - Using Curl. |
||
| 2371 | * |
||
| 2372 | * @param $uri url |
||
| 2373 | * |
||
| 2374 | * @return bool |
||
| 2375 | */ |
||
| 2376 | public static function verifyUrl($uri) |
||
| 2377 | { |
||
| 2378 | $curl = curl_init($uri); |
||
| 2379 | curl_setopt($curl, CURLOPT_FAILONERROR, true); |
||
| 2380 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
||
| 2381 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
| 2382 | curl_setopt($curl, CURLOPT_TIMEOUT, 15); |
||
| 2383 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); |
||
| 2384 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
||
| 2385 | curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); |
||
| 2386 | $response = curl_exec($curl); |
||
| 2387 | curl_close($curl); |
||
| 2388 | if (!empty($response)) { |
||
| 2389 | return true; |
||
| 2390 | } |
||
| 2391 | |||
| 2392 | return false; |
||
| 2393 | } |
||
| 2394 | |||
| 2395 | /** |
||
| 2396 | * Soft delete a message and his chidren. |
||
| 2397 | * |
||
| 2398 | * @param int $id id message to delete |
||
| 2399 | * |
||
| 2400 | * @return bool status query |
||
| 2401 | */ |
||
| 2402 | public static function deleteMessage($id) |
||
| 2403 | { |
||
| 2404 | $id = (int) $id; |
||
| 2405 | $messageInfo = MessageManager::get_message_by_id($id); |
||
| 2406 | if (!empty($messageInfo)) { |
||
| 2407 | // Delete comments too |
||
| 2408 | $messages = MessageManager::getMessagesByParent($id); |
||
| 2409 | if (!empty($messages)) { |
||
| 2410 | foreach ($messages as $message) { |
||
| 2411 | self::deleteMessage($message['id']); |
||
| 2412 | } |
||
| 2413 | } |
||
| 2414 | |||
| 2415 | // Soft delete message |
||
| 2416 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
| 2417 | $statusMessage = MESSAGE_STATUS_WALL_DELETE; |
||
| 2418 | $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' "; |
||
| 2419 | Database::query($sql); |
||
| 2420 | |||
| 2421 | MessageManager::delete_message_attachment_file($id, $messageInfo['user_sender_id']); |
||
| 2422 | MessageManager::delete_message_attachment_file($id, $messageInfo['user_receiver_id']); |
||
| 2423 | |||
| 2424 | return true; |
||
| 2425 | } |
||
| 2426 | |||
| 2427 | return false; |
||
| 2428 | } |
||
| 2429 | |||
| 2430 | /** |
||
| 2431 | * Generate the social block for a user. |
||
| 2432 | * |
||
| 2433 | * @param Template $template |
||
| 2434 | * @param int $userId The user id |
||
| 2435 | * @param string $groupBlock Optional. Highlight link possible values: |
||
| 2436 | * group_add, home, messages, messages_inbox, messages_compose, |
||
| 2437 | * messages_outbox, invitations, shared_profile, friends, groups, search |
||
| 2438 | * @param int $groupId Optional. Group ID |
||
| 2439 | * @param bool $show_full_profile |
||
| 2440 | * |
||
| 2441 | * @return string The HTML code with the social block |
||
| 2442 | */ |
||
| 2443 | public static function setSocialUserBlock( |
||
| 2552 | } |
||
| 2553 | |||
| 2554 | /** |
||
| 2555 | * @param int $user_id |
||
| 2556 | * @param $link_shared |
||
| 2557 | * @param $show_full_profile |
||
| 2558 | * |
||
| 2559 | * @return string |
||
| 2560 | */ |
||
| 2561 | public static function listMyFriends($user_id, $link_shared, $show_full_profile) |
||
| 2562 | { |
||
| 2563 | //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT |
||
| 2564 | $friends = self::get_friends($user_id, USER_RELATION_TYPE_FRIEND); |
||
| 2565 | $number_of_images = 30; |
||
| 2566 | $number_friends = count($friends); |
||
| 2567 | $friendHtml = ''; |
||
| 2568 | if ($number_friends != 0) { |
||
| 2569 | if ($number_friends > $number_of_images) { |
||
| 2570 | if (api_get_user_id() == $user_id) { |
||
| 2571 | $friendHtml .= ' <span><a href="friends.php">'.get_lang('SeeAll').'</a></span>'; |
||
| 2572 | } else { |
||
| 2573 | $friendHtml .= ' <span>' |
||
| 2574 | .'<a href="'.api_get_path(WEB_CODE_PATH).'social/profile_friends_and_groups.inc.php' |
||
| 2575 | .'?view=friends&height=390&width=610&user_id='.$user_id.'"' |
||
| 2576 | .'class="ajax" data-title="'.get_lang('SeeAll').'" title="'.get_lang('SeeAll').'" >'.get_lang('SeeAll').'</a></span>'; |
||
| 2577 | } |
||
| 2578 | } |
||
| 2579 | |||
| 2580 | $friendHtml .= '<ul class="nav nav-list">'; |
||
| 2581 | $j = 1; |
||
| 2582 | for ($k = 0; $k < $number_friends; $k++) { |
||
| 2583 | if ($j > $number_of_images) { |
||
| 2584 | break; |
||
| 2585 | } |
||
| 2586 | if (isset($friends[$k])) { |
||
| 2587 | $friend = $friends[$k]; |
||
| 2588 | $name_user = api_get_person_name($friend['firstName'], $friend['lastName']); |
||
| 2589 | $user_info_friend = api_get_user_info($friend['friend_user_id'], true); |
||
| 2590 | |||
| 2591 | if ($user_info_friend['user_is_online']) { |
||
| 2592 | $statusIcon = Display::span('', ['class' => 'online_user_in_text']); |
||
| 2593 | } else { |
||
| 2594 | $statusIcon = Display::span('', ['class' => 'offline_user_in_text']); |
||
| 2595 | } |
||
| 2596 | |||
| 2597 | $friendHtml .= '<li>'; |
||
| 2598 | $friendHtml .= '<div>'; |
||
| 2599 | |||
| 2600 | // the height = 92 must be the same in the image_friend_network span style in default.css |
||
| 2601 | $friends_profile = UserManager::getUserPicture( |
||
| 2602 | $friend['friend_user_id'], |
||
| 2603 | USER_IMAGE_SIZE_SMALL |
||
| 2604 | ); |
||
| 2605 | $friendHtml .= '<img src="'.$friends_profile.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'"/>'; |
||
| 2606 | $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared; |
||
| 2607 | $friendHtml .= $statusIcon.'<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'">'.$name_user.'</a>'; |
||
| 2608 | $friendHtml .= '</div>'; |
||
| 2609 | $friendHtml .= '</li>'; |
||
| 2610 | } |
||
| 2611 | $j++; |
||
| 2612 | } |
||
| 2613 | $friendHtml .= '</ul>'; |
||
| 2614 | } else { |
||
| 2615 | $friendHtml .= '<div class="">'.get_lang('NoFriendsInYourContactList').'<br /> |
||
| 2616 | <a class="btn btn-primary" href="'.api_get_path(WEB_PATH).'whoisonline.php"> |
||
| 2617 | <em class="fa fa-search"></em> '.get_lang('TryAndFindSomeFriends').'</a></div>'; |
||
| 2618 | } |
||
| 2619 | |||
| 2620 | $friendHtml = Display::panel($friendHtml, get_lang('SocialFriend').' ('.$number_friends.')'); |
||
| 2621 | |||
| 2622 | return $friendHtml; |
||
| 2623 | } |
||
| 2624 | |||
| 2625 | /** |
||
| 2626 | * @param int $user_id |
||
| 2627 | * @param $link_shared |
||
| 2628 | * @param bool $showLinkToChat |
||
| 2629 | * |
||
| 2630 | * @return string |
||
| 2631 | */ |
||
| 2632 | public static function listMyFriendsBlock($user_id, $link_shared = '', $showLinkToChat = false) |
||
| 2633 | { |
||
| 2634 | //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT |
||
| 2635 | $friends = self::get_friends($user_id, USER_RELATION_TYPE_FRIEND); |
||
| 2636 | $numberFriends = count($friends); |
||
| 2637 | $friendHtml = ''; |
||
| 2638 | |||
| 2639 | if (!empty($numberFriends)) { |
||
| 2640 | $friendHtml .= '<div class="list-group contact-list">'; |
||
| 2641 | $j = 1; |
||
| 2642 | |||
| 2643 | usort( |
||
| 2644 | $friends, |
||
| 2645 | function ($a, $b) { |
||
| 2646 | return strcmp($b['user_info']['user_is_online_in_chat'], $a['user_info']['user_is_online_in_chat']); |
||
| 2647 | } |
||
| 2648 | ); |
||
| 2649 | |||
| 2650 | foreach ($friends as $friend) { |
||
| 2651 | if ($j > $numberFriends) { |
||
| 2652 | break; |
||
| 2653 | } |
||
| 2654 | $name_user = api_get_person_name($friend['firstName'], $friend['lastName']); |
||
| 2655 | $user_info_friend = api_get_user_info($friend['friend_user_id'], true); |
||
| 2656 | |||
| 2657 | $statusIcon = Display::return_icon('statusoffline.png', get_lang('Offline')); |
||
| 2658 | $status = 0; |
||
| 2659 | if (!empty($user_info_friend['user_is_online_in_chat'])) { |
||
| 2660 | $statusIcon = Display::return_icon('statusonline.png', get_lang('Online')); |
||
| 2661 | $status = 1; |
||
| 2662 | } |
||
| 2663 | |||
| 2664 | $friendAvatarMedium = UserManager::getUserPicture( |
||
| 2665 | $friend['friend_user_id'], |
||
| 2666 | USER_IMAGE_SIZE_MEDIUM |
||
| 2667 | ); |
||
| 2668 | $friendAvatarSmall = UserManager::getUserPicture( |
||
| 2669 | $friend['friend_user_id'], |
||
| 2670 | USER_IMAGE_SIZE_SMALL |
||
| 2671 | ); |
||
| 2672 | $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>'; |
||
| 2673 | |||
| 2674 | $relation = self::get_relation_between_contacts( |
||
| 2675 | $friend['friend_user_id'], |
||
| 2676 | api_get_user_id() |
||
| 2677 | ); |
||
| 2678 | |||
| 2679 | if ($showLinkToChat) { |
||
| 2680 | $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">'; |
||
| 2681 | $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
||
| 2682 | $friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
||
| 2683 | } else { |
||
| 2684 | $link_shared = empty($link_shared) ? '' : '&'.$link_shared; |
||
| 2685 | $friendHtml .= '<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'" class="list-group-item">'; |
||
| 2686 | $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
||
| 2687 | $friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
||
| 2688 | } |
||
| 2689 | |||
| 2690 | $friendHtml .= '</a>'; |
||
| 2691 | |||
| 2692 | $j++; |
||
| 2693 | } |
||
| 2694 | $friendHtml .= '</div>'; |
||
| 2695 | } |
||
| 2696 | |||
| 2697 | return $friendHtml; |
||
| 2698 | } |
||
| 2699 | |||
| 2700 | /** |
||
| 2701 | * @param string $urlForm |
||
| 2702 | * |
||
| 2703 | * @return string |
||
| 2704 | */ |
||
| 2705 | public static function getWallForm($urlForm) |
||
| 2706 | { |
||
| 2707 | $userId = isset($_GET['u']) ? '?u='.intval($_GET['u']) : ''; |
||
| 2708 | $form = new FormValidator( |
||
| 2709 | 'social_wall_main', |
||
| 2710 | 'post', |
||
| 2711 | $urlForm.$userId, |
||
| 2712 | null, |
||
| 2713 | ['enctype' => 'multipart/form-data'], |
||
| 2714 | FormValidator::LAYOUT_HORIZONTAL |
||
| 2715 | ); |
||
| 2716 | |||
| 2717 | $socialWallPlaceholder = isset($_GET['u']) ? get_lang('SocialWallWriteNewPostToFriend') : get_lang( |
||
| 2718 | 'SocialWallWhatAreYouThinkingAbout' |
||
| 2719 | ); |
||
| 2720 | |||
| 2721 | $form->addTextarea( |
||
| 2722 | 'social_wall_new_msg_main', |
||
| 2723 | null, |
||
| 2724 | [ |
||
| 2725 | 'placeholder' => $socialWallPlaceholder, |
||
| 2726 | 'cols-size' => [1, 10, 1], |
||
| 2727 | 'aria-label' => $socialWallPlaceholder, |
||
| 2728 | ] |
||
| 2729 | ); |
||
| 2730 | $form->addHtml('<div class="form-group">'); |
||
| 2731 | $form->addHtml('<div class="col-sm-4 col-md-offset-1">'); |
||
| 2732 | $form->addFile('picture', get_lang('UploadFile'), ['custom' => true]); |
||
| 2733 | $form->addHtml('</div>'); |
||
| 2734 | $form->addHtml('<div class="col-sm-6">'); |
||
| 2735 | $form->addButtonSend( |
||
| 2736 | get_lang('Post'), |
||
| 2737 | 'wall_post_button', |
||
| 2738 | false, |
||
| 2739 | [ |
||
| 2740 | 'cols-size' => [1, 10, 1], |
||
| 2741 | 'custom' => true, |
||
| 2742 | ] |
||
| 2743 | ); |
||
| 2744 | $form->addHtml('</div>'); |
||
| 2745 | $form->addHtml('</div>'); |
||
| 2746 | |||
| 2747 | $form->addHidden('url_content', ''); |
||
| 2748 | $html = Display::panel($form->returnForm(), get_lang('SocialWall')); |
||
| 2749 | |||
| 2750 | return $html; |
||
| 2751 | } |
||
| 2752 | |||
| 2753 | /** |
||
| 2754 | * @param int $userId |
||
| 2755 | * @param int $start |
||
| 2756 | * @param int $length |
||
| 2757 | * @param array $threadList |
||
| 2758 | * |
||
| 2759 | * @return array |
||
| 2760 | */ |
||
| 2761 | public static function getMyWallMessages($userId, $start = 0, $length = 10, $threadList = []) |
||
| 2762 | { |
||
| 2763 | $userGroup = new UserGroup(); |
||
| 2764 | $groups = $userGroup->get_groups_by_user($userId, [GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_ADMIN]); |
||
| 2765 | $groupList = []; |
||
| 2766 | if (!empty($groups)) { |
||
| 2767 | $groupList = array_column($groups, 'id'); |
||
| 2768 | } |
||
| 2769 | |||
| 2770 | $friends = self::get_friends($userId, USER_RELATION_TYPE_FRIEND); |
||
| 2771 | $friendList = []; |
||
| 2772 | if (!empty($friends)) { |
||
| 2773 | $friendList = array_column($friends, 'friend_user_id'); |
||
| 2774 | } |
||
| 2775 | |||
| 2776 | $messages = self::getWallMessages( |
||
| 2777 | $userId, |
||
| 2778 | 0, |
||
| 2779 | $groupList, |
||
| 2780 | $friendList, |
||
| 2781 | '', |
||
| 2782 | $start, |
||
| 2783 | $length, |
||
| 2784 | false, |
||
| 2785 | $threadList |
||
| 2786 | ); |
||
| 2787 | |||
| 2788 | $countPost = self::getCountWallMessagesByUser($userId, $groupList, $friendList, $threadList); |
||
| 2789 | $messages = self::formatWallMessages($messages); |
||
| 2790 | |||
| 2791 | $html = ''; |
||
| 2792 | foreach ($messages as $message) { |
||
| 2793 | $post = $message['html']; |
||
| 2794 | $comments = ''; |
||
| 2795 | if ($message['msg_status'] == MESSAGE_STATUS_WALL_POST) { |
||
| 2796 | $comments = self::getWallPostComments($userId, $message); |
||
| 2797 | } |
||
| 2798 | |||
| 2799 | $html .= self::wrapPost($message, $post.$comments); |
||
| 2800 | } |
||
| 2801 | |||
| 2802 | return [ |
||
| 2803 | 'posts' => $html, |
||
| 2804 | 'count' => $countPost, |
||
| 2805 | ]; |
||
| 2806 | } |
||
| 2807 | |||
| 2808 | /** |
||
| 2809 | * @param string $message |
||
| 2810 | * @param string $content |
||
| 2811 | * |
||
| 2812 | * @return string |
||
| 2813 | */ |
||
| 2814 | public static function wrapPost($message, $content) |
||
| 2815 | { |
||
| 2816 | return Display::panel($content, '', |
||
| 2817 | '', |
||
| 2818 | 'default', |
||
| 2819 | '', |
||
| 2820 | 'post_'.$message['id'] |
||
| 2821 | ); |
||
| 2822 | } |
||
| 2823 | |||
| 2824 | /** |
||
| 2825 | * @param int $userId |
||
| 2826 | * |
||
| 2827 | * @return int |
||
| 2828 | */ |
||
| 2829 | public static function getCountWallMessagesByUser($userId, $groupList = [], $friendList = [], $threadList = []) |
||
| 2830 | { |
||
| 2831 | $count = self::getWallMessages( |
||
| 2832 | $userId, |
||
| 2833 | 0, |
||
| 2834 | $groupList, |
||
| 2835 | $friendList, |
||
| 2836 | '', |
||
| 2837 | 0, |
||
| 2838 | 0, |
||
| 2839 | true, |
||
| 2840 | $threadList |
||
| 2841 | ); |
||
| 2842 | |||
| 2843 | return $count; |
||
| 2844 | } |
||
| 2845 | |||
| 2846 | /** |
||
| 2847 | * @param int $userId |
||
| 2848 | * |
||
| 2849 | * @return string |
||
| 2850 | */ |
||
| 2851 | public static function getWallMessagesByUser($userId) |
||
| 2852 | { |
||
| 2853 | $messages = self::getWallMessages($userId); |
||
| 2854 | $messages = self::formatWallMessages($messages); |
||
| 2855 | |||
| 2856 | $html = ''; |
||
| 2857 | foreach ($messages as $message) { |
||
| 2858 | $post = $message['html']; |
||
| 2859 | $comments = self::getWallPostComments($userId, $message); |
||
| 2860 | $html .= self::wrapPost($message, $post.$comments); |
||
| 2861 | } |
||
| 2862 | |||
| 2863 | return $html; |
||
| 2864 | } |
||
| 2865 | |||
| 2866 | /** |
||
| 2867 | * Get HTML code block for user skills. |
||
| 2868 | * |
||
| 2869 | * @param int $userId The user ID |
||
| 2870 | * @param string $orientation |
||
| 2871 | * |
||
| 2872 | * @return string |
||
| 2873 | */ |
||
| 2874 | public static function getSkillBlock($userId, $orientation = 'horizontal') |
||
| 2875 | { |
||
| 2876 | if (Skill::isAllowed($userId, false) === false) { |
||
| 2877 | return ''; |
||
| 2878 | } |
||
| 2879 | |||
| 2880 | $skill = new Skill(); |
||
| 2881 | $ranking = $skill->getUserSkillRanking($userId); |
||
| 2882 | |||
| 2883 | $template = new Template(null, false, false, false, false, false); |
||
| 2884 | $template->assign('ranking', $ranking); |
||
| 2885 | $template->assign('orientation', $orientation); |
||
| 2886 | $template->assign('skills', $skill->getUserSkillsTable($userId, 0, 0, false)['skills']); |
||
| 2887 | $template->assign('user_id', $userId); |
||
| 2888 | $template->assign('show_skills_report_link', api_is_student() || api_is_student_boss() || api_is_drh()); |
||
| 2889 | |||
| 2890 | $skillBlock = $template->get_template('social/skills_block.tpl'); |
||
| 2891 | |||
| 2892 | return $template->fetch($skillBlock); |
||
| 2893 | } |
||
| 2894 | |||
| 2895 | /** |
||
| 2896 | * @param int $user_id |
||
| 2897 | * |
||
| 2898 | * @return string|array |
||
| 2899 | */ |
||
| 2900 | public static function getExtraFieldBlock($user_id, $isArray = false) |
||
| 2901 | { |
||
| 2902 | $fieldVisibility = api_get_configuration_value('profile_fields_visibility'); |
||
| 2903 | $fieldVisibilityKeys = []; |
||
| 2904 | if (isset($fieldVisibility['options'])) { |
||
| 2905 | $fieldVisibility = $fieldVisibility['options']; |
||
| 2906 | $fieldVisibilityKeys = array_keys($fieldVisibility); |
||
| 2907 | } |
||
| 2908 | |||
| 2909 | $t_ufo = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS); |
||
| 2910 | $extra_user_data = UserManager::get_extra_user_data($user_id); |
||
| 2911 | |||
| 2912 | $extra_information = ''; |
||
| 2913 | if (is_array($extra_user_data) && count($extra_user_data) > 0) { |
||
| 2914 | $extra_information_value = ''; |
||
| 2915 | $extraField = new ExtraField('user'); |
||
| 2916 | $listType = []; |
||
| 2917 | $extraFieldItem = []; |
||
| 2918 | foreach ($extra_user_data as $key => $data) { |
||
| 2919 | if (empty($data)) { |
||
| 2920 | continue; |
||
| 2921 | } |
||
| 2922 | if (in_array($key, $fieldVisibilityKeys) && $fieldVisibility[$key] === false) { |
||
| 2923 | continue; |
||
| 2924 | } |
||
| 2925 | |||
| 2926 | // Avoiding parameters |
||
| 2927 | if (in_array( |
||
| 2928 | $key, |
||
| 2929 | [ |
||
| 2930 | 'mail_notify_invitation', |
||
| 2931 | 'mail_notify_message', |
||
| 2932 | 'mail_notify_group_message', |
||
| 2933 | ] |
||
| 2934 | )) { |
||
| 2935 | continue; |
||
| 2936 | } |
||
| 2937 | // get display text, visibility and type from user_field table |
||
| 2938 | $field_variable = str_replace('extra_', '', $key); |
||
| 2939 | |||
| 2940 | $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable( |
||
| 2941 | $field_variable |
||
| 2942 | ); |
||
| 2943 | |||
| 2944 | if (in_array($extraFieldInfo['variable'], ['skype', 'linkedin_url'])) { |
||
| 2945 | continue; |
||
| 2946 | } |
||
| 2947 | |||
| 2948 | // if is not visible skip |
||
| 2949 | if ($extraFieldInfo['visible_to_self'] != 1) { |
||
| 2950 | continue; |
||
| 2951 | } |
||
| 2952 | |||
| 2953 | // if is not visible to others skip also |
||
| 2954 | if ($extraFieldInfo['visible_to_others'] != 1) { |
||
| 2955 | continue; |
||
| 2956 | } |
||
| 2957 | |||
| 2958 | if (is_array($data)) { |
||
| 2959 | switch ($extraFieldInfo['field_type']) { |
||
| 2960 | case ExtraField::FIELD_TYPE_RADIO: |
||
| 2961 | $objEfOption = new ExtraFieldOption('user'); |
||
| 2962 | $value = $data['extra_'.$extraFieldInfo['variable']]; |
||
| 2963 | $optionInfo = $objEfOption->get_field_option_by_field_and_option( |
||
| 2964 | $extraFieldInfo['id'], |
||
| 2965 | $value |
||
| 2966 | ); |
||
| 2967 | |||
| 2968 | if ($optionInfo && isset($optionInfo[0])) { |
||
| 2969 | $optionInfo = $optionInfo[0]; |
||
| 2970 | $extraFieldItem = [ |
||
| 2971 | 'variable' => $extraFieldInfo['variable'], |
||
| 2972 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2973 | 'value' => $optionInfo['display_text'], |
||
| 2974 | ]; |
||
| 2975 | } else { |
||
| 2976 | $extraFieldItem = [ |
||
| 2977 | 'variable' => $extraFieldInfo['variable'], |
||
| 2978 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2979 | 'value' => implode(',', $data), |
||
| 2980 | ]; |
||
| 2981 | } |
||
| 2982 | break; |
||
| 2983 | default: |
||
| 2984 | $extra_information_value .= |
||
| 2985 | '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).' ' |
||
| 2986 | .' '.implode(',', $data).'</li>'; |
||
| 2987 | $extraFieldItem = [ |
||
| 2988 | 'variable' => $extraFieldInfo['variable'], |
||
| 2989 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2990 | 'value' => implode(',', $data), |
||
| 2991 | ]; |
||
| 2992 | break; |
||
| 2993 | } |
||
| 2994 | } else { |
||
| 2995 | switch ($extraFieldInfo['field_type']) { |
||
| 2996 | case ExtraField::FIELD_TYPE_RADIO: |
||
| 2997 | $objEfOption = new ExtraFieldOption('user'); |
||
| 2998 | $optionInfo = $objEfOption->get_field_option_by_field_and_option($extraFieldInfo['id'], $extraFieldInfo['value']); |
||
| 2999 | break; |
||
| 3000 | case ExtraField::FIELD_TYPE_GEOLOCALIZATION_COORDINATES: |
||
| 3001 | case ExtraField::FIELD_TYPE_GEOLOCALIZATION: |
||
| 3002 | $data = explode('::', $data); |
||
| 3003 | $data = $data[0]; |
||
| 3004 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '.$data.'</li>'; |
||
| 3005 | $extraFieldItem = [ |
||
| 3006 | 'variable' => $extraFieldInfo['variable'], |
||
| 3007 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 3008 | 'value' => $data, |
||
| 3009 | ]; |
||
| 3010 | break; |
||
| 3011 | case ExtraField::FIELD_TYPE_DOUBLE_SELECT: |
||
| 3012 | $id_options = explode('::', $data); |
||
| 3013 | $value_options = []; |
||
| 3014 | // get option display text from user_field_options table |
||
| 3015 | foreach ($id_options as $id_option) { |
||
| 3016 | $sql = "SELECT display_text |
||
| 3017 | FROM $t_ufo |
||
| 3018 | WHERE id = '$id_option'"; |
||
| 3019 | $res_options = Database::query($sql); |
||
| 3020 | $row_options = Database::fetch_row($res_options); |
||
| 3021 | $value_options[] = $row_options[0]; |
||
| 3022 | } |
||
| 3023 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': ' |
||
| 3024 | .' '.implode(' ', $value_options).'</li>'; |
||
| 3025 | $extraFieldItem = [ |
||
| 3026 | 'variable' => $extraFieldInfo['variable'], |
||
| 3027 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 3028 | 'value' => $value_options, |
||
| 3029 | ]; |
||
| 3030 | break; |
||
| 3031 | case ExtraField::FIELD_TYPE_TAG: |
||
| 3032 | $user_tags = UserManager::get_user_tags($user_id, $extraFieldInfo['id']); |
||
| 3033 | |||
| 3034 | $tag_tmp = ''; |
||
| 3035 | foreach ($user_tags as $tags) { |
||
| 3036 | $tag_tmp .= '<a class="label label_tag"' |
||
| 3037 | .' href="'.api_get_path(WEB_PATH).'main/social/search.php?q='.$tags['tag'].'">' |
||
| 3038 | .$tags['tag'] |
||
| 3039 | .'</a>'; |
||
| 3040 | } |
||
| 3041 | if (is_array($user_tags) && count($user_tags) > 0) { |
||
| 3042 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': ' |
||
| 3043 | .' '.$tag_tmp.'</li>'; |
||
| 3044 | } |
||
| 3045 | $extraFieldItem = [ |
||
| 3046 | 'variable' => $extraFieldInfo['variable'], |
||
| 3047 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 3048 | 'value' => $tag_tmp, |
||
| 3049 | ]; |
||
| 3050 | break; |
||
| 3051 | case ExtraField::FIELD_TYPE_SOCIAL_PROFILE: |
||
| 3052 | $icon_path = UserManager::get_favicon_from_url($data); |
||
| 3053 | if (self::verifyUrl($icon_path) == false) { |
||
| 3054 | break; |
||
| 3055 | } |
||
| 3056 | $bottom = '0.2'; |
||
| 3057 | //quick hack for hi5 |
||
| 3058 | $domain = parse_url($icon_path, PHP_URL_HOST); |
||
| 3059 | if ($domain == 'www.hi5.com' || $domain == 'hi5.com') { |
||
| 3060 | $bottom = '-0.8'; |
||
| 3061 | } |
||
| 3062 | $data = '<a href="'.$data.'">' |
||
| 3063 | .'<img src="'.$icon_path.'" alt="icon"' |
||
| 3064 | .' style="margin-right:0.5em;margin-bottom:'.$bottom.'em;" />' |
||
| 3065 | .$extraFieldInfo['display_text'] |
||
| 3066 | .'</a>'; |
||
| 3067 | $extra_information_value .= '<li class="list-group-item">'.$data.'</li>'; |
||
| 3068 | $extraFieldItem = [ |
||
| 3069 | 'variable' => $extraFieldInfo['variable'], |
||
| 3070 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 3071 | 'value' => $data, |
||
| 3072 | ]; |
||
| 3073 | break; |
||
| 3074 | case ExtraField::FIELD_TYPE_SELECT_WITH_TEXT_FIELD: |
||
| 3075 | $parsedData = explode('::', $data); |
||
| 3076 | |||
| 3077 | if (!$parsedData) { |
||
| 3078 | break; |
||
| 3079 | } |
||
| 3080 | |||
| 3081 | $objEfOption = new ExtraFieldOption('user'); |
||
| 3082 | $optionInfo = $objEfOption->get($parsedData[0]); |
||
| 3083 | |||
| 3084 | $extra_information_value .= '<li class="list-group-item">' |
||
| 3085 | .$optionInfo['display_text'].': ' |
||
| 3086 | .$parsedData[1].'</li>'; |
||
| 3087 | $extraFieldItem = [ |
||
| 3088 | 'variable' => $extraFieldInfo['variable'], |
||
| 3089 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 3090 | 'value' => $parsedData[1], |
||
| 3091 | ]; |
||
| 3092 | break; |
||
| 3093 | case ExtraField::FIELD_TYPE_TRIPLE_SELECT: |
||
| 3094 | $optionIds = explode(';', $data); |
||
| 3095 | $optionValues = []; |
||
| 3096 | |||
| 3097 | foreach ($optionIds as $optionId) { |
||
| 3098 | $objEfOption = new ExtraFieldOption('user'); |
||
| 3099 | $optionInfo = $objEfOption->get($optionId); |
||
| 3100 | |||
| 3101 | $optionValues[] = $optionInfo['display_text']; |
||
| 3102 | } |
||
| 3103 | $extra_information_value .= '<li class="list-group-item">' |
||
| 3104 | .ucfirst($extraFieldInfo['display_text']).': ' |
||
| 3105 | .implode(' ', $optionValues).'</li>'; |
||
| 3106 | $extraFieldItem = [ |
||
| 3107 | 'variable' => $extraFieldInfo['variable'], |
||
| 3108 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 3109 | 'value' => implode(' ', $optionValues), |
||
| 3110 | ]; |
||
| 3111 | break; |
||
| 3112 | default: |
||
| 3113 | // Ofaj |
||
| 3114 | // Converts "Date of birth" into "age" |
||
| 3115 | if ($key === 'terms_datedenaissance') { |
||
| 3116 | $dataArray = date_to_str_ago($data, 'UTC', true); |
||
| 3117 | $dataToString = isset($dataArray['years']) && !empty($dataArray['years']) ? $dataArray['years'] : 0; |
||
| 3118 | if (!empty($dataToString)) { |
||
| 3119 | $data = $dataToString; |
||
| 3120 | $extraFieldInfo['display_text'] = get_lang('Age'); |
||
| 3121 | } |
||
| 3122 | } |
||
| 3123 | |||
| 3124 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '.$data.'</li>'; |
||
| 3125 | $extraFieldItem = [ |
||
| 3126 | 'variable' => $extraFieldInfo['variable'], |
||
| 3127 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 3128 | 'value' => $data, |
||
| 3129 | ]; |
||
| 3130 | break; |
||
| 3131 | } |
||
| 3132 | } |
||
| 3133 | |||
| 3134 | $listType[] = $extraFieldItem; |
||
| 3135 | } |
||
| 3136 | |||
| 3137 | if ($isArray) { |
||
| 3138 | return $listType; |
||
| 3139 | } else { |
||
| 3140 | // if there are information to show |
||
| 3141 | if (!empty($extra_information_value)) { |
||
| 3142 | $extra_information_value = '<ul class="list-group">'.$extra_information_value.'</ul>'; |
||
| 3143 | $extra_information .= Display::panelCollapse( |
||
| 3144 | get_lang('ExtraInformation'), |
||
| 3145 | $extra_information_value, |
||
| 3146 | 'sn-extra-information', |
||
| 3147 | null, |
||
| 3148 | 'sn-extra-accordion', |
||
| 3149 | 'sn-extra-collapse' |
||
| 3150 | ); |
||
| 3151 | } |
||
| 3152 | } |
||
| 3153 | } |
||
| 3154 | |||
| 3155 | return $extra_information; |
||
| 3156 | } |
||
| 3157 | |||
| 3158 | /** |
||
| 3159 | * @param string $url |
||
| 3160 | */ |
||
| 3161 | public static function handlePosts($url) |
||
| 3192 | } |
||
| 3193 | } |
||
| 3194 | |||
| 3195 | /** |
||
| 3196 | * @param int $countPost |
||
| 3197 | * @param array $htmlHeadXtra |
||
| 3198 | */ |
||
| 3199 | public static function getScrollJs($countPost, &$htmlHeadXtra) |
||
| 3200 | { |
||
| 3201 | // $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php'; |
||
| 3202 | $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php'; |
||
| 3203 | $javascriptDir = api_get_path(LIBRARY_PATH).'javascript/'; |
||
| 3204 | $locale = api_get_language_isocode(); |
||
| 3205 | |||
| 3206 | // Add Jquery scroll pagination plugin |
||
| 3207 | $htmlHeadXtra[] = api_get_js('jscroll/jquery.jscroll.js'); |
||
| 3208 | // Add Jquery Time ago plugin |
||
| 3209 | $htmlHeadXtra[] = api_get_asset('jquery-timeago/jquery.timeago.js'); |
||
| 3210 | $timeAgoLocaleDir = $javascriptDir.'jquery-timeago/locales/jquery.timeago.'.$locale.'.js'; |
||
| 3211 | if (file_exists($timeAgoLocaleDir)) { |
||
| 3212 | $htmlHeadXtra[] = api_get_js('jquery-timeago/locales/jquery.timeago.'.$locale.'.js'); |
||
| 3213 | } |
||
| 3214 | |||
| 3215 | if ($countPost > self::DEFAULT_WALL_POSTS) { |
||
| 3216 | $htmlHeadXtra[] = '<script> |
||
| 3217 | $(function() { |
||
| 3218 | var container = $("#wallMessages"); |
||
| 3219 | container.jscroll({ |
||
| 3220 | loadingHtml: "<div class=\"well_border\">'.get_lang('Loading').' </div>", |
||
| 3221 | nextSelector: "a.nextPage:last", |
||
| 3222 | contentSelector: "", |
||
| 3223 | callback: timeAgo |
||
| 3224 | }); |
||
| 3225 | }); |
||
| 3226 | </script>'; |
||
| 3227 | } |
||
| 3228 | |||
| 3229 | $htmlHeadXtra[] = '<script> |
||
| 3230 | function deleteMessage(id) |
||
| 3231 | { |
||
| 3232 | $.ajax({ |
||
| 3233 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 3234 | success: function (result) { |
||
| 3235 | if (result) { |
||
| 3236 | $("#message_" + id).parent().parent().parent().parent().html(result); |
||
| 3237 | } |
||
| 3238 | } |
||
| 3239 | }); |
||
| 3240 | } |
||
| 3241 | |||
| 3242 | function deleteComment(id) |
||
| 3243 | { |
||
| 3244 | $.ajax({ |
||
| 3245 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 3246 | success: function (result) { |
||
| 3247 | if (result) { |
||
| 3248 | $("#message_" + id).parent().parent().parent().html(result); |
||
| 3249 | } |
||
| 3250 | } |
||
| 3251 | }); |
||
| 3252 | } |
||
| 3253 | |||
| 3254 | function submitComment(messageId) |
||
| 3255 | { |
||
| 3256 | var data = $("#form_comment_"+messageId).serializeArray(); |
||
| 3257 | $.ajax({ |
||
| 3258 | type : "POST", |
||
| 3259 | url: "'.$socialAjaxUrl.'?a=send_comment" + "&id=" + messageId, |
||
| 3260 | data: data, |
||
| 3261 | success: function (result) { |
||
| 3262 | if (result) { |
||
| 3263 | $("#post_" + messageId + " textarea").val(""); |
||
| 3264 | $("#post_" + messageId + " .sub-mediapost").prepend(result); |
||
| 3265 | $("#post_" + messageId + " .sub-mediapost").append( |
||
| 3266 | $(\'<div id=result_\' + messageId +\'>'.addslashes(get_lang('Saved')).'</div>\') |
||
| 3267 | ); |
||
| 3268 | |||
| 3269 | $("#result_" + messageId + "").fadeIn("fast", function() { |
||
| 3270 | $("#result_" + messageId + "").delay(1000).fadeOut("fast", function() { |
||
| 3271 | $(this).remove(); |
||
| 3272 | }); |
||
| 3273 | }); |
||
| 3274 | } |
||
| 3275 | } |
||
| 3276 | }); |
||
| 3277 | } |
||
| 3278 | |||
| 3279 | $(function() { |
||
| 3280 | timeAgo(); |
||
| 3281 | |||
| 3282 | /*$(".delete_message").on("click", function() { |
||
| 3283 | var id = $(this).attr("id"); |
||
| 3284 | id = id.split("_")[1]; |
||
| 3285 | $.ajax({ |
||
| 3286 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 3287 | success: function (result) { |
||
| 3288 | if (result) { |
||
| 3289 | $("#message_" + id).parent().parent().parent().parent().html(result); |
||
| 3290 | } |
||
| 3291 | } |
||
| 3292 | }); |
||
| 3293 | }); |
||
| 3294 | |||
| 3295 | |||
| 3296 | $(".delete_comment").on("click", function() { |
||
| 3297 | var id = $(this).attr("id"); |
||
| 3298 | id = id.split("_")[1]; |
||
| 3299 | $.ajax({ |
||
| 3300 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 3301 | success: function (result) { |
||
| 3302 | if (result) { |
||
| 3303 | $("#message_" + id).parent().parent().parent().html(result); |
||
| 3304 | } |
||
| 3305 | } |
||
| 3306 | }); |
||
| 3307 | }); |
||
| 3308 | */ |
||
| 3309 | }); |
||
| 3310 | |||
| 3311 | function timeAgo() { |
||
| 3312 | $(".timeago").timeago(); |
||
| 3313 | } |
||
| 3314 | </script>'; |
||
| 3315 | } |
||
| 3316 | |||
| 3317 | /** |
||
| 3318 | * @param int $userId |
||
| 3319 | * @param int $countPost |
||
| 3320 | * |
||
| 3321 | * @return string |
||
| 3322 | */ |
||
| 3323 | public static function getAutoExtendLink($userId, $countPost) |
||
| 3324 | { |
||
| 3325 | $userId = (int) $userId; |
||
| 3326 | $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php'; |
||
| 3327 | $socialAutoExtendLink = ''; |
||
| 3328 | if ($countPost > self::DEFAULT_WALL_POSTS) { |
||
| 3329 | $socialAutoExtendLink = Display::url( |
||
| 3330 | get_lang('SeeMore'), |
||
| 3331 | $socialAjaxUrl.'?u='.$userId.'&a=list_wall_message&start='. |
||
| 3332 | self::DEFAULT_WALL_POSTS.'&length='.self::DEFAULT_SCROLL_NEW_POST, |
||
| 3333 | [ |
||
| 3334 | 'class' => 'nextPage next', |
||
| 3335 | ] |
||
| 3336 | ); |
||
| 3337 | } |
||
| 3338 | |||
| 3339 | return $socialAutoExtendLink; |
||
| 3340 | } |
||
| 3341 | |||
| 3342 | /** |
||
| 3343 | * @param int $userId |
||
| 3344 | * |
||
| 3345 | * @return array |
||
| 3346 | */ |
||
| 3347 | public static function getThreadList($userId) |
||
| 3348 | { |
||
| 3349 | $forumCourseId = api_get_configuration_value('global_forums_course_id'); |
||
| 3350 | |||
| 3351 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
||
| 3352 | |||
| 3353 | $threads = []; |
||
| 3354 | if (!empty($forumCourseId)) { |
||
| 3355 | $courseInfo = api_get_course_info_by_id($forumCourseId); |
||
| 3356 | getNotificationsPerUser($userId, true, $forumCourseId); |
||
| 3357 | $notification = Session::read('forum_notification'); |
||
| 3358 | Session::erase('forum_notification'); |
||
| 3359 | |||
| 3360 | $threadUrlBase = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
||
| 3361 | 'cidReq' => $courseInfo['code'], |
||
| 3362 | ]).'&'; |
||
| 3363 | if (isset($notification['thread']) && !empty($notification['thread'])) { |
||
| 3364 | $threadList = array_filter(array_unique($notification['thread'])); |
||
| 3365 | $em = Database::getManager(); |
||
| 3366 | $repo = $em->getRepository('ChamiloCourseBundle:CForumThread'); |
||
| 3367 | foreach ($threadList as $threadId) { |
||
| 3368 | /** @var \Chamilo\CourseBundle\Entity\CForumThread $thread */ |
||
| 3369 | $thread = $repo->find($threadId); |
||
| 3370 | if ($thread) { |
||
| 3371 | $threadUrl = $threadUrlBase.http_build_query([ |
||
| 3372 | 'forum' => $thread->getForumId(), |
||
| 3373 | 'thread' => $thread->getIid(), |
||
| 3374 | ]); |
||
| 3375 | $threads[] = [ |
||
| 3376 | 'id' => $threadId, |
||
| 3377 | 'url' => Display::url( |
||
| 3378 | $thread->getThreadTitle(), |
||
| 3379 | $threadUrl |
||
| 3380 | ), |
||
| 3381 | 'name' => Display::url( |
||
| 3382 | $thread->getThreadTitle(), |
||
| 3383 | $threadUrl |
||
| 3384 | ), |
||
| 3385 | 'description' => '', |
||
| 3386 | ]; |
||
| 3387 | } |
||
| 3388 | } |
||
| 3389 | } |
||
| 3390 | } |
||
| 3391 | |||
| 3392 | return $threads; |
||
| 3393 | } |
||
| 3394 | |||
| 3395 | /** |
||
| 3396 | * @param int $userId |
||
| 3397 | * |
||
| 3398 | * @return string |
||
| 3399 | */ |
||
| 3400 | public static function getGroupBlock($userId) |
||
| 3531 | } |
||
| 3532 | |||
| 3533 | /** |
||
| 3534 | * Returns the formatted header message post. |
||
| 3535 | * |
||
| 3536 | * @param int $authorInfo |
||
| 3537 | * @param int $receiverInfo |
||
| 3538 | * @param array $message Message data |
||
| 3539 | * |
||
| 3540 | * @return string $html The formatted header message post |
||
| 3541 | */ |
||
| 3542 | private static function headerMessagePost($authorInfo, $receiverInfo, $message) |
||
| 3642 | } |
||
| 3643 | } |
||
| 3644 |