BxBaseModProfilePageEntry.php 3.5 KB

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