BxBaseCmtsMenu.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. bx_import('BxTemplMenuCustom');
  10. /**
  11. * Menu representation.
  12. * @see BxDolMenu
  13. */
  14. class BxBaseCmtsMenu extends BxTemplMenuCustom
  15. {
  16. protected $_oCmts;
  17. protected $_aCmt;
  18. public function __construct ($aObject, $oTemplate)
  19. {
  20. parent::__construct ($aObject, $oTemplate);
  21. }
  22. public function setCmtsData($oCmts, $iCmtId)
  23. {
  24. if(empty($oCmts) || empty($iCmtId))
  25. return;
  26. $this->_oCmts = $oCmts;
  27. $this->_aCmt = $oCmts->getCommentRow($iCmtId);
  28. $sJsObject = $oCmts->getJsObjectName();
  29. $this->addMarkers(array(
  30. 'js_object' => $sJsObject,
  31. 'cmt_system' => $this->_oCmts->getSystemName(),
  32. 'cmt_id' => $this->_oCmts->getId(),
  33. 'content_id' => $iCmtId,
  34. 'reply_onclick' => $sJsObject . '.toggleReply(this, ' . $iCmtId . ')'
  35. ));
  36. }
  37. protected function _getMenuItemItemVote($aItem)
  38. {
  39. $oVote = $this->_oCmts->getVoteObject($this->_aCmt['cmt_unique_id']);
  40. if(!$oVote)
  41. return false;
  42. return $oVote->getElementInline();
  43. }
  44. /**
  45. * Check if menu items is visible.
  46. * @param $a menu item array
  47. * @return boolean
  48. */
  49. protected function _isVisible ($a)
  50. {
  51. if(!parent::_isVisible($a))
  52. return false;
  53. $sCheckFuncName = '';
  54. $aCheckFuncParams = array();
  55. switch ($a['name']) {
  56. case 'item-edit':
  57. $sCheckFuncName = 'isEditAllowed';
  58. if(!empty($this->_aCmt))
  59. $aCheckFuncParams = array($this->_aCmt);
  60. break;
  61. case 'item-delete':
  62. $sCheckFuncName = 'isRemoveAllowed';
  63. if(!empty($this->_aCmt))
  64. $aCheckFuncParams = array($this->_aCmt);
  65. break;
  66. case 'item-vote':
  67. $sCheckFuncName = 'isVoteAllowed';
  68. if(!empty($this->_aCmt))
  69. $aCheckFuncParams = array($this->_aCmt);
  70. break;
  71. case 'item-reply':
  72. $sCheckFuncName = 'isPostReplyAllowed';
  73. break;
  74. }
  75. if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
  76. return true;
  77. return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
  78. }
  79. }
  80. /** @} */