1
0

BxBaseModGroupsAddContent.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGroupsAddContent extends BxBaseMenu
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_iContentId;
  16. protected $_aContentInfo;
  17. protected $_oContentProfile;
  18. public function __construct($aObject, $oTemplate = false)
  19. {
  20. parent::__construct($aObject, $oTemplate);
  21. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  22. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  23. if(empty($iContentId) && bx_get('profile_id') !== false)
  24. $iContentId = BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getContentId();
  25. if(!empty($iContentId))
  26. $this->setContentId($iContentId);
  27. }
  28. public function setContentId($iContentId)
  29. {
  30. $this->_iContentId = $iContentId;
  31. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  32. if(empty($this->_aContentInfo) || !is_array($this->_aContentInfo))
  33. return;
  34. $this->_oContentProfile = BxDolProfile::getInstanceByContentAndType($this->_iContentId, $this->_sModule);
  35. if(!$this->_oContentProfile)
  36. return;
  37. $this->addMarkers(array(
  38. 'profile_id' => $this->_oContentProfile->id()
  39. ));
  40. }
  41. protected function getMenuItemsRaw ()
  42. {
  43. $aMenuItems = parent::getMenuItemsRaw();
  44. $iContextPid = $this->_oContentProfile->id();
  45. $aResult = [];
  46. foreach($aMenuItems as $iKey => $aMenuItem) {
  47. if((int)$aMenuItem['active'] == 0)
  48. continue;
  49. if(bx_srv($aMenuItem['module'], 'check_allowed_add_in_context', [$this->_sModule]) !== CHECK_ACTION_RESULT_ALLOWED)
  50. continue;
  51. if(bx_srv($this->_sModule, 'check_allowed_post_in_profile', [$this->_iContentId, $aMenuItem['module']]) !== CHECK_ACTION_RESULT_ALLOWED)
  52. continue;
  53. $aResult[$iKey] = array_merge($aMenuItem, [
  54. 'link' => bx_append_url_params($aMenuItem['link'], ['context_pid' => $iContextPid])
  55. ]);
  56. }
  57. return $aResult;
  58. }
  59. }
  60. /** @} */