BxAccntTemplate.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 Accounts Accounts
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxAccntTemplate extends BxBaseModGeneralTemplate
  12. {
  13. protected $aAuthTypes = [];
  14. function __construct(&$oConfig, &$oDb)
  15. {
  16. $this->MODULE = 'bx_accounts';
  17. parent::__construct($oConfig, $oDb);
  18. $this->aAuthTypes = BxDolDb::getInstance()->fromCache('sys_objects_auths', 'getAll', 'SELECT * FROM `sys_objects_auths`');
  19. }
  20. public function getProfilesByAccount($aContentInfo, $iMaxVisible = 2, $iMaxInPopup = 20)
  21. {
  22. $CNF = &$this->_oConfig->CNF;
  23. $iMax = $iMaxVisible + $iMaxInPopup;
  24. $aProfiles = BxDolAccount::getInstance($aContentInfo['id'])->getProfiles();
  25. $iProfiles = count($aProfiles);
  26. $aTmplVars = [
  27. 'class_cnt' => '',
  28. 'bx_repeat:profiles' => [],
  29. 'bx_if:profiles_more' => [
  30. 'condition' => $iProfiles > $iMaxVisible,
  31. 'content' => [
  32. 'html_id' => $this->_oConfig->getHtmlIds('profile_more_popup') . $aContentInfo['id'],
  33. 'more' => _t('_bx_accnt_txt_more', $iProfiles - $iMaxVisible),
  34. 'more_attr' => bx_html_attribute(_t('_bx_accnt_txt_see_more')),
  35. 'popup' => '',
  36. ],
  37. ],
  38. ];
  39. $aTmplVarsPopup = [
  40. 'bx_repeat:profiles' => [],
  41. ];
  42. if($iProfiles > $iMax)
  43. $aProfiles = array_slice($aProfiles, 0, $iMax);
  44. $i = 0;
  45. foreach ($aProfiles as $aProfile) {
  46. $oProfile = BxDolProfile::getInstance((int)$aProfile['id']);
  47. if(!$oProfile)
  48. continue;
  49. $iId = $oProfile->id();
  50. $sName = $oProfile->getDisplayName();
  51. $sAuthAccountsIcons = '';
  52. foreach ($this->aAuthTypes as $r) {
  53. $oModule = BxDolModule::getInstance($r['Name']);
  54. if (!$oModule)
  55. continue;
  56. if ($oModule->_oDb->getRemoteProfileId($iId))
  57. $sAuthAccountsIcons .= '<i title="' . bx_html_attribute(_t($r['Title'])) . '" class="sys-icon ' . ($r['Icon'] ? $r['Icon'] : 'circle-user') . '"></i> ';
  58. }
  59. $aTmplVarsProfile = [
  60. 'html_id' => $this->_oConfig->getHtmlIds('profile') . $iId,
  61. 'id' => $iId,
  62. 'url' => $oProfile->getUrl(),
  63. 'name' => strmaxtextlen($sName, $CNF['PARAM_PROFILE_NAME_LENGTH_MAX'], '...'),
  64. 'name_attr' => bx_html_attribute($sName),
  65. 'auth_accounts_icons' => $sAuthAccountsIcons,
  66. ];
  67. if($i < $iMaxVisible)
  68. $aTmplVars['bx_repeat:profiles'][] = $aTmplVarsProfile;
  69. if($i >= $iMaxVisible)
  70. $aTmplVarsPopup['bx_repeat:profiles'][] = $aTmplVarsProfile;
  71. ++$i;
  72. }
  73. if($aTmplVarsPopup['bx_repeat:profiles'])
  74. $aTmplVars['bx_if:profiles_more']['content']['popup'] = BxTemplFunctions::getInstance()->transBox('', $this->parseHtmlByName('profiles_more.html', $aTmplVarsPopup));
  75. return $this->parseHtmlByName('profiles.html', $aTmplVars);
  76. }
  77. public function getPopupSetRole($aRoles, $iAccountId, $iAccountRole)
  78. {
  79. $sJsObject = $this->_oConfig->getJsObject('manage_tools');
  80. $sHtmlIdPrefix = str_replace('_', '-', $this->_oConfig->getName()) . '-role';
  81. $sMaskOnClick = '%s.onClickSetOperatorRoleSubmit(this, %d, %d)';
  82. $aRoles = array_merge(array(array('id' => 0, 'title' => '_bx_accnt_txt_not_operator')), $aRoles);
  83. $aTmplVarsRoles = array();
  84. foreach($aRoles as $aRole) {
  85. $iRole = (int)$aRole['id'];
  86. $bRole = $iRole != 0;
  87. if($iRole == BX_DOL_STUDIO_ROLE_MASTER)
  88. continue;
  89. $aTmplVarsRoles[] = array(
  90. 'id' => $sHtmlIdPrefix . '-' . $iRole,
  91. 'type' => !$bRole ? 'radio' : 'checkbox',
  92. 'value' => $iRole,
  93. 'onclick' => sprintf($sMaskOnClick, $sJsObject, $iAccountId, $iRole),
  94. 'title' => _t($aRole['title']),
  95. 'bx_if:show_checked' => array(
  96. 'condition' => ($bRole && $iAccountRole & (1 << ($iRole - 1))) || (!$bRole && $iAccountRole == 0),
  97. 'content' => array()
  98. ),
  99. 'bx_if:show_divider' => array(
  100. 'condition' => !$bRole,
  101. 'content' => array()
  102. )
  103. );
  104. }
  105. return $this->parseHtmlByName('set_role_popup.html', array(
  106. 'bx_repeat:roles' => $aTmplVarsRoles
  107. ));
  108. }
  109. }
  110. /** @} */