BxBaseModProfilePageEntry.php 3.3 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 BaseProfile Base classes for profile modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxBaseModGeneralPageEntry');
  12. bx_import('BxDolModule');
  13. bx_import('BxDolMenu');
  14. bx_import('BxDolProfile');
  15. bx_import('BxDolInformer');
  16. /**
  17. * Profile create/edit/delete pages.
  18. */
  19. class BxBaseModProfilePageEntry extends BxBaseModGeneralPageEntry
  20. {
  21. protected $_aProfileInfo;
  22. protected $_oProfile;
  23. public function __construct($aObject, $oTemplate = false)
  24. {
  25. parent::__construct($aObject, $oTemplate);
  26. $CNF = &$this->_oModule->_oConfig->CNF;
  27. $aInformers = array ();
  28. // get profile info
  29. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  30. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  31. if ($iProfileId)
  32. $this->_oProfile = BxDolProfile::getInstance($iProfileId);
  33. if (!$this->_oProfile && $iContentId)
  34. $this->_oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  35. if ($this->_oProfile) {
  36. $this->_aProfileInfo = $this->_oProfile->getInfo();
  37. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_aProfileInfo['content_id']);
  38. }
  39. if (!$this->_aContentInfo || !$this->_oProfile)
  40. return;
  41. // select view profile submenu
  42. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  43. $oMenuSubmenu->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'], array (
  44. 'title' => $this->_oProfile->getDisplayName(),
  45. 'link' => $this->_oProfile->getUrl(),
  46. 'icon' => $this->_oProfile->getIcon(),
  47. ));
  48. // add replaceable markers
  49. $this->addMarkers($this->_aProfileInfo); // every content field can be used as marker
  50. $this->addMarkers(array('profile_id' => $this->_oProfile->id())); // profile id field is also suported
  51. $this->addMarkers(array('display_name' => $this->_oProfile->getDisplayName())); // profile display name is also suported
  52. // display message if profile isn't active
  53. if (bx_get_logged_profile_id() == $this->_oProfile->id() && !empty($CNF['INFORMERS']['status'])) {
  54. $sStatus = $this->_aContentInfo['profile_status'];
  55. if (isset($CNF['INFORMERS']['status']['map'][$sStatus]))
  56. $aInformers[] = array ('name' => $CNF['INFORMERS']['status']['name'], 'msg' => _t($CNF['INFORMERS']['status']['map'][$sStatus]), 'type' => BX_INFORMER_ALERT);
  57. }
  58. // display message if it is possible to switch to this profile
  59. $oProfile = $this->_aContentInfo ? BxDolProfile::getInstanceByContentTypeAccount($this->_aContentInfo['id'], $this->MODULE) : false;
  60. if ($oProfile)
  61. $oProfile->checkSwitchToProfile($this->_oTemplate);
  62. // add informers
  63. if ($aInformers) {
  64. $oInformer = BxDolInformer::getInstance($this->_oTemplate);
  65. if ($oInformer) {
  66. foreach ($aInformers as $a)
  67. $oInformer->add($a['name'], $this->_replaceMarkers($a['msg']), $a['type']);
  68. }
  69. }
  70. }
  71. }
  72. /** @} */