BxBaseServiceConnections.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCoreBaseRepresentation UNA Core Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services for connections.
  11. */
  12. class BxBaseServiceConnections extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. /**
  19. * get grid with friends connections
  20. */
  21. public function serviceConnectionsTable ()
  22. {
  23. $oGrid = BxDolGrid::getObjectInstance('sys_grid_connections');
  24. if (!$oGrid)
  25. return false;
  26. return $oGrid->getCode();
  27. }
  28. /**
  29. * get number of received unconfirmed connections (friend requests)
  30. * @param $sConnectionsObject connections object to get unconfirmed connections from
  31. * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
  32. * @return number
  33. */
  34. public function serviceGetUnconfirmedConnectionsNum ($sConnectionsObject, $mixedId = 0)
  35. {
  36. $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
  37. if (!$oConnection)
  38. return 0;
  39. if (!$mixedId)
  40. $mixedId = bx_get_logged_profile_id();
  41. $i = 0;
  42. $a = $oConnection->getConnectedInitiators($mixedId, 0); // get received friend requests
  43. foreach ($a as $iId)
  44. if (BxDolProfile::getInstance($iId))
  45. ++$i;
  46. return $i;
  47. }
  48. /*
  49. * Get notification data for Notifications module.
  50. */
  51. public function serviceGetNotificationsPost($aEvent)
  52. {
  53. $iProfile = (int)$aEvent['object_id'];
  54. $oProfile = BxDolProfile::getInstance($iProfile);
  55. if(!$oProfile)
  56. return array();
  57. return array(
  58. 'entry_sample' => '_sys_profile_sample_single',
  59. 'entry_url' => $oProfile->getUrl(),
  60. 'entry_caption' => $oProfile->getDisplayName(),
  61. 'entry_author' => $oProfile->id(),
  62. 'lang_key' => '_sys_profile_subscription_added',
  63. );
  64. }
  65. }
  66. /** @} */