1
0

BxBaseVoteReactionsMenuDo.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. $sIcon = '';
  38. switch($aReaction['use']) {
  39. case 'icon':
  40. $sIcon = $this->_oObject->getIcon($sName);
  41. break;
  42. case 'emoji':
  43. $sIcon = $this->_oObject->getEmoji($sName);
  44. break;
  45. case 'image':
  46. $sIcon = $this->_oObject->getImage($sName);
  47. break;
  48. }
  49. $aMenuItems[] = array(
  50. 'id' => $sName,
  51. 'name' => $sName,
  52. 'class' => '',
  53. 'link' => 'javascript:void(0)',
  54. 'onclick' => 'javascript:' . $this->_oObject->getJsClickDo($sName, $this->_iValue),
  55. 'target' => '_self',
  56. 'title' => _t($aReaction['title']),
  57. 'icon' => $sIcon,
  58. 'active' => 1
  59. );
  60. }
  61. return $aMenuItems;
  62. }
  63. protected function _getMenuItem ($a)
  64. {
  65. $aResult = parent::_getMenuItem($a);
  66. if(empty($aResult) || !is_array($aResult))
  67. return $aResult;
  68. $aResult['title'] = '';
  69. $aResult['bx_if:title']['condition'] = false;
  70. return $aResult;
  71. }
  72. protected function _getMenuAttrs ($a)
  73. {
  74. $sResult = parent::_getMenuAttrs($a);
  75. $sResult .= 'title = "' . bx_html_attribute(_t($a['title'])) . '"';
  76. return $sResult;
  77. }
  78. }
  79. /** @} */