1
0

BxBaseMenuUnitMeta.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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($sContent, 'a', $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($sContent, 'button', $aAttrs);
  32. }
  33. public function getUnitMetaItemButtonSmall($sContent, $aAttrs = array())
  34. {
  35. return $this->_getUnitMetaItemButtonOrLink($sContent, 'sbutton', $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 getUnitMetaItem($sName, $sContent, $aAttrs = array(), $sTemplate = 'unit_meta_item.html')
  46. {
  47. if(empty($sContent) && $sName != 'nl')
  48. return '';
  49. if(!is_array($aAttrs))
  50. $aAttrs = array();
  51. $aTags = array('span', 'a', 'button', 'sbutton', 'custom', 'nl');
  52. $sTmplVarsClass = '';
  53. if(!empty($aAttrs['class'])) {
  54. $sTmplVarsClass = $aAttrs['class'];
  55. unset($aAttrs['class']);
  56. }
  57. $aTmplVarsAttrs = array();
  58. foreach($aAttrs as $sKey => $sValue)
  59. $aTmplVarsAttrs[] = array('key' => $sKey, 'value' => bx_html_attribute($sValue));
  60. $aTmplVars = array();
  61. foreach($aTags as $sTag) {
  62. $aTmplVarsTag = array();
  63. $bTmplVarsTag = $sTag == $sName;
  64. if($bTmplVarsTag)
  65. $aTmplVarsTag = array(
  66. 'style_prefix' => $this->_sStylePrefix,
  67. 'class' => $sTmplVarsClass,
  68. 'content' => $sContent,
  69. 'bx_repeat:attrs' => $aTmplVarsAttrs
  70. );
  71. $aTmplVars['bx_if:' . $sTag] = array(
  72. 'condition' => $bTmplVarsTag,
  73. 'content' => $aTmplVarsTag
  74. );
  75. }
  76. return $this->_oTemplate->parseHtmlByName($sTemplate, $aTmplVars);
  77. }
  78. protected function _getMenuItemNl($aItem)
  79. {
  80. return $this->getUnitMetaItemNl();
  81. }
  82. protected function _getMenuItemDefault($aItem)
  83. {
  84. $sResult = '';
  85. if(!empty($aItem['link']))
  86. $sResult = $this->getUnitMetaItemLink($aItem['title'], array(
  87. 'href' => $aItem['link']
  88. ));
  89. else if(!empty($aItem['onclick']))
  90. $sResult = $this->getUnitMetaItemButtonSmall($aItem['title'], array(
  91. 'onclick' => $aItem['onclick']
  92. ));
  93. else
  94. $sResult = $this->getUnitMetaItemText($aItem['title']);
  95. return $sResult;
  96. }
  97. protected function _getUnitMetaItemButtonOrLink($sContent, $sName, $aAttrs = array())
  98. {
  99. if (!isset($aAttrs['href']))
  100. $aAttrs['href'] = 'javascript:';
  101. return $this->getUnitMetaItem($sName, $sContent, $aAttrs);
  102. }
  103. }
  104. /** @} */