BxBaseCmtsMenu.php 2.2 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 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. $this->addMarkers(array(
  29. 'js_object' => $oCmts->getJsObjectName(),
  30. 'content_id' => $iCmtId
  31. ));
  32. }
  33. /**
  34. * Check if menu items is visible.
  35. * @param $a menu item array
  36. * @return boolean
  37. */
  38. protected function _isVisible ($a) {
  39. if(!parent::_isVisible($a))
  40. return false;
  41. $sCheckFuncName = '';
  42. $aCheckFuncParams = array();
  43. switch ($a['name']) {
  44. case 'item-edit':
  45. $sCheckFuncName = 'isEditAllowed';
  46. if(!empty($this->_aCmt))
  47. $aCheckFuncParams = array($this->_aCmt);
  48. break;
  49. case 'item-delete':
  50. $sCheckFuncName = 'isRemoveAllowed';
  51. if(!empty($this->_aCmt))
  52. $aCheckFuncParams = array($this->_aCmt);
  53. break;
  54. case 'item-reply':
  55. $sCheckFuncName = 'isPostReplyAllowed';
  56. break;
  57. case 'item-rate-plus':
  58. /*
  59. //TODO: remove if Minus won't be used
  60. if(!empty($this->_aCmt) && (int)$this->_aCmt['cmt_rated'] > 0)
  61. return false;
  62. */
  63. $sCheckFuncName = 'isRateAllowed';
  64. break;
  65. /*
  66. //TODO: remove if Minus won't be used
  67. case 'item-rate-minus':
  68. if(!empty($this->_aCmt) && (int)$this->_aCmt['cmt_rated'] <= 0)
  69. return false;
  70. $sCheckFuncName = 'isRateAllowed';
  71. break;
  72. */
  73. }
  74. if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
  75. return true;
  76. return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
  77. }
  78. }
  79. /** @} */