BxBaseServiceConnections.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. $CNF = &BxDolModule::getInstance($aProfile['type'])->_oConfig->CNF;
  97. if(getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $aProfile['id'] != bx_get_logged_profile_id())
  98. return false;
  99. $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscriptions');
  100. if (!$oGrid)
  101. return false;
  102. return BxDolTemplate::getInstance()->parseHtmlByName('connections_list.html', array(
  103. 'name' => 'subscriptions',
  104. 'content' => $oGrid->getCode()
  105. ));
  106. }
  107. /**
  108. * get grid with subscribed me connections
  109. */
  110. public function serviceSubscribedMeTable ()
  111. {
  112. $aProfile = BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getInfo();
  113. if(empty($aProfile) || !is_array($aProfile))
  114. return false;
  115. $CNF = &BxDolModule::getInstance($aProfile['type'])->_oConfig->CNF;
  116. if(getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on' && $aProfile['id'] != bx_get_logged_profile_id())
  117. return false;
  118. $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscribed_me');
  119. if (!$oGrid)
  120. return false;
  121. return BxDolTemplate::getInstance()->parseHtmlByName('connections_list.html', array(
  122. 'name' => 'subscribers',
  123. 'content' => $oGrid->getCode()
  124. ));
  125. }
  126. /*
  127. * Get notification data for Notifications module - action Subscribe.
  128. */
  129. public function serviceGetNotificationsPost($aEvent)
  130. {
  131. $iProfile = (int)$aEvent['object_id'];
  132. $oProfile = BxDolProfile::getInstance($iProfile);
  133. if(!$oProfile)
  134. return array();
  135. return array(
  136. 'entry_sample' => '_sys_profile_sample_single',
  137. 'entry_url' => $oProfile->getUrl(),
  138. 'entry_caption' => $oProfile->getDisplayName(),
  139. 'entry_author' => $oProfile->id(),
  140. 'lang_key' => '_sys_profile_subscription_added',
  141. );
  142. }
  143. /*
  144. * Get notification data for Notifications module - action Friend.
  145. */
  146. public function serviceGetNotificationsPostFriendship($aEvent)
  147. {
  148. $iProfile = (int)$aEvent['object_id'];
  149. $oProfile = BxDolProfile::getInstance($iProfile);
  150. if(!$oProfile)
  151. return array();
  152. return array(
  153. 'entry_sample' => '_sys_profile_sample_single',
  154. 'entry_url' => $oProfile->getUrl(),
  155. 'entry_caption' => $oProfile->getDisplayName(),
  156. 'entry_author' => $oProfile->id(),
  157. 'lang_key' => '_sys_profile_friendship_added',
  158. );
  159. }
  160. }
  161. /** @} */