BxHelpToursTemplate.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 Help Tours Help Tours
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxHelpToursTemplate extends BxBaseModGeneralTemplate
  12. {
  13. public function __construct(&$oConfig, &$oDb)
  14. {
  15. parent::__construct($oConfig, $oDb);
  16. }
  17. public function getHelpTourCode($aTour, $aHelpTourItems) {
  18. $this->addJs(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'shepherd/js/|shepherd.min.js');
  19. $this->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'shepherd/css/|shepherd.css');
  20. $iShowOnlyItem = isAdmin() && bx_get('help_tour_item') ? intval(bx_get('help_tour_item')) : 0;
  21. $aHelpTourItemsTmpl = [];
  22. foreach ($aHelpTourItems as $iCounter => $aItem) {
  23. if ($iShowOnlyItem && $iShowOnlyItem != $aItem['id']) continue;
  24. $aStep = [
  25. 'id' => 'bx-help-tour-step-'.$aItem['id'],
  26. 'text' => _t($aItem['text']),
  27. ];
  28. if ($aItem['title']) $aStep['title'] = _t($aItem['title']);
  29. if ($aItem['element']) $aStep['attachTo'] = ['element' => $aItem['element'], 'on' => $aItem['arrow']];
  30. $aHelpTourItemsTmpl[] = $aStep;
  31. }
  32. if (!$aHelpTourItemsTmpl) return;
  33. return $this->parseHtmlByName('tour.html', [
  34. 'tour_overlay' => $aTour['overlay'] ? 'true' : 'false',
  35. 'steps' => json_encode($aHelpTourItemsTmpl),
  36. 'js_obj' => $this->getTourJsObject(),
  37. 'bx_if:not_preview' => [
  38. 'condition' => !(isAdmin() && (bx_get('help_tour_preview') || bx_get('help_tour_item'))),
  39. 'content' => [
  40. 'finish_callback_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'tour_seen/',
  41. 'tour_id' => $aTour['id'],
  42. ],
  43. ],
  44. ]);
  45. }
  46. public function getTourJsObject() {
  47. return 'bx_help_tour_obj';
  48. }
  49. }
  50. /** @} */