BxBaseServiceConnections.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. public function serviceGetLiveUpdatesUnconfirmedConnections($sModule, $sConnectionsObject, $aMenuItemParent, $aMenuItemChild, $iCount = 0)
  49. {
  50. $iProfile = bx_get_logged_profile_id();
  51. $oProfile = BxDolProfile::getInstance($iProfile);
  52. if(!$oProfile || $oProfile->getModule() != $sModule)
  53. return false;
  54. $iCountNew = $this->serviceGetUnconfirmedConnectionsNum($sConnectionsObject, $iProfile);
  55. if($iCountNew <= $iCount)
  56. return false;
  57. return array(
  58. 'count' => $iCountNew, // required
  59. 'method' => 'bx_menu_show_live_update(oData)', // required
  60. 'data' => array(
  61. 'code' => BxDolTemplate::getInstance()->parseHtmlByName('menu_item_addon.html', array(
  62. 'content' => '{count}'
  63. )),
  64. 'mi_parent' => $aMenuItemParent,
  65. 'mi_child' => $aMenuItemChild
  66. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  67. );
  68. }
  69. /**
  70. * get number of initiated connections (like "my subscriptions")
  71. * @param $sConnectionsObject connections object to get connections from
  72. * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
  73. * @return number
  74. */
  75. public function serviceGetConnectedContentNum ($sConnectionsObject, $mixedId = 0)
  76. {
  77. $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
  78. if (!$oConnection)
  79. return 0;
  80. if (!$mixedId)
  81. $mixedId = bx_get_logged_profile_id();
  82. $i = 0;
  83. $a = $oConnection->getConnectedContent($mixedId); // get received friend requests
  84. foreach ($a as $iId)
  85. if (BxDolProfile::getInstance($iId))
  86. ++$i;
  87. return $i;
  88. }
  89. /**
  90. * get number of received connections (like "subscribed me")
  91. * @param $sConnectionsObject connections object to get connections from
  92. * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
  93. * @return number
  94. */
  95. public function serviceGetConnectedInitiatorsNum ($sConnectionsObject, $mixedId = 0)
  96. {
  97. $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
  98. if (!$oConnection)
  99. return 0;
  100. if (!$mixedId)
  101. $mixedId = bx_get_logged_profile_id();
  102. $i = 0;
  103. $a = $oConnection->getConnectedInitiators($mixedId); // get received friend requests
  104. foreach ($a as $iId)
  105. if (BxDolProfile::getInstance($iId))
  106. ++$i;
  107. return $i;
  108. }
  109. /**
  110. * get grid with subscriptions connections
  111. */
  112. public function serviceSubscriptionsTable ()
  113. {
  114. $aProfile = BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getInfo();
  115. if(empty($aProfile) || !is_array($aProfile))
  116. return false;
  117. $CNF = &BxDolModule::getInstance($aProfile['type'])->_oConfig->CNF;
  118. if(getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $aProfile['id'] != bx_get_logged_profile_id())
  119. return false;
  120. $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscriptions');
  121. if (!$oGrid)
  122. return false;
  123. return BxDolTemplate::getInstance()->parseHtmlByName('connections_list.html', array(
  124. 'name' => 'subscriptions',
  125. 'content' => $oGrid->getCode()
  126. ));
  127. }
  128. /**
  129. * get grid with subscribed me connections
  130. */
  131. public function serviceSubscribedMeTable ()
  132. {
  133. $aProfile = BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getInfo();
  134. if(empty($aProfile) || !is_array($aProfile))
  135. return false;
  136. $CNF = &BxDolModule::getInstance($aProfile['type'])->_oConfig->CNF;
  137. if(getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on' && $aProfile['id'] != bx_get_logged_profile_id())
  138. return false;
  139. $oGrid = BxDolGrid::getObjectInstance('sys_grid_subscribed_me');
  140. if (!$oGrid)
  141. return false;
  142. return BxDolTemplate::getInstance()->parseHtmlByName('connections_list.html', array(
  143. 'name' => 'subscribers',
  144. 'content' => $oGrid->getCode()
  145. ));
  146. }
  147. /*
  148. * Get notification data for Notifications module - action Subscribe.
  149. */
  150. public function serviceGetNotificationsPost($aEvent)
  151. {
  152. $iProfile = (int)$aEvent['object_id'];
  153. $oProfile = BxDolProfile::getInstance($iProfile);
  154. if(!$oProfile)
  155. return array();
  156. return array(
  157. 'entry_sample' => '_sys_profile_sample_single',
  158. 'entry_url' => $oProfile->getUrl(),
  159. 'entry_caption' => $oProfile->getDisplayName(),
  160. 'entry_author' => $oProfile->id(),
  161. 'lang_key' => '_sys_profile_subscription_added',
  162. );
  163. }
  164. /*
  165. * Get notification data for Notifications module - action Friend.
  166. */
  167. public function serviceGetNotificationsPostFriendship($aEvent)
  168. {
  169. $iProfile = (int)$aEvent['object_id'];
  170. $oProfile = BxDolProfile::getInstance($iProfile);
  171. if(!$oProfile)
  172. return array();
  173. return array(
  174. 'entry_sample' => '_sys_profile_sample_single',
  175. 'entry_url' => $oProfile->getUrl(),
  176. 'entry_caption' => $oProfile->getDisplayName(),
  177. 'entry_author' => $oProfile->id(),
  178. 'lang_key' => '_sys_profile_friendship_added',
  179. );
  180. }
  181. }
  182. /** @} */