BxAnonFollowModule.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 AnonymousFollow Anonymous Follow
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxAnonFollowModule extends BxDolModule
  12. {
  13. public function __construct(&$aModule)
  14. {
  15. parent::__construct($aModule);
  16. }
  17. /**
  18. * SERVICE METHODS
  19. */
  20. /**
  21. * @page service Service Calls
  22. * @section bx_anon_follow Anonymous Follow
  23. * @subsection bx_anon_follow-page_blocks Page Blocks
  24. * @subsubsection bx_anon_follow-get_profile_fields get_profile_fields
  25. *
  26. * @code bx_srv('bx_anon_follow', 'get_profile_fields', [...]); @endcode
  27. *
  28. * Get array with module filelds
  29. *
  30. * @param $aParams an array with search params.
  31. * @return array with module filelds
  32. *
  33. * @see BxAnonFollowModule::GetProfileFields
  34. */
  35. /**
  36. * @ref bx_anon_follow-get_profile_fields "get_profile_fields"
  37. */
  38. public function serviceGetProfileFields($sModule)
  39. {
  40. $aResult = array();
  41. $oModule = BxDolModule::getInstance($sModule);
  42. $aFields = BxDolRequest::serviceExists($sModule, 'get_searchable_fields_extended') ? BxDolService::call($sModule, 'get_searchable_fields_extended') : array();
  43. foreach($aFields as $sKey => $aField){
  44. if ($aField['type'] == 'text' || $aField['type'] == 'select')
  45. $aResult[$sKey] = _t($aField['caption']);
  46. }
  47. return $aResult;
  48. }
  49. /**
  50. * @page service Service Calls
  51. * @section bx_anon_follow Anonymous Follow
  52. * @subsection bx_anon_follow-page_blocks Page Blocks
  53. * @subsubsection bx_anon_follow-check_is_subscribed check_is_subscribed
  54. *
  55. * @code bx_srv('bx_anon_follow', 'check_is_subscribed', [...]); @endcode
  56. *
  57. * Get subscribed connection for specified profile
  58. *
  59. * @param $aParams an array with search params.
  60. * @return boolean connection for specified profile
  61. *
  62. * @see BxAnonFollowModule::CheckIsSubscribed
  63. */
  64. /**
  65. * @ref bx_anon_follow-check_is_subscribed "check_is_subscribed"
  66. */
  67. public function serviceCheckIsSubscribed ($iProfileId)
  68. {
  69. if(isset($iProfileId)){
  70. return !$this->checkIsSubscribed($iProfileId);
  71. }
  72. return false;
  73. }
  74. /**
  75. * @page service Service Calls
  76. * @section bx_anon_follow Anonymous Follow
  77. * @subsection bx_anon_follow-page_blocks Page Blocks
  78. * @subsubsection bx_anon_follow-subscribed_me_table subscribed_me_table
  79. *
  80. * @code bx_srv('bx_anon_follow', 'subscribed_me_table', [...]); @endcode
  81. *
  82. * Get grid with subscribers list
  83. *
  84. * @param $aParams an array with search params.
  85. * @return HTML string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  86. *
  87. * @see BxAnonFollowModule::serviceSubscribedMeTable
  88. */
  89. /**
  90. * @ref bx_anon_follow-subscribed_me_table "subscribed_me_table"
  91. */
  92. public function serviceSubscribedMeTable ($iProfileId = 0)
  93. {
  94. if(!$iProfileId && bx_get('profile_id') !== false)
  95. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  96. $aProfile = BxDolProfile::getInstance($iProfileId)->getInfo();
  97. if(empty($aProfile) || !is_array($aProfile))
  98. return false;
  99. $oGrid = BxDolGrid::getObjectInstance('bx_anon_follow_grid_subscribed_me');
  100. if(!$oGrid)
  101. return false;
  102. $oGrid->setProfileId($iProfileId);
  103. $sContent = $oGrid->getCode();
  104. if(empty($sContent))
  105. return false;
  106. $iCount = BxDolService::call('system', 'get_connected_initiators_num', array('sys_profiles_subscriptions', $aProfile['id']), 'TemplServiceConnections');
  107. return $this->_oTemplate->parseHtmlByName('connections_list.html', array(
  108. 'name' => 'subscribers',
  109. 'content' => $sContent,
  110. 'count_info' => _t('_bx_anon_follow_txt_followers_count_info', $iCount),
  111. ));
  112. }
  113. /**
  114. * @page service Service Calls
  115. * @section bx_anon_follow Anonymous Follow
  116. * @subsection bx_anon_follow-page_blocks Page Blocks
  117. * @subsubsection bx_anon_follow-subscriptions_table subscriptions_table
  118. *
  119. * @code bx_srv('bx_anon_follow', 'subscriptions_table', [...]); @endcode
  120. *
  121. * Get grid with subscriptions list
  122. *
  123. * @param $aParams an array with search params.
  124. * @return HTML string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  125. *
  126. * @see BxAnonFollowModule::serviceSubscriptionsTable
  127. */
  128. /**
  129. * @ref bx_anon_follow-subscriptions_table "subscriptions_table"
  130. */
  131. public function serviceSubscriptionsTable ($iProfileId = 0)
  132. {
  133. if(!$iProfileId && bx_get('profile_id') !== false)
  134. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  135. $aProfile = BxDolProfile::getInstance($iProfileId)->getInfo();
  136. if(empty($aProfile) || !is_array($aProfile))
  137. return false;
  138. $oGrid = BxDolGrid::getObjectInstance('bx_anon_follow_grid_subscriptions');
  139. if(!$oGrid)
  140. return false;
  141. $oGrid->setProfileId($iProfileId);
  142. $sContent = $oGrid->getCode();
  143. if(empty($sContent))
  144. return false;
  145. $iCount = BxDolService::call('system', 'get_connected_content_num', array('sys_profiles_subscriptions', $aProfile['id']), 'TemplServiceConnections');
  146. return $this->_oTemplate->parseHtmlByName('connections_list.html', array(
  147. 'name' => 'subscribers',
  148. 'content' => $sContent,
  149. 'count_info' => _t('_bx_anon_follow_txt_following_count_info', $iCount),
  150. ));
  151. }
  152. /**
  153. * @page service Service Calls
  154. * @section bx_anon_follow Anonymous Follow
  155. * @subsection bx_anon_follow-page_blocks Page Blocks
  156. * @subsubsection bx_anon_follow-include_js include_js
  157. *
  158. * @code bx_srv('bx_anon_follow', 'include_js', [...]); @endcode
  159. *
  160. * Add js to injection in head
  161. *
  162. * @param $aParams an array with search params.
  163. * @return void
  164. *
  165. * @see BxAnonFollowModule::serviceIncludeJs
  166. */
  167. /**
  168. * @ref bx_anon_follow-include_js "include_js"
  169. */
  170. public function serviceIncludeJs ()
  171. {
  172. $this->_oTemplate->addJs(array('main.js'));
  173. return ;
  174. }
  175. public function checkIsSubscribed($iProfileId)
  176. {
  177. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  178. if(!$oConnection){
  179. return false;
  180. }
  181. if($iProfileId == bx_get_logged_profile_id()){
  182. return true;
  183. }
  184. if($oConnection->isConnected(bx_get_logged_profile_id(), $iProfileId)){
  185. return true;
  186. }
  187. }
  188. }
  189. /** @} */