BxAttendantModule.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. /**
  21. * Service methods
  22. */
  23. /**
  24. * @page service Service Calls
  25. * @section bx_attendant Attendant
  26. * @subsection bx_attendant-other Other
  27. * @subsubsection bx_attendant-on-profile get_profile_modules
  28. *
  29. * @code bx_srv('bx_attendant', 'get_profile_modules', [...]); @endcode
  30. *
  31. * Get list of avaliable modules for on_profile_creation event
  32. *
  33. * @return an array with avaliable modules.
  34. *
  35. * @see BxAttendantModule::serviceGetProfileModules
  36. */
  37. /**
  38. * @ref bx_attendant-get_profile_modules "get_profile_modules"
  39. */
  40. public function serviceGetProfileModules()
  41. {
  42. $aResult = array();
  43. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  44. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  45. foreach($aModules as $aModule){
  46. if(BxDolRequest::serviceExists($aModule['name'], BX_ATTENDANT_ON_PROFILE_CREATION_METHOD)){
  47. $aResult[$aModule['name']] = $aModule['title'];
  48. }
  49. }
  50. return $aResult;
  51. }
  52. /**
  53. * @page service Service Calls
  54. * @section bx_attendant Attendant
  55. * @subsection bx_attendant-other Other
  56. * @subsubsection bx_attendant-on-profile get_popup_with_recommended_on_event_show
  57. *
  58. * @code bx_srv('bx_attendant', 'get_popup_with_recommended_on_event_show', [...]); @endcode
  59. *
  60. * Get list of events for on_profile_creation show
  61. *
  62. * @return an array with avaliable events.
  63. *
  64. * @see BxAttendantModule::serviceGetPopupWithRecommendedOnEventShow
  65. */
  66. /**
  67. * @ref bx_attendant-get_popup_with_recommended_on_event_show "get_popup_with_recommended_on_event_show"
  68. */
  69. public function serviceGetPopupWithRecommendedOnEventShow()
  70. {
  71. $aResult = array();
  72. $aChoices = array(BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_CONFIRMATION, BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_REGISTRATION);
  73. foreach($aChoices as $sChoice)
  74. $aResult[$sChoice] = _t('_bx_attendant_popup_event_after_' . $sChoice);
  75. return $aResult;
  76. }
  77. /**
  78. * @page service Service Calls
  79. * @section bx_attendant Attendant
  80. * @subsection bx_attendant-other Other
  81. * @subsubsection bx_attendant-get_profile_modules handle_action_view
  82. *
  83. * @code bx_srv('bx_attendant', 'handle_action_view', [...]); @endcode
  84. *
  85. * Get Include for injection
  86. *
  87. * @return an include code
  88. *
  89. * @see BxAttendantModule::HandleActionView
  90. */
  91. /**
  92. * @ref bx_attendant-handle_action_view "handle_action_view"
  93. */
  94. public function serviceHandleActionView()
  95. {
  96. if (!isLogged())
  97. return;
  98. $sRv = '';
  99. $aEvents = $this->_oDb->getEvents(array('type' => 'active_by_action_and_object_id', 'action' => 'view', 'object_id' => bx_get_logged_profile_id()));
  100. foreach($aEvents as $aEvent){
  101. $oRv = call_user_func_array(array($this, $aEvent['method']), array($aEvent['object_id']));
  102. if ($oRv !== false){
  103. $sRv .= $oRv;
  104. $this->_oDb->setEventProcessed($aEvent['id']);
  105. }
  106. }
  107. return $sRv;
  108. }
  109. public function serviceHandleActionNonView()
  110. {
  111. //for some other actions fex cron - not implemented
  112. }
  113. public function addEvent($sMethod, $sAction, $iObjectId)
  114. {
  115. $this->_oDb->addEvent($sMethod, $sAction, $iObjectId);
  116. }
  117. public function initPopupWithRecommendedOnProfileAdd($iProfileId)
  118. {
  119. $this->addEvent('processPopupWithRecommendedOnProfileAdd', 'view', $iProfileId);
  120. }
  121. public function processPopupWithRecommendedOnProfileAdd($iProfileId)
  122. {
  123. $sRv = '';
  124. $sEvent = getParam('bx_attendant_on_profile_event_list');
  125. $oProfile = BxDolProfile::getInstance($iProfileId);
  126. $oAccount = $oProfile ? $oProfile->getAccountObject() : null;
  127. if ($sEvent == BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_REGISTRATION || ($sEvent == BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_CONFIRMATION && $oAccount != null && $oAccount->isConfirmed())){
  128. $aModules = explode(',', getParam('bx_attendant_on_profile_creation_modules'));
  129. $aModulteData = array();
  130. foreach($aModules as $sModuleName){
  131. if(BxDolRequest::serviceExists($sModuleName, BX_ATTENDANT_ON_PROFILE_CREATION_METHOD)){
  132. $aTmp = BxDolService::call($sModuleName, BX_ATTENDANT_ON_PROFILE_CREATION_METHOD, array('unit_view' => 'showcase', 'empty_message' => false, "ajax_paginate" => false));
  133. if (isset($aTmp['content'])){
  134. $sTmp = $aTmp['content'];
  135. $sTmp = str_replace('bx_conn_action', 'bx_attendant_conn_action', $sTmp);
  136. $aModulteData[$sModuleName] = $sTmp;
  137. }
  138. }
  139. }
  140. if (count($aModulteData) > 0)
  141. $sRv = $this->_oTemplate->popupWithRecommendedOnProfileAdd($aModulteData);
  142. return $sRv;
  143. }
  144. else{
  145. return false;
  146. }
  147. }
  148. }
  149. /** @} */