BxBaseMenuUnitMeta.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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->getUnitMetaItem('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->getUnitMetaItem('button', $sContent, $aAttrs);
  32. }
  33. public function getUnitMetaItemButtonSmall($sContent, $aAttrs = array())
  34. {
  35. return $this->getUnitMetaItem('sbutton', $sContent, $aAttrs);
  36. }
  37. public function getUnitMetaItemCustom($sContent)
  38. {
  39. return $this->getUnitMetaItem('custom', $sContent);
  40. }
  41. public function getUnitMetaItem($sName, $sContent, $aAttrs = array(), $sTemplate = 'unit_meta_item.html')
  42. {
  43. if(empty($sContent))
  44. return '';
  45. if(!is_array($aAttrs))
  46. $aAttrs = array();
  47. $aTags = array('span', 'a', 'button', 'sbutton', 'custom');
  48. $sTmplVarsClass = '';
  49. if(!empty($aAttrs['class'])) {
  50. $sTmplVarsClass = $aAttrs['class'];
  51. unset($aAttrs['class']);
  52. }
  53. $aTmplVarsAttrs = array();
  54. foreach($aAttrs as $sKey => $sValue)
  55. $aTmplVarsAttrs[] = array('key' => $sKey, 'value' => bx_html_attribute($sValue));
  56. $aTmplVars = array();
  57. foreach($aTags as $sTag) {
  58. $aTmplVarsTag = array();
  59. $bTmplVarsTag = $sTag == $sName;
  60. if($bTmplVarsTag)
  61. $aTmplVarsTag = array(
  62. 'style_prefix' => $this->_sStylePrefix,
  63. 'class' => $sTmplVarsClass,
  64. 'content' => $sContent,
  65. 'bx_repeat:attrs' => $aTmplVarsAttrs
  66. );
  67. $aTmplVars['bx_if:' . $sTag] = array(
  68. 'condition' => $bTmplVarsTag,
  69. 'content' => $aTmplVarsTag
  70. );
  71. }
  72. return $this->_oTemplate->parseHtmlByName($sTemplate, $aTmplVars);
  73. }
  74. protected function _getMenuItemDefault($aItem)
  75. {
  76. $sResult = '';
  77. if(!empty($aItem['link']))
  78. $sResult = $this->getUnitMetaItemLink($aItem['title'], array(
  79. 'href' => $aItem['link']
  80. ));
  81. else if(!empty($aItem['onclick']))
  82. $sResult = $this->getUnitMetaItemButtonSmall($aItem['title'], array(
  83. 'onclick' => $aItem['onclick']
  84. ));
  85. else
  86. $sResult = $this->getUnitMetaItemText($aItem['title']);
  87. return $sResult;
  88. }
  89. }
  90. /** @} */