BxBaseServiceConnections.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. $aProfile = BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getInfo();
  94. if(empty($aProfile) || !is_array($aProfile))
  95. return false;
  96. $aProfileInfo = BxDolService::call($aProfile['type'], 'get_content_info_by_id', array($aProfile['content_id']));
  97. if(empty($aProfileInfo) || !is_array($aProfileInfo))
  98. return false;
  99. if((int)$aProfileInfo['public_subscriptions'] == 0 && $aProfile['id'] != bx_get_logged_profile_id())
  100. return false;
  101. $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscriptions');
  102. if (!$oGrid)
  103. return false;
  104. return $oGrid->getCode();
  105. }
  106. /**
  107. * get grid with subscribed me connections
  108. */
  109. public function serviceSubscribedMeTable ()
  110. {
  111. $aProfile = BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getInfo();
  112. if(empty($aProfile) || !is_array($aProfile))
  113. return false;
  114. $aProfileInfo = BxDolService::call($aProfile['type'], 'get_content_info_by_id', array($aProfile['content_id']));
  115. if(empty($aProfileInfo) || !is_array($aProfileInfo))
  116. return false;
  117. if((int)$aProfileInfo['public_subscribed_me'] == 0 && $aProfile['id'] != bx_get_logged_profile_id())
  118. return false;
  119. $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscribed_me');
  120. if (!$oGrid)
  121. return false;
  122. return $oGrid->getCode();
  123. }
  124. /*
  125. * Get notification data for Notifications module.
  126. */
  127. public function serviceGetNotificationsPost($aEvent)
  128. {
  129. $iProfile = (int)$aEvent['object_id'];
  130. $oProfile = BxDolProfile::getInstance($iProfile);
  131. if(!$oProfile)
  132. return array();
  133. return array(
  134. 'entry_sample' => '_sys_profile_sample_single',
  135. 'entry_url' => $oProfile->getUrl(),
  136. 'entry_caption' => $oProfile->getDisplayName(),
  137. 'entry_author' => $oProfile->id(),
  138. 'lang_key' => '_sys_profile_subscription_added',
  139. );
  140. }
  141. }
  142. /** @} */