BxBaseCmtsMenuManage.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Menu representation.
  11. * @see BxDolMenu
  12. */
  13. class BxBaseCmtsMenuManage extends BxTemplMenu
  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. $this->addMarkers(array(
  28. 'js_object' => $oCmts->getJsObjectName(),
  29. 'content_id' => $iCmtId,
  30. ));
  31. }
  32. /**
  33. * Check if menu items is visible.
  34. * @param $a menu item array
  35. * @return boolean
  36. */
  37. protected function _isVisible ($a)
  38. {
  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. }
  55. if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
  56. return true;
  57. return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
  58. }
  59. }
  60. /** @} */