BxBasePrivacyFormGroupCustom.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxBasePrivacyFormGroupCustom extends BxTemplFormView
  10. {
  11. protected $_iProfileId;
  12. protected $_iContentId;
  13. protected $_sObject;
  14. protected $_oObject;
  15. protected $_iGroupId;
  16. protected $_aGroupSettings;
  17. protected $_iGroupCustomId;
  18. protected $_aGroupCustomInfo;
  19. public function __construct($aInfo, $oTemplate)
  20. {
  21. parent::__construct($aInfo, $oTemplate);
  22. $this->_iProfileId = bx_get_logged_profile_id();
  23. $this->_iContentId = 0;
  24. $this->_sObject = '';
  25. $this->_oObject = null;
  26. $this->_iGroupId = 0;
  27. $this->_aGroupSettings = array();
  28. $this->_iGroupCustomId = 0;
  29. $this->_aGroupCustomInfo = array();
  30. switch($this->aParams['display']) {
  31. case 'sys_privacy_group_custom_manage':
  32. $this->aInputs['action']['value'] = 'select_group';
  33. break;
  34. }
  35. }
  36. public function initChecker($aValues = array(), $aSpecificValues = array())
  37. {
  38. $this->initData($aValues);
  39. return parent::initChecker($aValues, $aSpecificValues);
  40. }
  41. public function getGroupId()
  42. {
  43. return $this->_iGroupId;
  44. }
  45. public function getGroupCustomId()
  46. {
  47. return $this->_iGroupCustomId;
  48. }
  49. public function getElementGroupCustom($aParams = array())
  50. {
  51. $this->initData($aParams);
  52. $sName = 'sys-pgc-' . str_replace('_', '-', $this->_sObject);
  53. $iValue = !empty($aParams['value']) ? (int)$aParams['value'] : $this->_iGroupCustomId;
  54. $aValueMembers = array();
  55. if(!empty($aParams['value_members']) && is_array($aParams['value_members']))
  56. $aValueMembers = $aParams['value_members'];
  57. else if($this->_iGroupCustomId)
  58. $aValueMembers = $this->_aGroupCustomInfo['members'];
  59. $aInput = array(
  60. 'type' => 'hidden',
  61. 'name' => $sName . '-id',
  62. 'caption' => '',
  63. 'value' => $iValue,
  64. 'db' => array(
  65. 'pass' => 'Int'
  66. )
  67. );
  68. $aInputMembers = array(
  69. 'type' => 'custom',
  70. 'name' => $sName . '-members',
  71. 'caption' => '',
  72. 'value' => $aValueMembers,
  73. 'ajax_get_suggestions' => BX_DOL_URL_ROOT . bx_append_url_params('privacy.php', array(
  74. 'object' => $this->_sObject,
  75. 'action' => 'users_list',
  76. 'group' => $this->_iGroupId
  77. )),
  78. 'attrs' => array(
  79. 'disabled' => 'disabled'
  80. )
  81. );
  82. return $this->oTemplate->parseHtmlByName('privacy_group_custom.html', array(
  83. 'js_object' => $this->_oObject->getJsObjectName(),
  84. 'html_id' => $sName,
  85. 'input_id' => $this->genInputStandard($aInput),
  86. 'input_members' => $this->genCustomInputUsernamesSuggestions($aInputMembers)
  87. ));
  88. }
  89. protected function genCustomInputSearch($aInput)
  90. {
  91. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . bx_append_url_params('privacy.php', array(
  92. 'object' => $this->_sObject,
  93. 'action' => 'users_list',
  94. 'group' => $this->_iGroupId
  95. ));
  96. return $this->genCustomInputUsernamesSuggestions($aInput);
  97. }
  98. protected function genCustomInputList($aInput)
  99. {
  100. $iProfileId = bx_get_logged_profile_id();
  101. $oConnection = BxDolConnection::getObjectInstance($this->_aGroupSettings['connection']);
  102. if(!$oConnection)
  103. return '';
  104. $aConnectedIds = $oConnection->getConnectedContent($iProfileId, true);
  105. $aSelected = array();
  106. if(!empty($this->_aGroupCustomInfo) && is_array($this->_aGroupCustomInfo))
  107. $aSelected = $this->_aGroupCustomInfo['members'];
  108. $aTmplVarsUsers = array();
  109. if(!empty($aConnectedIds) && is_array($aConnectedIds)) {
  110. $aCheckbox = $aInput;
  111. $aCheckbox['type'] = 'checkbox';
  112. $aCheckbox['name'] .= '[]';
  113. foreach($aConnectedIds as $iConnectedId) {
  114. $oProfile = BxDolProfile::getInstanceMagic($iConnectedId);
  115. if(!$oProfile)
  116. continue;
  117. $aCheckbox['value'] = $iConnectedId;
  118. $aCheckbox['checked'] = in_array($iConnectedId, $aSelected) ? 1 : 0;
  119. $aTmplVarsUsers[] = array(
  120. 'checkbox' => $this->genInput($aCheckbox),
  121. 'unit' => $oProfile->getUnit()
  122. );
  123. }
  124. }
  125. if(empty($aTmplVarsUsers))
  126. $aTmplVarsUsers = MsgBox(_t('_Empty'));
  127. return $this->oTemplate->parseHtmlByName('privacy_users_select_list.html', array(
  128. 'bx_repeat:users' => $aTmplVarsUsers
  129. ));
  130. }
  131. protected function initData($aData)
  132. {
  133. if(!empty($aData['profile_id']))
  134. $this->_iProfileId = (int)$aData['profile_id'];
  135. if(!empty($aData['content_id']))
  136. $this->_iContentId = (int)$aData['content_id'];
  137. if(!empty($aData['object'])) {
  138. $this->_sObject = $aData['object'];
  139. $this->_oObject = BxDolPrivacy::getObjectInstance($this->_sObject);
  140. }
  141. if(!empty($aData['group_id'])) {
  142. $this->_iGroupId = (int)$aData['group_id'];
  143. $this->_aGroupSettings = $this->_oObject ? $this->_oObject->getGroupSettings($this->_iGroupId) : array();
  144. }
  145. if(!empty($this->_iProfileId) && !empty($this->_sObject) && !empty($this->_iGroupId)) {
  146. $this->_aGroupCustomInfo = $this->_oObject->getGroupCustom(array(
  147. 'type' => 'pcog_ext',
  148. 'profile_id' => $this->_iProfileId,
  149. 'content_id' => $this->_iContentId,
  150. 'object' => $this->_sObject,
  151. 'group_id' => $this->_iGroupId
  152. ));
  153. if(!empty($this->_aGroupCustomInfo) && is_array($this->_aGroupCustomInfo))
  154. $this->_iGroupCustomId = (int)$this->_aGroupCustomInfo['id'];
  155. }
  156. }
  157. }
  158. /** @} */