BxAttendantModule.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 Attendant Attendant
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_ATTENDANT_ON_PROFILE_CREATION_METHOD', 'browse_recommended');
  12. define('BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_REGISTRATION', 'registration');
  13. define('BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_CONFIRMATION', 'confirmation');
  14. class BxAttendantModule extends BxDolModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. }
  20. public function actionRecomendedPopup($sModule, $sEvent, $iObjectId, $bManual)
  21. {
  22. $sRv = '';
  23. $aModules = explode(',', getParam('bx_attendant_on_profile_creation_modules'));
  24. $aModuleData = array();
  25. foreach($aModules as $sModuleName){
  26. if(BxDolRequest::serviceExists($sModuleName, BX_ATTENDANT_ON_PROFILE_CREATION_METHOD)){
  27. $aTmp = BxDolService::call($sModuleName, BX_ATTENDANT_ON_PROFILE_CREATION_METHOD, ['unit_view' => 'showcase', 'empty_message' => false, "ajax_paginate" => false]);
  28. if (isset($aTmp['content'])){
  29. $sTmp = $aTmp['content'];
  30. $sTmp = str_replace('bx_conn_action', 'bx_attendant_conn_action', $sTmp);
  31. $aModuleData[$sModuleName] = $sTmp;
  32. }
  33. }
  34. }
  35. $oSession = BxDolSession::getInstance();
  36. $sFirstPage = $oSession->getValue('sys_entrance_url');
  37. if ($sFirstPage){
  38. if (getParam('bx_attendant_redirect_to_entered_page') == 'on'){
  39. echo json_encode(['redirect' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink($sFirstPage))]);
  40. exit();
  41. }
  42. else{
  43. if(getParam('bx_attendant_suggest_entered_page') == 'on'){
  44. list($sPageLink, $aPageParams) = bx_get_base_url($sFirstPage);
  45. if (isset($aPageParams['i']) && isset($aPageParams['id'])){
  46. $oPage = BxDolPage::getObjectInstanceByURI($aPageParams['i']);
  47. if ($oPage){
  48. $sModuleName = $oPage->getModule();
  49. if(bx_srv('system', 'is_module_context', [$sModuleName])){
  50. $oModule = BxDolModule::getInstance($sModuleName);
  51. $aTmp = $oModule->serviceBrowse([
  52. 'mode' => 'recent',
  53. 'params' => [
  54. 'filter' => [
  55. 'field' => 'id',
  56. 'value' => [$aPageParams['id']],
  57. 'operator' => 'in',
  58. 'table' => 'tableSearch'
  59. ],
  60. ]
  61. ]);
  62. if (isset($aTmp['content'])){
  63. $sTmp = $aTmp['content'];
  64. $sTmp = str_replace('bx_conn_action', 'bx_attendant_conn_action', $sTmp);
  65. $aModuleData[$sModuleName. '_initial_link'] = $sTmp;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. $sRv = $this->_oTemplate->popup($aModuleData, $bManual);
  74. bx_alert('bx_attendant', 'show_popup', bx_get_logged_profile_id(), 0, ['module' => $sModule, 'event' => $sEvent, 'object_id' => $iObjectId, 'result' => &$sRv]);
  75. echo $sRv;
  76. }
  77. /**
  78. * Service methods
  79. */
  80. /**
  81. * @page service Service Calls
  82. * @section bx_attendant Attendant
  83. * @subsection bx_attendant-other Other
  84. * @subsubsection bx_attendant-on-profile get_profile_modules
  85. *
  86. * @code bx_srv('bx_attendant', 'get_profile_modules', [...]); @endcode
  87. *
  88. * Get list of avaliable modules for on_profile_creation event
  89. *
  90. * @return an array with avaliable modules.
  91. *
  92. * @see BxAttendantModule::serviceGetProfileModules
  93. */
  94. /**
  95. * @ref bx_attendant-get_profile_modules "get_profile_modules"
  96. */
  97. public function serviceGetProfileModules()
  98. {
  99. $aResult = array();
  100. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  101. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  102. foreach($aModules as $aModule){
  103. if(BxDolRequest::serviceExists($aModule['name'], BX_ATTENDANT_ON_PROFILE_CREATION_METHOD)){
  104. $aResult[$aModule['name']] = $aModule['title'];
  105. }
  106. }
  107. return $aResult;
  108. }
  109. /**
  110. * @page service Service Calls
  111. * @section bx_attendant Attendant
  112. * @subsection bx_attendant-other Other
  113. * @subsubsection bx_attendant-on-profile get_options_redirect_after_show
  114. *
  115. * @code bx_srv('bx_attendant', 'get_options_redirect_after_show', [...]); @endcode
  116. *
  117. * Get list avaliable redirct pages
  118. *
  119. * @return an array with avaliable redirct pages.
  120. *
  121. * @see BxAttendantModule::serviceGetOptionsRedirectAfterShow
  122. */
  123. /**
  124. * @ref bx_attendant-get_options_redirect_after_show "get_options_redirect_after_show"
  125. */
  126. public function serviceGetOptionsRedirectAfterShow()
  127. {
  128. $CNF = &$this->_oConfig->CNF;
  129. $aResult = [];
  130. $aChoices = ['noredirect', 'homepage', 'profile', 'custom'];
  131. foreach($aChoices as $sChoice)
  132. $aResult[] = array('key' => $sChoice, 'value' => _t('_bx_attendant_option_redirect_show_' . $sChoice));
  133. return $aResult;
  134. }
  135. /**
  136. * @page service Service Calls
  137. * @section bx_attendant Attendant
  138. * @subsection bx_attendant-other Other
  139. * @subsubsection bx_attendant-on-profile get_popup_with_recommended_on_event_show
  140. *
  141. * @code bx_srv('bx_attendant', 'get_popup_with_recommended_on_event_show', [...]); @endcode
  142. *
  143. * Get list of events for on_profile_creation show
  144. *
  145. * @return an array with avaliable events.
  146. *
  147. * @see BxAttendantModule::serviceGetPopupWithRecommendedOnEventShow
  148. */
  149. /**
  150. * @ref bx_attendant-get_popup_with_recommended_on_event_show "get_popup_with_recommended_on_event_show"
  151. */
  152. public function serviceGetPopupWithRecommendedOnEventShow()
  153. {
  154. $aResult = array();
  155. $aChoices = array(BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_CONFIRMATION, BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_REGISTRATION);
  156. foreach($aChoices as $sChoice)
  157. $aResult[$sChoice] = _t('_bx_attendant_popup_event_after_' . $sChoice);
  158. return $aResult;
  159. }
  160. /**
  161. * @page service Service Calls
  162. * @section bx_attendant Attendant
  163. * @subsection bx_attendant-other Other
  164. * @subsubsection bx_attendant-get_profile_modules handle_action_view
  165. *
  166. * @code bx_srv('bx_attendant', 'handle_action_view', [...]); @endcode
  167. *
  168. * Get Include for injection
  169. *
  170. * @return an include code
  171. *
  172. * @see BxAttendantModule::HandleActionView
  173. */
  174. /**
  175. * @ref bx_attendant-handle_action_view "handle_action_view"
  176. */
  177. public function serviceHandleActionView()
  178. {
  179. $sRv = $this->_oTemplate->init();
  180. if (!isLogged())
  181. return;
  182. $aEvents = $this->_oDb->getEvents(array('type' => 'active_by_action_and_profile_id', 'action' => 'view', 'profile_id' => bx_get_logged_profile_id()));
  183. foreach($aEvents as $aEvent){
  184. //$oRv = call_user_func_array(array($this, $aEvent['method']), array($aEvent['object_id']));
  185. $oRv = $this->processPopupOnEvent($aEvent);
  186. if ($oRv !== false){
  187. $sRv .= $oRv;
  188. $this->_oDb->setEventProcessed($aEvent['id']);
  189. }
  190. }
  191. return $sRv;
  192. }
  193. public function serviceHandleActionNonView()
  194. {
  195. //for some other actions fex cron - not implemented
  196. }
  197. public function addEvent($sAction, $iObjectId, $sModule, $sEvent, $iProfileId)
  198. {
  199. $this->_oDb->addEvent($sAction, $iObjectId, $sModule, $sEvent, $iProfileId);
  200. }
  201. public function initPopupByEvent($iObjectId, $sModule, $sEvent, $iProfileId)
  202. {
  203. $this->addEvent('view', $iObjectId, $sModule, $sEvent, $iProfileId);
  204. }
  205. public function processPopupOnEvent($aEvent)
  206. {
  207. $sRv = '';
  208. $sDefaultEvent = getParam('bx_attendant_on_profile_event_list');
  209. $oProfile = BxDolProfile::getInstance($aEvent['profile_id']);
  210. $oAccount = $oProfile ? $oProfile->getAccountObject() : null;
  211. $bNeedRaiseEvent = false;
  212. if ($aEvent['event'] == 'add' && $aEvent['module'] == 'profile'){
  213. if (getParam('bx_attendant_on_profile_creation_modules') != '' && ($sDefaultEvent == BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_REGISTRATION || ($sDefaultEvent == BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_CONFIRMATION && $oAccount != null && $oAccount->isConfirmed()))){
  214. if ($oProfile->getModule() != 'system'){
  215. $bNeedRaiseEvent = true;
  216. }
  217. }
  218. }
  219. else{
  220. bx_alert('bx_attendant', 'before_show_popup', bx_get_logged_profile_id(), 0, ['module' => $aEvent['module'], 'event' => $aEvent['event'], 'object_id' => $aEvent['object_id'], 'result' => &$bNeedRaiseEvent]);
  221. }
  222. if ($bNeedRaiseEvent)
  223. return getParam('bx_attendant_on_profile_creation_modules').'<script>oBxAttendant.showPopup("' . $aEvent['module'] . '", "' . $aEvent['event'] . '", ' . $aEvent['object_id'] . ')</script>';
  224. else
  225. return false;
  226. }
  227. }
  228. /** @} */