BxBaseMenuCreatePost.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 BxBaseMenuCreatePost extends BxTemplMenuCustom
  14. {
  15. protected $_sJsObject;
  16. protected $_mixedContextId;
  17. public function __construct ($aObject, $oTemplate)
  18. {
  19. parent::__construct ($aObject);
  20. $this->_aObject['menu_id'] = 'sys-create-post-menu';
  21. $this->_bShowDivider = false;
  22. $this->_sJsObject = 'oBxDolCreatePost';
  23. $this->_mixedContextId = false;
  24. }
  25. public function setContextId($mixedContextId)
  26. {
  27. $this->_mixedContextId = $mixedContextId;
  28. }
  29. protected function getMenuItemsRaw ()
  30. {
  31. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'all_pairs_name_uri', 'active' => 1));
  32. $aResult = array();
  33. $aMenuItems = $this->_oQuery->getMenuItems();
  34. foreach($aMenuItems as $iKey => $aMenuItem) {
  35. if((int)$aMenuItem['active'] == 0)
  36. continue;
  37. $sModule = $aMenuItem['module'];
  38. if(!isset($aModules[$sModule]))
  39. continue;
  40. if(BxDolRequest::serviceExists($sModule, 'act_as_profile'))
  41. continue;
  42. if($this->_mixedContextId !== false && ($aContextInfo = BxDolProfileQuery::getInstance()->getInfoById(abs($this->_mixedContextId))))
  43. if(bx_srv($aContextInfo['type'], 'check_allowed_post_in_profile', [$aContextInfo['content_id'], $sModule]) !== CHECK_ACTION_RESULT_ALLOWED)
  44. continue;
  45. $aResult[$iKey] = array_merge($aMenuItem, array(
  46. 'id' => $sModule,
  47. 'name' => $sModule,
  48. 'onclick' => "return " . $this->_sJsObject . ".getForm('" . $sModule . "', '" . $aModules[$sModule] . "', this)"
  49. ));
  50. }
  51. if(!empty($aResult) && is_array($aResult))
  52. $aResult['more-auto'] = array(
  53. 'module' => 'system',
  54. 'id' => 'more-auto',
  55. 'name' => 'more-auto',
  56. 'title' => '_sys_menu_item_title_va_more_auto_empty',
  57. 'href' => 'javascript:void(0)',
  58. 'icon' => 'ellipsis-v',
  59. 'active' => 1
  60. );
  61. return $aResult;
  62. }
  63. }
  64. /** @} */