BxAttendantModule.php 7.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 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)
  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. if ($aModuleData)
  36. $sRv = $this->_oTemplate->popup($aModuleData);
  37. bx_alert('bx_attendant', 'show_popup', bx_get_logged_profile_id(), 0, ['module' => $sModule, 'event' => $sEvent, 'object_id' => $iObjectId, 'result' => &$sRv]);
  38. echo $sRv;
  39. }
  40. /**
  41. * Service methods
  42. */
  43. /**
  44. * @page service Service Calls
  45. * @section bx_attendant Attendant
  46. * @subsection bx_attendant-other Other
  47. * @subsubsection bx_attendant-on-profile get_profile_modules
  48. *
  49. * @code bx_srv('bx_attendant', 'get_profile_modules', [...]); @endcode
  50. *
  51. * Get list of avaliable modules for on_profile_creation event
  52. *
  53. * @return an array with avaliable modules.
  54. *
  55. * @see BxAttendantModule::serviceGetProfileModules
  56. */
  57. /**
  58. * @ref bx_attendant-get_profile_modules "get_profile_modules"
  59. */
  60. public function serviceGetProfileModules()
  61. {
  62. $aResult = array();
  63. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  64. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  65. foreach($aModules as $aModule){
  66. if(BxDolRequest::serviceExists($aModule['name'], BX_ATTENDANT_ON_PROFILE_CREATION_METHOD)){
  67. $aResult[$aModule['name']] = $aModule['title'];
  68. }
  69. }
  70. return $aResult;
  71. }
  72. /**
  73. * @page service Service Calls
  74. * @section bx_attendant Attendant
  75. * @subsection bx_attendant-other Other
  76. * @subsubsection bx_attendant-on-profile get_options_redirect_after_show
  77. *
  78. * @code bx_srv('bx_attendant', 'get_options_redirect_after_show', [...]); @endcode
  79. *
  80. * Get list avaliable redirct pages
  81. *
  82. * @return an array with avaliable redirct pages.
  83. *
  84. * @see BxAttendantModule::serviceGetOptionsRedirectAfterShow
  85. */
  86. /**
  87. * @ref bx_attendant-get_options_redirect_after_show "get_options_redirect_after_show"
  88. */
  89. public function serviceGetOptionsRedirectAfterShow()
  90. {
  91. $CNF = &$this->_oConfig->CNF;
  92. $aResult = [];
  93. $aChoices = ['noredirect', 'homepage', 'profile', 'custom'];
  94. foreach($aChoices as $sChoice)
  95. $aResult[] = array('key' => $sChoice, 'value' => _t('_bx_attendant_option_redirect_show_' . $sChoice));
  96. return $aResult;
  97. }
  98. /**
  99. * @page service Service Calls
  100. * @section bx_attendant Attendant
  101. * @subsection bx_attendant-other Other
  102. * @subsubsection bx_attendant-on-profile get_popup_with_recommended_on_event_show
  103. *
  104. * @code bx_srv('bx_attendant', 'get_popup_with_recommended_on_event_show', [...]); @endcode
  105. *
  106. * Get list of events for on_profile_creation show
  107. *
  108. * @return an array with avaliable events.
  109. *
  110. * @see BxAttendantModule::serviceGetPopupWithRecommendedOnEventShow
  111. */
  112. /**
  113. * @ref bx_attendant-get_popup_with_recommended_on_event_show "get_popup_with_recommended_on_event_show"
  114. */
  115. public function serviceGetPopupWithRecommendedOnEventShow()
  116. {
  117. $aResult = array();
  118. $aChoices = array(BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_CONFIRMATION, BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_REGISTRATION);
  119. foreach($aChoices as $sChoice)
  120. $aResult[$sChoice] = _t('_bx_attendant_popup_event_after_' . $sChoice);
  121. return $aResult;
  122. }
  123. /**
  124. * @page service Service Calls
  125. * @section bx_attendant Attendant
  126. * @subsection bx_attendant-other Other
  127. * @subsubsection bx_attendant-get_profile_modules handle_action_view
  128. *
  129. * @code bx_srv('bx_attendant', 'handle_action_view', [...]); @endcode
  130. *
  131. * Get Include for injection
  132. *
  133. * @return an include code
  134. *
  135. * @see BxAttendantModule::HandleActionView
  136. */
  137. /**
  138. * @ref bx_attendant-handle_action_view "handle_action_view"
  139. */
  140. public function serviceHandleActionView()
  141. {
  142. $sRv = $this->_oTemplate->init();
  143. if (!isLogged())
  144. return;
  145. $aEvents = $this->_oDb->getEvents(array('type' => 'active_by_action_and_profile_id', 'action' => 'view', 'profile_id' => bx_get_logged_profile_id()));
  146. foreach($aEvents as $aEvent){
  147. //$oRv = call_user_func_array(array($this, $aEvent['method']), array($aEvent['object_id']));
  148. $oRv = $this->processPopupOnEvent($aEvent);
  149. if ($oRv !== false){
  150. $sRv .= $oRv;
  151. $this->_oDb->setEventProcessed($aEvent['id']);
  152. }
  153. }
  154. return $sRv;
  155. }
  156. public function serviceHandleActionNonView()
  157. {
  158. //for some other actions fex cron - not implemented
  159. }
  160. public function addEvent($sAction, $iObjectId, $sModule, $sEvent, $iProfileId)
  161. {
  162. $this->_oDb->addEvent($sAction, $iObjectId, $sModule, $sEvent, $iProfileId);
  163. }
  164. public function initPopupByEvent($iObjectId, $sModule, $sEvent, $iProfileId)
  165. {
  166. $this->addEvent('view', $iObjectId, $sModule, $sEvent, $iProfileId);
  167. }
  168. public function processPopupOnEvent($aEvent)
  169. {
  170. $sRv = '';
  171. $sDefaultEvent = getParam('bx_attendant_on_profile_event_list');
  172. $oProfile = BxDolProfile::getInstance($aEvent['profile_id']);
  173. $oAccount = $oProfile ? $oProfile->getAccountObject() : null;
  174. $bNeedRaiseEvent = false;
  175. if ($aEvent['event'] == 'add' && $aEvent['module'] == 'profile'){
  176. 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()))){
  177. $bNeedRaiseEvent = true;
  178. }
  179. }
  180. else{
  181. 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]);
  182. }
  183. if ($bNeedRaiseEvent)
  184. return getParam('bx_attendant_on_profile_creation_modules').'<script>oBxAttendant.showPopup("' . $aEvent['module'] . '", "' . $aEvent['event'] . '", ' . $aEvent['object_id'] . ')</script>';
  185. else
  186. return false;
  187. }
  188. }
  189. /** @} */