1
0

BxBaseMenuUnitMeta.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Menu representation.
  11. * @see BxDolMenu
  12. */
  13. class BxBaseMenuUnitMeta extends BxTemplMenuCustom
  14. {
  15. protected $_sStylePrefix;
  16. public function __construct ($aObject, $oTemplate)
  17. {
  18. parent::__construct ($aObject, $oTemplate);
  19. $this->_sStylePrefix = 'sys-meta';
  20. }
  21. public function getUnitMetaItemLink($sContent, $aAttrs = array())
  22. {
  23. return $this->getUnitMetaItemButtonOrLink('a', $sContent, $aAttrs);
  24. }
  25. public function getUnitMetaItemText($sContent, $aAttrs = array())
  26. {
  27. return $this->getUnitMetaItem('span', $sContent, $aAttrs);
  28. }
  29. public function getUnitMetaItemButton($sContent, $aAttrs = array())
  30. {
  31. return $this->getUnitMetaItemButtonOrLink('button', $sContent, $aAttrs);
  32. }
  33. public function getUnitMetaItemButtonSmall($sContent, $aAttrs = array())
  34. {
  35. return $this->getUnitMetaItemButtonOrLink('sbutton', $sContent, $aAttrs);
  36. }
  37. public function getUnitMetaItemNl($sContent = '')
  38. {
  39. return $this->getUnitMetaItem('nl', $sContent);
  40. }
  41. public function getUnitMetaItemCustom($sContent)
  42. {
  43. return $this->getUnitMetaItem('custom', $sContent);
  44. }
  45. public function getUnitMetaItemExtended($sContent = '', $sIcon = '', $sUrl = '', $bIsNoBg = false, $bIsNoPadding = false )
  46. {
  47. $aTmplVarsEx = [];
  48. if ($sContent == '' && $sIcon == '')
  49. return ;
  50. $aTmplVarsEx['bx_if:icon'] = [
  51. 'condition' => ($sIcon != ''),
  52. 'content' => ['icon' => $this->getMenuIconHtml($sIcon)]
  53. ];
  54. $aTmplVarsEx['bx_if:noicon'] = [
  55. 'condition' => ($sIcon == ''),
  56. 'content' => []
  57. ];
  58. $aTmplVarsEx['bx_if:a'] = [
  59. 'condition' => ($sUrl != ''),
  60. 'content' => ['link' => $sUrl]
  61. ];
  62. $aTmplVarsEx['bx_if:a2'] = [
  63. 'condition' => ($sUrl != ''),
  64. 'content' => []
  65. ];
  66. $aTmplVarsEx['bx_if:text'] = [
  67. 'condition' => ($sContent != ''),
  68. 'content' => ['content' => $sContent]
  69. ];
  70. $aTmplVars['bx_if:extended'] = [
  71. 'condition' => true,
  72. 'content' => $aTmplVarsEx
  73. ];
  74. $aTags = array('span', 'a', 'button', 'sbutton', 'custom', 'nl');
  75. foreach($aTags as $sTag) {
  76. $aTmplVars['bx_if:' . $sTag] = array(
  77. 'condition' => false,
  78. 'content' => []
  79. );
  80. }
  81. $aTmplVars['class'] = $bIsNoBg ? 'bx-menu-meta-item-ex-no-bg' : '';
  82. $aTmplVars['class'] = $bIsNoPadding ? 'bx-menu-meta-item-ex-no-pad' : '';
  83. return $this->_oTemplate->parseHtmlByName('unit_meta_item_ex.html', $aTmplVars);
  84. }
  85. public function getUnitMetaItem($sName, $sContent, $aAttrs = array(), $sTemplate = 'unit_meta_item.html')
  86. {
  87. if(empty($sContent) && $sName != 'nl')
  88. return '';
  89. if(!is_array($aAttrs))
  90. $aAttrs = array();
  91. $aTags = array('span', 'a', 'button', 'sbutton', 'custom', 'nl', 'extended');
  92. $sTmplVarsClass = '';
  93. if(!empty($aAttrs['class'])) {
  94. $sTmplVarsClass = $aAttrs['class'];
  95. unset($aAttrs['class']);
  96. }
  97. $aTmplVarsAttrs = array();
  98. foreach($aAttrs as $sKey => $sValue)
  99. $aTmplVarsAttrs[] = array('key' => $sKey, 'value' => bx_html_attribute($sValue));
  100. $aTmplVars = array();
  101. foreach($aTags as $sTag) {
  102. $aTmplVarsTag = array();
  103. $bTmplVarsTag = $sTag == $sName;
  104. if($bTmplVarsTag)
  105. $aTmplVarsTag = array(
  106. 'style_prefix' => $this->_sStylePrefix,
  107. 'class' => $sTmplVarsClass,
  108. 'content' => $sContent,
  109. 'bx_repeat:attrs' => $aTmplVarsAttrs
  110. );
  111. $aTmplVars['bx_if:' . $sTag] = array(
  112. 'condition' => $bTmplVarsTag,
  113. 'content' => $aTmplVarsTag
  114. );
  115. }
  116. return $this->_oTemplate->parseHtmlByName($sTemplate, $aTmplVars);
  117. }
  118. public function getUnitMetaItemButtonOrLink($sName, $sContent, $aAttrs = array())
  119. {
  120. if(!isset($aAttrs['href']))
  121. $aAttrs['href'] = 'javascript:void(0)';
  122. return $this->getUnitMetaItem($sName, $sContent, $aAttrs);
  123. }
  124. protected function _getMenuItemNl($aItem)
  125. {
  126. return $this->getUnitMetaItemNl();
  127. }
  128. protected function _getMenuItemDefault($aItem)
  129. {
  130. $sResult = '';
  131. if(!empty($aItem['link']))
  132. $sResult = $this->getUnitMetaItemLink($aItem['title'], array(
  133. 'href' => $aItem['link']
  134. ));
  135. else if(!empty($aItem['onclick']))
  136. $sResult = $this->getUnitMetaItemButtonSmall($aItem['title'], array(
  137. 'onclick' => $aItem['onclick']
  138. ));
  139. else
  140. $sResult = $this->getUnitMetaItemText($aItem['title']);
  141. return $sResult;
  142. }
  143. }
  144. /** @} */