BxBaseCmtsMenu.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. $this->addMarkers(array(
  33. 'js_object' => $oCmts->getJsObjectName(),
  34. 'vote_onclick' => $sVotesOnclick,
  35. 'content_id' => $iCmtId
  36. ));
  37. }
  38. /**
  39. * Check if menu items is visible.
  40. * @param $a menu item array
  41. * @return boolean
  42. */
  43. protected function _isVisible ($a) {
  44. if(!parent::_isVisible($a))
  45. return false;
  46. $sCheckFuncName = '';
  47. $aCheckFuncParams = array();
  48. switch ($a['name']) {
  49. case 'item-edit':
  50. $sCheckFuncName = 'isEditAllowed';
  51. if(!empty($this->_aCmt))
  52. $aCheckFuncParams = array($this->_aCmt);
  53. break;
  54. case 'item-delete':
  55. $sCheckFuncName = 'isRemoveAllowed';
  56. if(!empty($this->_aCmt))
  57. $aCheckFuncParams = array($this->_aCmt);
  58. break;
  59. case 'item-vote':
  60. $sCheckFuncName = 'isVoteAllowed';
  61. if(!empty($this->_aCmt))
  62. $aCheckFuncParams = array($this->_aCmt);
  63. break;
  64. case 'item-reply':
  65. $sCheckFuncName = 'isPostReplyAllowed';
  66. break;
  67. }
  68. if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
  69. return true;
  70. return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
  71. }
  72. /**
  73. * Get menu items array, which are ready to pass to template.
  74. * @return array
  75. */
  76. protected function _getMenuItems() {
  77. $aItems = parent::_getMenuItems();
  78. foreach($aItems as $iKey => $aItem)
  79. switch($aItem['name']) {
  80. case 'item-vote':
  81. $oVote = $this->_oCmts->getVoteObject($this->_aCmt['cmt_id']);
  82. if($oVote !== false)
  83. $aItems[$iKey]['addon'] = $oVote->getCounter();
  84. break;
  85. }
  86. return $aItems;
  87. }
  88. }
  89. /** @} */