platform/plugins/Users/handlers/Users/contact/response/contacts.php - Q Platform
Show:

File: platform/plugins/Users/handlers/Users/contact/response/contacts.php

  1. <?php
  2.  
  3. /**
  4. * @module Users
  5. */
  6.  
  7. /**
  8. * Used by HTTP clients to fetch one more more contacts
  9. * @class HTTP Users contacts
  10. * @method GET/labels
  11. * @param {array} [$params] Parameters that can come from the request
  12. * @param {string|array} [$params.userIds] The users whose labels to fetch. Can be a comma-separated string
  13. * @param {string|array} [$params.contactUserIds] Optionally filter by contact users. Can be a comma-separated string
  14. * @param {string|array} [$params.labels] Optionally filter by specific labels, or label prefixes ending in "/". Can be a comma-separated string
  15. * @return {array} An array of Users_Label objects.
  16. */
  17. function Users_contact_response_contacts($params = array())
  18. {
  19. $req = array_merge($_REQUEST, $params);
  20. if (!isset($req['userId']) and !isset($req['userIds'])) {
  21. throw new Q_Exception_RequiredField(array(
  22. 'field' => 'userId'
  23. ), 'userId');
  24. }
  25. $userIds = isset($req['userIds']) ? $req['userIds'] : array($req['userId']);
  26. if (is_string($userIds)) {
  27. $userIds = explode(",", $userIds);
  28. }
  29. if (isset($req['labels'])) {
  30. $labels = $req['labels'];
  31. } else if (isset($req['label'])) {
  32. $labels = array($req['label']);
  33. } else {
  34. $labels = null;
  35. }
  36. if (isset($labels)) {
  37. if (is_string($labels)) {
  38. $labels = explode(",", $labels);
  39. }
  40. }
  41. if (isset($req['contactUserIds'])) {
  42. $contactUserIds = $req['contactUserIds'];
  43. if (is_string($userIds)) {
  44. $contactUserIds = explode(",", $contactUserIds);
  45. }
  46. }
  47. $contacts = array();
  48. if (isset($req['batch'])) {
  49. // expects batch format, i.e. $userIds, $labels and $contactUserIds
  50. foreach ($userIds as $i => $userId) {
  51. $contact = new Users_Contact();
  52. $contact->userId = $userId;
  53. $contact->label = $labels[$i];
  54. $contact->contactUserId = $contactUserIds[$i];
  55. $contacts[] = $contact->retrieve() ? $contact : null;
  56. }
  57. } else {
  58. $opt = array();
  59. if (isset($contactUserIds)) {
  60. $opt['contactUserId'] = $contactUserIds;
  61. }
  62. foreach ($userIds as $i => $userId) {
  63. $contacts = array_merge($contacts, Users_Contact::fetch($userId, $labels, $opt));
  64. }
  65. }
  66. return Q_Response::setSlot('contacts', Db::exportArray($contacts));
  67. }