BxTimelineMenuItemActions.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * 'Item' menu.
  13. */
  14. class BxTimelineMenuItemActions extends BxTemplMenuCustom
  15. {
  16. protected $_aEvent;
  17. protected $_oModule;
  18. public function __construct($aObject, $oTemplate = false)
  19. {
  20. parent::__construct($aObject, $oTemplate);
  21. $this->_oModule = BxDolModule::getInstance('bx_timeline');
  22. }
  23. public function setEvent($sView, $aEvent)
  24. {
  25. if(empty($aEvent) || !is_array($aEvent))
  26. return;
  27. $this->_aEvent = $aEvent;
  28. $iCommentsObject = 0;
  29. $sCommentsSystem = $sCommentsOnclick = '';
  30. if(isset($aEvent['comments']) && is_array($aEvent['comments']) && isset($aEvent['comments']['system'])) {
  31. $sCommentsSystem = $aEvent['comments']['system'];
  32. $iCommentsObject = $aEvent['comments']['object_id'];
  33. $sCommentsOnclick = $this->_oModule->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sCommentsSystem . "', " . $iCommentsObject . ")";
  34. }
  35. $this->addMarkers(array(
  36. 'js_object_view' => $this->_oModule->_oConfig->getJsObject('view_' . $sView),
  37. 'view' => $sView,
  38. 'content_id' => $aEvent['id'],
  39. 'comment_system' => $sCommentsSystem,
  40. 'comment_object' => $iCommentsObject,
  41. 'comment_onclick' => $sCommentsOnclick,
  42. ));
  43. }
  44. public function isVisible()
  45. {
  46. if(!isset($this->_aObject['menu_items']))
  47. $this->_aObject['menu_items'] = $this->_oQuery->getMenuItems();
  48. $bVisible = false;
  49. foreach ($this->_aObject['menu_items'] as $a) {
  50. if((isset($a['active']) && !$a['active']) || (isset($a['visible_for_levels']) && !$this->_isVisible($a)))
  51. continue;
  52. $bVisible = true;
  53. break;
  54. }
  55. return $bVisible;
  56. }
  57. protected function _getMenuItemItemVote($aItem)
  58. {
  59. if(!isset($this->_aEvent['votes']) || !is_array($this->_aEvent['votes']) || !isset($this->_aEvent['votes']['system']))
  60. return false;
  61. $sVotesSystem = $this->_aEvent['votes']['system'];
  62. $iVotesObject = $this->_aEvent['votes']['object_id'];
  63. return $this->_oModule->getVoteObject($sVotesSystem, $iVotesObject)->getElementInline(array('dynamic_mode' => $this->_bDynamicMode));
  64. }
  65. protected function _getMenuItemItemReport($aItem)
  66. {
  67. if(!isset($this->_aEvent['reports']) || !is_array($this->_aEvent['reports']) || !isset($this->_aEvent['reports']['system']))
  68. return false;
  69. $sReportsSystem = $this->_aEvent['reports']['system'];
  70. $iReportsObject = $this->_aEvent['reports']['object_id'];
  71. return $this->_oModule->getReportObject($sReportsSystem, $iReportsObject)->getElementInline(array('dynamic_mode' => $this->_bDynamicMode));
  72. }
  73. protected function _getMenuItemItemShare($aItem)
  74. {
  75. $iOwnerId = $this->_oModule->getUserId(); //--- in whose timeline the content will be shared
  76. $sType = $this->_aEvent['type'];
  77. $sAction = $this->_aEvent['action'];
  78. $iObjectId = $this->_oModule->_oConfig->isSystem($sType, $sAction) ? $this->_aEvent['object_id'] : $this->_aEvent['id'];
  79. return $this->_oModule->serviceGetShareElementBlock($iOwnerId, $sType, $sAction, $iObjectId);
  80. }
  81. /**
  82. * Check if menu items is visible.
  83. * @param $a menu item array
  84. * @return boolean
  85. */
  86. protected function _isVisible ($a)
  87. {
  88. if(!parent::_isVisible($a) || empty($this->_aEvent))
  89. return false;
  90. $sCheckFuncName = '';
  91. $aCheckFuncParams = array($this->_aEvent);
  92. switch ($a['name']) {
  93. case 'item-comment':
  94. $sCheckFuncName = 'isAllowedComment';
  95. break;
  96. case 'item-vote':
  97. $sCheckFuncName = 'isAllowedVote';
  98. break;
  99. case 'item-report':
  100. $sCheckFuncName = 'isAllowedReport';
  101. break;
  102. case 'item-more':
  103. $sCheckFuncName = 'isAllowedMore';
  104. break;
  105. }
  106. if(!$sCheckFuncName || !method_exists($this->_oModule, $sCheckFuncName))
  107. return true;
  108. return call_user_func_array(array($this->_oModule, $sCheckFuncName), $aCheckFuncParams) === true;
  109. }
  110. }
  111. /** @} */