1
0

BxBaseVoteReactionsMenuDo.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 BxBaseVoteReactionsMenuDo extends BxTemplMenu
  14. {
  15. protected $_iValue;
  16. protected $_oObject;
  17. public function __construct($aObject, $oTemplate)
  18. {
  19. parent::__construct ($aObject, $oTemplate);
  20. }
  21. public function setParams($aParams)
  22. {
  23. if(empty($aParams['object']) || !is_a($aParams['object'], 'BxTemplVoteReactions'))
  24. return;
  25. $this->_oObject = $aParams['object'];
  26. $this->_iValue = isset($aParams['value']) ? (int)$aParams['value'] : $this->_oObject->getValue();
  27. }
  28. protected function getMenuItemsRaw()
  29. {
  30. $sJsObject = $this->_oObject->getJsObjectName();
  31. $aReactions = $this->_oObject->getReactions(true);
  32. $sDefault = $this->_oObject->getDefault();
  33. $aMenuItems = array();
  34. foreach($aReactions as $sName => $aReaction) {
  35. if($sName == $sDefault)
  36. continue;
  37. $aMenuItems[] = array(
  38. 'id' => $sName,
  39. 'name' => $sName,
  40. 'class' => '',
  41. 'link' => 'javascript:void(0)',
  42. 'onclick' => 'javascript:' . $this->_oObject->getJsClickDo($sName, $this->_iValue),
  43. 'target' => '_self',
  44. 'title' => _t($aReaction['title']),
  45. 'icon' => $this->_oObject->getIcon($sName),
  46. 'active' => 1
  47. );
  48. }
  49. return $aMenuItems;
  50. }
  51. protected function _getMenuItem ($a)
  52. {
  53. $aResult = parent::_getMenuItem($a);
  54. if(empty($aResult) || !is_array($aResult))
  55. return $aResult;
  56. $aResult['title'] = '';
  57. $aResult['bx_if:title']['condition'] = false;
  58. return $aResult;
  59. }
  60. }
  61. /** @} */