BxBaseModProfilePageEntry.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Profile create/edit/delete pages.
  13. */
  14. class BxBaseModProfilePageEntry extends BxBaseModGeneralPageEntry
  15. {
  16. protected $_aProfileInfo;
  17. protected $_oProfile;
  18. public function __construct($aObject, $oTemplate = false)
  19. {
  20. parent::__construct($aObject, $oTemplate);
  21. $CNF = &$this->_oModule->_oConfig->CNF;
  22. // get profile info
  23. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  24. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  25. if ($iProfileId)
  26. $this->_oProfile = BxDolProfile::getInstance($iProfileId);
  27. if (!$this->_oProfile && $iContentId)
  28. $this->_oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  29. if ($this->_oProfile) {
  30. $this->_aProfileInfo = $this->_oProfile->getInfo();
  31. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_aProfileInfo['content_id']);
  32. }
  33. if (!$this->_aContentInfo || !$this->_oProfile || (!$this->_oProfile->isActive() && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)) {
  34. $this->setPageCover(false);
  35. return;
  36. }
  37. // select view profile submenu
  38. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  39. $oMenuSubmenu->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'], array (
  40. 'title' => $this->_oProfile->getDisplayName(),
  41. 'link' => $this->_oProfile->getUrl(),
  42. 'icon' => $CNF['ICON'],
  43. ));
  44. // add replaceable markers
  45. $this->addMarkers($this->_aProfileInfo); // every content field can be used as marker
  46. $this->addMarkers(array('profile_id' => $this->_oProfile->id())); // profile id field
  47. $this->addMarkers(array('display_name' => $this->_oProfile->getDisplayName())); // profile display name
  48. $this->addMarkers(array('profile_link' => $this->_oProfile->getUrl())); // profile link
  49. // display message if profile isn't active
  50. $aInformers = array ();
  51. $oInformer = BxDolInformer::getInstance($this->_oTemplate);
  52. if (bx_get_logged_profile_id() == $this->_oProfile->id() && !empty($CNF['INFORMERS']['status']) && $oInformer) {
  53. $sStatus = $this->_aContentInfo['profile_status'];
  54. if (isset($CNF['INFORMERS']['status']['map'][$sStatus]))
  55. $aInformers[] = array ('name' => $CNF['INFORMERS']['status']['name'], 'msg' => _t($CNF['INFORMERS']['status']['map'][$sStatus]), 'type' => BX_INFORMER_ALERT);
  56. }
  57. // display message if it is possible to switch to this profile
  58. if ($this->_oModule->serviceActAsProfile()) {
  59. $oProfile = $this->_aContentInfo ? BxDolProfile::getInstanceByContentTypeAccount($this->_aContentInfo['id'], $this->MODULE) : false;
  60. if ($oProfile)
  61. $oProfile->checkSwitchToProfile($this->_oTemplate);
  62. }
  63. // add informers
  64. if ($aInformers && $oInformer) {
  65. foreach ($aInformers as $a)
  66. $oInformer->add($a['name'], $this->_replaceMarkers($a['msg']), $a['type']);
  67. }
  68. // set cover
  69. $this->_oModule->_oTemplate->setCover($this->_aContentInfo);
  70. }
  71. public function getCode ()
  72. {
  73. // check if profile is active
  74. if (!$this->_oProfile || (!$this->_oProfile->isActive() && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)) {
  75. $this->_oTemplate->displayPageNotFound();
  76. exit;
  77. }
  78. return parent::getCode();
  79. }
  80. protected function _processPermissionsCheck ()
  81. {
  82. $CNF = &$this->_oModule->_oConfig->CNF;
  83. bx_import('BxDolPrivacy');
  84. $mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo);
  85. if ($CNF['OBJECT_PAGE_VIEW_ENTRY'] == $this->_sObject) {
  86. if ((BX_DOL_PG_HIDDEN == $this->_aContentInfo['allow_view_to'] || BX_DOL_PG_MEONLY == $this->_aContentInfo['allow_view_to']) && CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
  87. $this->_oTemplate->displayAccessDenied($mixedAllowView);
  88. exit;
  89. }
  90. elseif (CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
  91. // replace current page with different set of blocks
  92. $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
  93. $this->_sObject = $aObject['object'];
  94. $this->_aObject = $aObject;
  95. $this->_oQuery = new BxDolPageQuery($this->_aObject);
  96. }
  97. }
  98. elseif (CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
  99. $this->_oTemplate->displayAccessDenied($mixedAllowView);
  100. exit;
  101. }
  102. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  103. }
  104. }
  105. /** @} */