1
0

BxBaseModProfileGridAdministration.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModProfileGridAdministration extends BxBaseModGeneralGridAdministration
  12. {
  13. protected $_sFilter1Name;
  14. protected $_sFilter1Value;
  15. protected $_aFilter1Values;
  16. public function __construct ($aOptions, $oTemplate = false)
  17. {
  18. parent::__construct ($aOptions, $oTemplate);
  19. $CNF = &$this->_oModule->_oConfig->CNF;
  20. $this->_aQueryReset = array('order_field', 'order_dir', $this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']);
  21. $this->_sFilter1Name = 'filter1';
  22. $this->_aFilter1Values = array(
  23. 'active' => $CNF['T']['filter_item_active'],
  24. 'pending' => $CNF['T']['filter_item_pending'],
  25. 'suspended' => $CNF['T']['filter_item_suspended'],
  26. );
  27. $sFilter1 = bx_get($this->_sFilter1Name);
  28. if(!empty($sFilter1)) {
  29. $this->_sFilter1Value = bx_process_input($sFilter1);
  30. $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
  31. }
  32. }
  33. public function performActionSetAclLevel()
  34. {
  35. $oMenu = BxDolMenu::getObjectInstance('sys_set_acl_level');
  36. $aIds = bx_get('ids');
  37. if(!$aIds || !is_array($aIds) || !$oMenu) {
  38. echoJson(array());
  39. return;
  40. }
  41. $aIdsResult = array();
  42. foreach($aIds as $iId) {
  43. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
  44. if($this->_oModule->checkAllowedSetMembership($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  45. continue;
  46. $aIdsResult[] = $this->_getProfileId($iId);
  47. }
  48. if(empty($aIdsResult)) {
  49. echoJson(array());
  50. return;
  51. }
  52. if(count($aIdsResult) == 1)
  53. $aIdsResult = $aIdsResult[0];
  54. $sContent = $this->_oTemplate->parseHtmlByName('set_acl_popup.html', array(
  55. 'content' => $oMenu->getCode($aIdsResult)
  56. ));
  57. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oModule->_oConfig->getName() . 'set_acl_level_popup', $sContent);
  58. echoJson(array('popup' => $sContent));
  59. }
  60. public function performActionDeleteWithContent()
  61. {
  62. $this->performActionDelete(array('with_content' => true));
  63. }
  64. protected function _getActionSetAclLevel($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  65. {
  66. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedSetMembership($aRow) !== CHECK_ACTION_RESULT_ALLOWED)
  67. return '';
  68. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  69. }
  70. protected function _getActionAuditProfile($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  71. {
  72. if (!getParam('sys_audit_enable') || getParam('sys_audit_acl_levels') == '')
  73. return;
  74. $iProfileId = bx_get_logged_profile_id();
  75. if (!BxDolAcl::getInstance()->isMemberLevelInSet(explode(',', getParam('sys_audit_acl_levels')), $iProfileId))
  76. return;
  77. $CNF = &$this->_oModule->_oConfig->CNF;
  78. $oProfile = $this->_getProfileObject($aRow[$CNF['FIELD_ID']]);
  79. $sUrl = BX_DOL_URL_ROOT . 'studio/audit.php?actor_id=' . $oProfile->id();
  80. $a['attr'] = array_merge($a['attr'], array(
  81. "onclick" => "window.open('" . $sUrl . "','_audit');"
  82. ));
  83. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  84. }
  85. protected function _getActionDeleteWithContent($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  86. {
  87. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)
  88. return '';
  89. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  90. }
  91. protected function _switcherChecked2State($isChecked)
  92. {
  93. return $isChecked ? 'active' : 'suspended';
  94. }
  95. protected function _switcherState2Checked($mixedState)
  96. {
  97. return 'active' == $mixedState ? true : false;
  98. }
  99. protected function _enable ($mixedId, $isChecked)
  100. {
  101. $oProfile = $this->_getProfileObject($mixedId);
  102. if($oProfile instanceof BxDolProfileUndefined)
  103. return false;
  104. $iAction = BX_PROFILE_ACTION_MANUAL;
  105. $bSendEmailNotification = $this->_oModule->serviceActAsProfile();
  106. return $isChecked ? $oProfile->activate($iAction, 0, $bSendEmailNotification) : $oProfile->suspend($iAction, 0, $bSendEmailNotification);
  107. }
  108. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  109. {
  110. $iFilterPartsCount = substr_count($sFilter, $this->_sParamsDivider);
  111. switch ($iFilterPartsCount) {
  112. case 1:
  113. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  114. break;
  115. case 2:
  116. list($this->_sFilter1Value, $this->_sFilter2Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  117. break;
  118. }
  119. if(!empty($this->_sFilter1Value))
  120. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tp`.`status`=?", $this->_sFilter1Value);
  121. return $this->_getDataSqlInner($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  122. }
  123. protected function _getDataSqlInner($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  124. {
  125. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  126. }
  127. //--- Layout methods ---//
  128. protected function _getFilterControls()
  129. {
  130. parent::_getFilterControls();
  131. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  132. }
  133. protected function _getCellFullname($mixedValue, $sKey, $aField, $aRow)
  134. {
  135. $oProfile = $this->_getProfileObject($aRow['id']);
  136. return parent::_getCellDefault($oProfile->getUnit(), $sKey, $aField, $aRow);
  137. }
  138. protected function _getCellLastOnline($mixedValue, $sKey, $aField, $aRow)
  139. {
  140. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  141. }
  142. protected function _getCellAddedTs($mixedValue, $sKey, $aField, $aRow)
  143. {
  144. return $this->_getCellLastOnline($mixedValue, $sKey, $aField, $aRow);
  145. }
  146. protected function _getCellAccount($mixedValue, $sKey, $aField, $aRow)
  147. {
  148. $sManageAccountUrl = $this->_getManageAccountUrl($aRow[$sKey]);
  149. if(!empty($sManageAccountUrl)) {
  150. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  151. 'href' => $sManageAccountUrl,
  152. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  153. 'content' => $mixedValue,
  154. ));
  155. }
  156. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  157. }
  158. protected function _getProfileObject($iId)
  159. {
  160. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iId, $this->_oModule->_oConfig->getName());
  161. if (!$oProfile)
  162. $oProfile = BxDolProfileUndefined::getInstance();
  163. return $oProfile;
  164. }
  165. protected function _getProfileId($iId)
  166. {
  167. return $this->_getProfileObject($iId)->id();
  168. }
  169. protected function _doDelete($iId, $aParams = array())
  170. {
  171. if($this->_oModule->checkMyself($iId))
  172. return false;
  173. if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
  174. $oProfile = $this->_getProfileObject($iId);
  175. if($oProfile instanceof BxDolProfileUndefined)
  176. return false;
  177. return $oProfile->delete($oProfile->id(), true);
  178. }
  179. return parent::_doDelete($iId, $aParams);
  180. }
  181. }
  182. /** @} */