BxTimelineMenuItemManage.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 Timeline Timeline
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxTemplMenu');
  12. /**
  13. * 'Item' menu.
  14. */
  15. class BxTimelineMenuItemManage extends BxTemplMenu
  16. {
  17. protected $_aEvent;
  18. protected $_oModule;
  19. public function __construct($aObject, $oTemplate = false)
  20. {
  21. parent::__construct($aObject, $oTemplate);
  22. $this->_oModule = BxDolModule::getInstance('bx_timeline');
  23. $this->addMarkers(array(
  24. 'js_object_view' => $this->_oModule->_oConfig->getJsObject('view'),
  25. ));
  26. }
  27. public function setEvent($aEvent)
  28. {
  29. if(empty($aEvent) || !is_array($aEvent))
  30. return;
  31. $this->_aEvent = $aEvent;
  32. $this->addMarkers(array(
  33. 'content_id' => $aEvent['id'],
  34. ));
  35. }
  36. public function isVisible()
  37. {
  38. if(!isset($this->_aObject['menu_items']))
  39. $this->_aObject['menu_items'] = $this->_oQuery->getMenuItems();
  40. $bVisible = false;
  41. foreach ($this->_aObject['menu_items'] as $a) {
  42. if((isset($a['active']) && !$a['active']) || (isset($a['visible_for_levels']) && !$this->_isVisible($a)))
  43. continue;
  44. $bVisible = true;
  45. break;
  46. }
  47. return $bVisible;
  48. }
  49. /**
  50. * Check if menu items is visible.
  51. * @param $a menu item array
  52. * @return boolean
  53. */
  54. protected function _isVisible ($a)
  55. {
  56. if(!parent::_isVisible($a))
  57. return false;
  58. $sCheckFuncName = '';
  59. $aCheckFuncParams = array();
  60. switch ($a['name']) {
  61. case 'item-delete':
  62. $sCheckFuncName = 'isAllowedDelete';
  63. if(!empty($this->_aEvent))
  64. $aCheckFuncParams = array($this->_aEvent);
  65. break;
  66. }
  67. if(!$sCheckFuncName || !method_exists($this->_oModule, $sCheckFuncName))
  68. return true;
  69. return call_user_func_array(array($this->_oModule, $sCheckFuncName), $aCheckFuncParams) === true;
  70. }
  71. }
  72. /** @} */