BxAttendantTemplate.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. bx_import ('BxDolModuleTemplate');
  12. class BxAttendantTemplate extends BxBaseModGeneralTemplate
  13. {
  14. var $sContainerId = 'oBxAttendantPopupWithRecommendedOnProfileAdd';
  15. function __construct(&$oConfig, &$oDb)
  16. {
  17. parent::__construct($oConfig, $oDb);
  18. }
  19. public function init()
  20. {
  21. $this->addJs([
  22. 'main.js',
  23. 'flickity/flickity.pkgd.min.js',
  24. 'modules/base/general/js/|showcase.js'
  25. ]
  26. );
  27. $this->addCss([
  28. 'main.css',
  29. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css'
  30. ]
  31. );
  32. if (isLogged())
  33. return $this->getJsCode('main') . BxBaseFunctions::getInstance()->transBox($this->sContainerId, '', true, true);
  34. return '';
  35. }
  36. public function popup($aModuleData, $bManual)
  37. {
  38. $aVars = [];
  39. foreach ($aModuleData as $sModuleName => $sModuleData){
  40. $aVars[] = [
  41. 'html' => $sModuleData,
  42. 'title' => $this->getStringValueByModuleOrDefault('_bx_attendant_popup_with_recommended_title_', $sModuleName) ,
  43. 'description' => $this->getStringValueByModuleOrDefault('_bx_attendant_popup_with_recommended_description_', $sModuleName)
  44. ];
  45. }
  46. if ($bManual || count($aVars) >0){
  47. return $this->parseHtmlByName('popup_recommended.html', [
  48. 'bx_if:data' => [
  49. 'condition' => count($aVars) > 0,
  50. 'content' => [
  51. 'bx_repeat:items' => $aVars,
  52. 'button_text' => _t('_bx_attendant_popup_with_recommended_button_text')
  53. ]
  54. ],
  55. 'bx_if:nodata' => [
  56. 'condition' => count($aVars) == 0,
  57. 'content' => [
  58. ]
  59. ]
  60. ]
  61. );
  62. }
  63. else{
  64. return '';
  65. }
  66. }
  67. public function getJsCode($sType, $aParams = array(), $bWrap = true)
  68. {
  69. $sRedirectUrl = '';
  70. switch (getParam('bx_attendant_on_profile_after_action_url')) {
  71. case 'profile':
  72. $sRedirectUrl = BxDolProfile::getInstance()->getUrl();
  73. break;
  74. case 'custom':
  75. $sRedirectCustom = getParam('bx_attendant_on_profile_after_action_url_custom');
  76. if($sRedirectCustom) {
  77. $sRedirectUrl = BxDolPermalinks::getInstance()->permalink($sRedirectCustom);
  78. if (false === strpos($sRedirectUrl, 'http://') && false === strpos($sRedirectUrl, 'https://'))
  79. $sRedirectUrl = BX_DOL_URL_ROOT . $sRedirectCustom;
  80. }
  81. break;
  82. case 'homepage':
  83. $sRedirectUrl = BX_DOL_URL_ROOT;
  84. break;
  85. }
  86. $aParams = array_merge(array(
  87. 'sContainerId' => $this->sContainerId,
  88. 'sUrlAfterShow' => $sRedirectUrl
  89. ), $aParams);
  90. return parent::getJsCode($sType, $aParams, $bWrap);
  91. }
  92. private function getStringValueByModuleOrDefault($sKey, $sModuleName)
  93. {
  94. $sFullKey = $sKey . $sModuleName;
  95. $sValue = _t($sFullKey);
  96. if ($sValue == $sFullKey){
  97. $oModule = BxDolModule::getInstance($sModuleName);
  98. if ($oModule)
  99. $sValue =_t($sKey . 'default', $oModule->_aModule['title']);
  100. }
  101. return $sValue;
  102. }
  103. }
  104. /** @} */