1
0

BxBaseModGroupsGridAdministration.php 5.7 KB

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