BxBaseServiceConnections.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 UnaBaseView UNA 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 number of initiated connections (like "my subscriptions")
  50. * @param $sConnectionsObject connections object to get connections from
  51. * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
  52. * @return number
  53. */
  54. public function serviceGetConnectedContentNum ($sConnectionsObject, $mixedId = 0)
  55. {
  56. $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
  57. if (!$oConnection)
  58. return 0;
  59. if (!$mixedId)
  60. $mixedId = bx_get_logged_profile_id();
  61. $i = 0;
  62. $a = $oConnection->getConnectedContent($mixedId); // get received friend requests
  63. foreach ($a as $iId)
  64. if (BxDolProfile::getInstance($iId))
  65. ++$i;
  66. return $i;
  67. }
  68. /**
  69. * get number of received connections (like "subscribed me")
  70. * @param $sConnectionsObject connections object to get connections from
  71. * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
  72. * @return number
  73. */
  74. public function serviceGetConnectedInitiatorsNum ($sConnectionsObject, $mixedId = 0)
  75. {
  76. $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
  77. if (!$oConnection)
  78. return 0;
  79. if (!$mixedId)
  80. $mixedId = bx_get_logged_profile_id();
  81. $i = 0;
  82. $a = $oConnection->getConnectedInitiators($mixedId); // get received friend requests
  83. foreach ($a as $iId)
  84. if (BxDolProfile::getInstance($iId))
  85. ++$i;
  86. return $i;
  87. }
  88. /**
  89. * get grid with subscriptions connections
  90. */
  91. public function serviceSubscriptionsTable ()
  92. {
  93. $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscriptions');
  94. if (!$oGrid)
  95. return false;
  96. return $oGrid->getCode();
  97. }
  98. /**
  99. * get grid with subscribed me connections
  100. */
  101. public function serviceSubscribedMeTable ()
  102. {
  103. $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscribed_me');
  104. if (!$oGrid)
  105. return false;
  106. return $oGrid->getCode();
  107. }
  108. /*
  109. * Get notification data for Notifications module.
  110. */
  111. public function serviceGetNotificationsPost($aEvent)
  112. {
  113. $iProfile = (int)$aEvent['object_id'];
  114. $oProfile = BxDolProfile::getInstance($iProfile);
  115. if(!$oProfile)
  116. return array();
  117. return array(
  118. 'entry_sample' => '_sys_profile_sample_single',
  119. 'entry_url' => $oProfile->getUrl(),
  120. 'entry_caption' => $oProfile->getDisplayName(),
  121. 'entry_author' => $oProfile->id(),
  122. 'lang_key' => '_sys_profile_subscription_added',
  123. );
  124. }
  125. }
  126. /** @} */