BxBaseCmtsMenu.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxTemplMenu');
  10. /**
  11. * Menu representation.
  12. * @see BxDolMenu
  13. */
  14. class BxBaseCmtsMenu extends BxTemplMenu
  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. $sVotesOnclick = '';
  29. $oVote = $this->_oCmts->getVoteObject($iCmtId);
  30. if($oVote !== false)
  31. $sVotesOnclick = $oVote->getJsClick();
  32. $sJsObject = $oCmts->getJsObjectName();
  33. $this->addMarkers(array(
  34. 'js_object' => $sJsObject,
  35. 'cmt_system' => $this->_oCmts->getSystemName(),
  36. 'cmt_id' => $this->_oCmts->getId(),
  37. 'content_id' => $iCmtId,
  38. 'vote_onclick' => $sVotesOnclick,
  39. 'reply_onclick' => $sJsObject . '.toggleReply(this, ' . $iCmtId . ')'
  40. ));
  41. }
  42. /**
  43. * Check if menu items is visible.
  44. * @param $a menu item array
  45. * @return boolean
  46. */
  47. protected function _isVisible ($a) {
  48. if(!parent::_isVisible($a))
  49. return false;
  50. $sCheckFuncName = '';
  51. $aCheckFuncParams = array();
  52. switch ($a['name']) {
  53. case 'item-edit':
  54. $sCheckFuncName = 'isEditAllowed';
  55. if(!empty($this->_aCmt))
  56. $aCheckFuncParams = array($this->_aCmt);
  57. break;
  58. case 'item-delete':
  59. $sCheckFuncName = 'isRemoveAllowed';
  60. if(!empty($this->_aCmt))
  61. $aCheckFuncParams = array($this->_aCmt);
  62. break;
  63. case 'item-vote':
  64. $sCheckFuncName = 'isVoteAllowed';
  65. if(!empty($this->_aCmt))
  66. $aCheckFuncParams = array($this->_aCmt);
  67. break;
  68. case 'item-reply':
  69. $sCheckFuncName = 'isPostReplyAllowed';
  70. break;
  71. }
  72. if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
  73. return true;
  74. return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
  75. }
  76. }
  77. /** @} */