BxBaseServiceProfiles.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 DolphinCore Dolphin Core
  7. * @{
  8. */
  9. /**
  10. * System service for profiles handling functionality.
  11. */
  12. class BxBaseServiceProfiles extends BxDol {
  13. public function __construct() {
  14. parent::__construct();
  15. }
  16. public function serviceProfilesList ($iAccountId = 0) {
  17. bx_import('BxDolProfileQuery');
  18. $oProfilesQuery = BxDolProfileQuery::getInstance();
  19. $aProfiles = $oProfilesQuery->getProfilesByAccount($iAccountId ? $iAccountId : getLoggedId());
  20. if (!$aProfiles)
  21. return false;
  22. $s = '';
  23. foreach ($aProfiles as $aProfile)
  24. if ($aProfile['type'] != 'system')
  25. $s .= BxDolService::call($aProfile['type'], 'profile_unit', array($aProfile['content_id']));
  26. if (!$s)
  27. $s = MsgBox(_t('_sys_txt_empty'));
  28. return $s . '<div class="bx-clear"></div>';
  29. }
  30. public function serviceAccountProfileSwitcher ($iAccountId = false) {
  31. bx_import('BxDolProfileQuery');
  32. $oProfilesQuery = BxDolProfileQuery::getInstance();
  33. $aProfiles = $oProfilesQuery->getProfilesByAccount($iAccountId ? $iAccountId : getLoggedId());
  34. if (!$aProfiles)
  35. return false;
  36. $iLoggedPofileId = bx_get_logged_profile_id();
  37. $aVars = array (
  38. 'bx_repeat:row' => array(),
  39. );
  40. foreach ($aProfiles as $aProfile) {
  41. //if ($aProfile['type'] == 'system')
  42. // continue;
  43. $aVars['bx_repeat:row'][] = array (
  44. 'bx_if:active' => array (
  45. 'condition' => $iLoggedPofileId == $aProfile['id'],
  46. 'content' => array('id' => $aProfile['id']),
  47. ),
  48. 'bx_if:inactive' => array (
  49. 'condition' => $iLoggedPofileId != $aProfile['id'],
  50. 'content' => array('id' => $aProfile['id'], 'url_switch' => BxDolPermalinks::getInstance()->permalink('page.php?i=account-profile-switcher', array('switch_to_profile' => $aProfile['id']))),
  51. ),
  52. 'unit' => BxDolService::call($aProfile['type'], 'profile_unit', array($aProfile['content_id'])),
  53. );
  54. }
  55. if (!$aVars['bx_repeat:row'])
  56. return MsgBox(_t('_sys_txt_empty'));
  57. bx_import('BxDolTemplate');
  58. $oTemplate = BxDolTemplate::getInstance();
  59. $oTemplate->addCss('account.css');
  60. return $oTemplate->parseHtmlByName('profile_switch_row.html', $aVars);
  61. }
  62. }
  63. /** @} */