BxBaseMenuUnitMeta.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 = '')
  46. {
  47. $aTmplVarsEx = [];
  48. $aTmplVarsEx['bx_if:icon'] = [
  49. 'condition' => ($sIcon != ''),
  50. 'content' => ['icon' => $this->getMenuIconHtml($sIcon)]
  51. ];
  52. $aTmplVarsEx['bx_if:noicon'] = [
  53. 'condition' => ($sIcon == ''),
  54. 'content' => []
  55. ];
  56. $aTmplVarsEx['bx_if:a'] = [
  57. 'condition' => ($sUrl != ''),
  58. 'content' => ['link' => $sUrl]
  59. ];
  60. $aTmplVarsEx['bx_if:a2'] = [
  61. 'condition' => ($sUrl != ''),
  62. 'content' => []
  63. ];
  64. $aTmplVarsEx['bx_if:text'] = [
  65. 'condition' => ($sContent != ''),
  66. 'content' => ['content' => $sContent]
  67. ];
  68. $aTmplVars['bx_if:extended'] = [
  69. 'condition' => true,
  70. 'content' => $aTmplVarsEx
  71. ];
  72. $aTags = array('span', 'a', 'button', 'sbutton', 'custom', 'nl');
  73. foreach($aTags as $sTag) {
  74. $aTmplVars['bx_if:' . $sTag] = array(
  75. 'condition' => false,
  76. 'content' => []
  77. );
  78. }
  79. return $this->_oTemplate->parseHtmlByName('unit_meta_item_ex.html', $aTmplVars);
  80. }
  81. public function getUnitMetaItem($sName, $sContent, $aAttrs = array(), $sTemplate = 'unit_meta_item.html')
  82. {
  83. if(empty($sContent) && $sName != 'nl')
  84. return '';
  85. if(!is_array($aAttrs))
  86. $aAttrs = array();
  87. $aTags = array('span', 'a', 'button', 'sbutton', 'custom', 'nl', 'extended');
  88. $sTmplVarsClass = '';
  89. if(!empty($aAttrs['class'])) {
  90. $sTmplVarsClass = $aAttrs['class'];
  91. unset($aAttrs['class']);
  92. }
  93. $aTmplVarsAttrs = array();
  94. foreach($aAttrs as $sKey => $sValue)
  95. $aTmplVarsAttrs[] = array('key' => $sKey, 'value' => bx_html_attribute($sValue));
  96. $aTmplVars = array();
  97. foreach($aTags as $sTag) {
  98. $aTmplVarsTag = array();
  99. $bTmplVarsTag = $sTag == $sName;
  100. if($bTmplVarsTag)
  101. $aTmplVarsTag = array(
  102. 'style_prefix' => $this->_sStylePrefix,
  103. 'class' => $sTmplVarsClass,
  104. 'content' => $sContent,
  105. 'bx_repeat:attrs' => $aTmplVarsAttrs
  106. );
  107. $aTmplVars['bx_if:' . $sTag] = array(
  108. 'condition' => $bTmplVarsTag,
  109. 'content' => $aTmplVarsTag
  110. );
  111. }
  112. return $this->_oTemplate->parseHtmlByName($sTemplate, $aTmplVars);
  113. }
  114. public function getUnitMetaItemButtonOrLink($sName, $sContent, $aAttrs = array())
  115. {
  116. if(!isset($aAttrs['href']))
  117. $aAttrs['href'] = 'javascript:void(0)';
  118. return $this->getUnitMetaItem($sName, $sContent, $aAttrs);
  119. }
  120. protected function _getMenuItemNl($aItem)
  121. {
  122. return $this->getUnitMetaItemNl();
  123. }
  124. protected function _getMenuItemDefault($aItem)
  125. {
  126. $sResult = '';
  127. if(!empty($aItem['link']))
  128. $sResult = $this->getUnitMetaItemLink($aItem['title'], array(
  129. 'href' => $aItem['link']
  130. ));
  131. else if(!empty($aItem['onclick']))
  132. $sResult = $this->getUnitMetaItemButtonSmall($aItem['title'], array(
  133. 'onclick' => $aItem['onclick']
  134. ));
  135. else
  136. $sResult = $this->getUnitMetaItemText($aItem['title']);
  137. return $sResult;
  138. }
  139. }
  140. /** @} */