BxBaseModProfilePageEntry.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /**
  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. $aInformers = array ();
  23. // get profile info
  24. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  25. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  26. if ($iProfileId)
  27. $this->_oProfile = BxDolProfile::getInstance($iProfileId);
  28. if (!$this->_oProfile && $iContentId)
  29. $this->_oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  30. if ($this->_oProfile) {
  31. $this->_aProfileInfo = $this->_oProfile->getInfo();
  32. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_aProfileInfo['content_id']);
  33. }
  34. if (!$this->_aContentInfo || !$this->_oProfile)
  35. return;
  36. // select view profile submenu
  37. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  38. $oMenuSubmenu->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'], array (
  39. 'title' => $this->_oProfile->getDisplayName(),
  40. 'link' => $this->_oProfile->getUrl(),
  41. 'icon' => $this->_oProfile->getIcon(),
  42. ));
  43. // add replaceable markers
  44. $this->addMarkers($this->_aProfileInfo); // every content field can be used as marker
  45. $this->addMarkers(array('profile_id' => $this->_oProfile->id())); // profile id field
  46. $this->addMarkers(array('display_name' => $this->_oProfile->getDisplayName())); // profile display name
  47. $this->addMarkers(array('profile_link' => $this->_oProfile->getUrl())); // profile link
  48. // display message if profile isn't active
  49. if (bx_get_logged_profile_id() == $this->_oProfile->id() && !empty($CNF['INFORMERS']['status'])) {
  50. $sStatus = $this->_aContentInfo['profile_status'];
  51. if (isset($CNF['INFORMERS']['status']['map'][$sStatus]))
  52. $aInformers[] = array ('name' => $CNF['INFORMERS']['status']['name'], 'msg' => _t($CNF['INFORMERS']['status']['map'][$sStatus]), 'type' => BX_INFORMER_ALERT);
  53. }
  54. // display message if it is possible to switch to this profile
  55. $oProfile = $this->_aContentInfo ? BxDolProfile::getInstanceByContentTypeAccount($this->_aContentInfo['id'], $this->MODULE) : false;
  56. if ($oProfile)
  57. $oProfile->checkSwitchToProfile($this->_oTemplate);
  58. // add informers
  59. if ($aInformers) {
  60. $oInformer = BxDolInformer::getInstance($this->_oTemplate);
  61. if ($oInformer) {
  62. foreach ($aInformers as $a)
  63. $oInformer->add($a['name'], $this->_replaceMarkers($a['msg']), $a['type']);
  64. }
  65. }
  66. }
  67. }
  68. /** @} */