BxBaseCmtsMenuActions.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Menu representation.
  11. * @see BxDolMenu
  12. */
  13. class BxBaseCmtsMenuActions extends BxTemplMenuCustom
  14. {
  15. protected $_oCmts;
  16. protected $_aCmt;
  17. public function __construct ($aObject, $oTemplate)
  18. {
  19. parent::__construct ($aObject, $oTemplate);
  20. }
  21. public function setCmtsData($oCmts, $iCmtId)
  22. {
  23. if(empty($oCmts) || empty($iCmtId))
  24. return;
  25. $this->_oCmts = $oCmts;
  26. $this->_aCmt = $oCmts->getCommentRow($iCmtId);
  27. $sJsObject = $oCmts->getJsObjectName();
  28. $this->addMarkers(array(
  29. 'js_object' => $sJsObject,
  30. 'cmt_system' => $this->_oCmts->getSystemName(),
  31. 'cmt_id' => $this->_oCmts->getId(),
  32. 'content_id' => $iCmtId,
  33. 'reply_onclick' => $sJsObject . '.toggleReply(this, ' . $iCmtId . ')'
  34. ));
  35. }
  36. protected function _getMenuItemItemVote($aItem)
  37. {
  38. $oVote = $this->_oCmts->getVoteObject($this->_aCmt['cmt_unique_id']);
  39. if(!$oVote)
  40. return false;
  41. return $oVote->getElementInline(array('dynamic_mode' => $this->_bDynamicMode));
  42. }
  43. /**
  44. * Check if menu items is visible.
  45. * @param $a menu item array
  46. * @return boolean
  47. */
  48. protected function _isVisible ($a)
  49. {
  50. if(!parent::_isVisible($a))
  51. return false;
  52. $sCheckFuncName = '';
  53. $aCheckFuncParams = array();
  54. switch ($a['name']) {
  55. case 'item-vote':
  56. $sCheckFuncName = 'isVoteAllowed';
  57. if(!empty($this->_aCmt))
  58. $aCheckFuncParams = array($this->_aCmt);
  59. break;
  60. case 'item-reply':
  61. $sCheckFuncName = 'isPostReplyAllowed';
  62. break;
  63. }
  64. if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
  65. return true;
  66. return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
  67. }
  68. }
  69. /** @} */