BxBaseModGroupsGridAdministration.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGroupsGridAdministration extends BxBaseModProfileGridAdministration
  12. {
  13. protected $_bContentFilter;
  14. public function __construct ($aOptions, $oTemplate = false)
  15. {
  16. parent::__construct ($aOptions, $oTemplate);
  17. }
  18. protected function _init()
  19. {
  20. $CNF = &$this->_oModule->_oConfig->CNF;
  21. //--- Status
  22. $this->_sStatusField = $CNF['FIELD_STATUS_ADMIN'];
  23. $this->_aStatusValues = [
  24. BX_BASE_MOD_GENERAL_STATUS_ACTIVE,
  25. BX_BASE_MOD_GENERAL_STATUS_HIDDEN,
  26. BX_BASE_MOD_GENERAL_STATUS_PENDING
  27. ];
  28. //--- Filter 1
  29. $this->_sFilter1Name = 'filter1';
  30. $this->_aFilter1Values = [
  31. BX_BASE_MOD_GENERAL_STATUS_ACTIVE => $CNF['T']['filter_item_active'],
  32. BX_BASE_MOD_GENERAL_STATUS_HIDDEN => $CNF['T']['filter_item_hidden'],
  33. ];
  34. if($this->_oModule->_oConfig->isAutoApprove())
  35. $this->_aFilter1Values[BX_BASE_MOD_GENERAL_STATUS_PENDING] = $CNF['T']['filter_item_pending'];
  36. if(($sFilter1 = bx_get($this->_sFilter1Name)) !== false) {
  37. $this->_sFilter1Value = bx_process_input($sFilter1);
  38. $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
  39. }
  40. //--- Filter 2
  41. $oCf = BxDolContentFilter::getInstance();
  42. if(($this->_bContentFilter = ($oCf->isEnabled() && !empty($CNF['FIELD_CF']))) !== false) {
  43. $this->_sFilter2Name = 'filter2';
  44. $this->_aFilter2Values = $oCf->getValues();
  45. if(($sFilter2 = bx_get($this->_sFilter2Name)) !== false) {
  46. $this->_sFilter2Value = bx_process_input($sFilter2);
  47. $this->_aQueryAppend[$this->_sFilter2Name] = $this->_sFilter2Value;
  48. }
  49. }
  50. }
  51. protected function _switcherChecked2State($isChecked)
  52. {
  53. return $isChecked ? BX_BASE_MOD_GENERAL_STATUS_ACTIVE : BX_BASE_MOD_GENERAL_STATUS_HIDDEN;
  54. }
  55. protected function _switcherState2Checked($mixedState)
  56. {
  57. return BX_BASE_MOD_GENERAL_STATUS_ACTIVE == $mixedState ? true : false;
  58. }
  59. protected function _enable ($mixedId, $isChecked)
  60. {
  61. $CNF = &$this->_oModule->_oConfig->CNF;
  62. $bStatusAdmin = $this->_sStatusField == $CNF['FIELD_STATUS_ADMIN'];
  63. $sStatusBefore = '';
  64. if($bStatusAdmin) {
  65. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
  66. if(!empty($aContentInfo) && is_array($aContentInfo))
  67. $sStatusBefore = $aContentInfo[$this->_sStatusField];
  68. }
  69. $mixedResult = parent::__enable($mixedId, $isChecked);
  70. if((int)$mixedResult > 0) {
  71. if($bStatusAdmin && $sStatusBefore == BX_BASE_MOD_GENERAL_STATUS_PENDING) {
  72. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
  73. if($aContentInfo[$this->_sStatusField] == BX_BASE_MOD_GENERAL_STATUS_ACTIVE)
  74. $this->_oModule->onApprove($aContentInfo);
  75. }
  76. }
  77. return $mixedResult;
  78. }
  79. protected function _getActionAuditContext($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  80. {
  81. if (!getParam('sys_audit_enable') || getParam('sys_audit_acl_levels') == '')
  82. return;
  83. $iProfileId = bx_get_logged_profile_id();
  84. if (!BxDolAcl::getInstance()->isMemberLevelInSet(explode(',', getParam('sys_audit_acl_levels')), $iProfileId))
  85. return;
  86. $CNF = &$this->_oModule->_oConfig->CNF;
  87. $oProfile = $this->_getProfileObject($aRow[$CNF['FIELD_ID']]);
  88. $sUrl = BX_DOL_URL_ROOT . 'page/audit-administration?context_id=' . $oProfile->id();
  89. $a['attr'] = array_merge($a['attr'], array(
  90. "onclick" => "window.open('" . $sUrl . "','_audit');"
  91. ));
  92. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  93. }
  94. protected function _getCellName($mixedValue, $sKey, $aField, $aRow)
  95. {
  96. $oProfile = $this->_getProfileObject($aRow['id']);
  97. if($this->_bIsApi)
  98. return ['type' => 'profile', 'data' => BxDolProfile::getData($oProfile->id())];
  99. return parent::_getCellDefault($oProfile->getUnit(0, [
  100. 'template' => 'unit_wo_cover',
  101. 'link_target' => '_blank'
  102. ]), $sKey, $aField, $aRow);
  103. }
  104. protected function _getFilterControls()
  105. {
  106. parent::_getFilterControls();
  107. $sContent = $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values);
  108. if($this->_bContentFilter)
  109. $sContent .= $this->_getFilterSelectOne($this->_sFilter2Name, $this->_sFilter2Value, $this->_aFilter2Values);
  110. $sContent .= $this->_getSearchInput();
  111. return $sContent;
  112. }
  113. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  114. {
  115. $CNF = &$this->_oModule->_oConfig->CNF;
  116. $aFilterParts = explode($this->_sParamsDivider, $sFilter);
  117. switch (substr_count($sFilter, $this->_sParamsDivider)) {
  118. case 1:
  119. list($this->_sFilter1Value, $sFilter) = $aFilterParts;
  120. break;
  121. case 2:
  122. list($this->_sFilter1Value, $this->_sFilter2Value, $sFilter) = $aFilterParts;
  123. break;
  124. }
  125. if(!empty($this->_sFilter1Value))
  126. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `td`.`" . $this->_sStatusField . "`=?", $this->_sFilter1Value);
  127. if($this->_bContentFilter && !empty($this->_sFilter2Value))
  128. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `td`.`" . $CNF['FIELD_CF'] . "`=?", $this->_sFilter2Value);
  129. return parent::_getDataSqlInner($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  130. }
  131. }
  132. /** @} */