BxBaseModGroupsGridAdministration.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. if(($this->_bContentFilter = !empty($CNF['FIELD_CF'])) !== false) {
  35. $this->_sFilter2Name = 'filter2';
  36. $this->_aFilter2Values = BxDolFormQuery::getDataItems('sys_content_filter');
  37. if(($sFilter2 = bx_get($this->_sFilter2Name)) !== false) {
  38. $this->_sFilter2Value = bx_process_input($sFilter2);
  39. $this->_aQueryAppend[$this->_sFilter2Name] = $this->_sFilter2Value;
  40. }
  41. }
  42. }
  43. protected function _switcherChecked2State($isChecked)
  44. {
  45. return $isChecked ? BX_BASE_MOD_GENERAL_STATUS_ACTIVE : BX_BASE_MOD_GENERAL_STATUS_HIDDEN;
  46. }
  47. protected function _switcherState2Checked($mixedState)
  48. {
  49. return BX_BASE_MOD_GENERAL_STATUS_ACTIVE == $mixedState ? true : false;
  50. }
  51. protected function _enable ($mixedId, $isChecked)
  52. {
  53. $CNF = &$this->_oModule->_oConfig->CNF;
  54. $bStatusAdmin = $this->_sStatusField == $CNF['FIELD_STATUS_ADMIN'];
  55. $sStatusBefore = '';
  56. if($bStatusAdmin) {
  57. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
  58. if(!empty($aContentInfo) && is_array($aContentInfo))
  59. $sStatusBefore = $aContentInfo[$this->_sStatusField];
  60. }
  61. $mixedResult = parent::__enable($mixedId, $isChecked);
  62. if((int)$mixedResult > 0) {
  63. if($bStatusAdmin && $sStatusBefore == BX_BASE_MOD_GENERAL_STATUS_PENDING) {
  64. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
  65. if($aContentInfo[$this->_sStatusField] == BX_BASE_MOD_GENERAL_STATUS_ACTIVE)
  66. $this->_oModule->onApprove($aContentInfo);
  67. }
  68. }
  69. return $mixedResult;
  70. }
  71. protected function _getActionAuditContext($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  72. {
  73. if (!getParam('sys_audit_enable') || getParam('sys_audit_acl_levels') == '')
  74. return;
  75. $iProfileId = bx_get_logged_profile_id();
  76. if (!BxDolAcl::getInstance()->isMemberLevelInSet(explode(',', getParam('sys_audit_acl_levels')), $iProfileId))
  77. return;
  78. $CNF = &$this->_oModule->_oConfig->CNF;
  79. $oProfile = $this->_getProfileObject($aRow[$CNF['FIELD_ID']]);
  80. $sUrl = BX_DOL_URL_ROOT . 'page/audit-administration?context_id=' . $oProfile->id();
  81. $a['attr'] = array_merge($a['attr'], array(
  82. "onclick" => "window.open('" . $sUrl . "','_audit');"
  83. ));
  84. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  85. }
  86. protected function _getCellName($mixedValue, $sKey, $aField, $aRow)
  87. {
  88. $oProfile = $this->_getProfileObject($aRow['id']);
  89. return parent::_getCellDefault($oProfile->getUnit(0, array('template' => 'unit_wo_cover')), $sKey, $aField, $aRow);
  90. }
  91. protected function _getFilterControls()
  92. {
  93. parent::_getFilterControls();
  94. $sContent = $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values);
  95. if($this->_bContentFilter)
  96. $sContent .= $this->_getFilterSelectOne($this->_sFilter2Name, $this->_sFilter2Value, $this->_aFilter2Values);
  97. $sContent .= $this->_getSearchInput();
  98. return $sContent;
  99. }
  100. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  101. {
  102. $CNF = &$this->_oModule->_oConfig->CNF;
  103. if(strpos($sFilter, $this->_sParamsDivider) !== false) {
  104. $aFilters = explode($this->_sParamsDivider, $sFilter);
  105. if($this->_bContentFilter)
  106. list($this->_sFilter1Value, $this->_sFilter2Value, $sFilter) = $aFilters;
  107. else
  108. list($this->_sFilter1Value, $sFilter) = $aFilters;
  109. }
  110. if(!empty($this->_sFilter1Value))
  111. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $this->_sStatusField . "`=?", $this->_sFilter1Value);
  112. if(!empty($this->_sFilter2Value))
  113. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $CNF['FIELD_CF'] . "`=?", $this->_sFilter2Value);
  114. return parent::_getDataSqlInner($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  115. }
  116. }
  117. /** @} */