BxDolAuditGrid.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. define('BX_DOL_MANAGE_TOOLS_ADMINISTRATION', 'administration');
  10. class BxDolAuditGrid extends BxTemplGrid
  11. {
  12. protected $_sParamsDivider;
  13. protected $_sFilter1Name;
  14. protected $_sFilter1Value;
  15. protected $_aFilter1Values;
  16. protected $_sFilterProfileName;
  17. protected $_sFilterProfileValue;
  18. protected $_aFilterProfileValues;
  19. protected $_sFilterActionName;
  20. protected $_sFilterActionValue;
  21. protected $_aFilterActionValues;
  22. protected $_sFilterFromDateName;
  23. protected $_sFilterFromDateValue;
  24. protected $_sFilterToDateName;
  25. protected $_sFilterToDateValue;
  26. public function __construct ($aOptions, $oTemplate = false)
  27. {
  28. $this->_sFilter1Name = 'module';
  29. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules'));
  30. $this->_aFilter1Values[''] = _t('_adm_txt_select_module');
  31. foreach($aModules as $aModule){
  32. $this->_aFilter1Values[$aModule['name']] = $aModule['title'];
  33. }
  34. $sFilter1 = bx_get($this->_sFilter1Name);
  35. if(!empty($sFilter1)) {
  36. $this->_sFilter1Value = bx_process_input($sFilter1);
  37. $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
  38. }
  39. $this->_sFilterProfileName = 'profile';
  40. $aProfiles = BxDolAuditQuery::getInstance()->getData(array('type' => 'profile_list'));
  41. $this->_aFilterProfileValues[''] = _t('_sys_audit_filter_profile_select');
  42. foreach($aProfiles as $iProfile){
  43. $oProfile = BxDolProfile::getInstance($iProfile);
  44. if ($oProfile)
  45. $this->_aFilterProfileValues[$iProfile] = $oProfile->getDisplayName();
  46. }
  47. $sFilterProfile = bx_get($this->_sFilterProfileName);
  48. if(!empty($sFilterProfile)) {
  49. $this->_sFilterProfileValue = bx_process_input($sFilterProfile);
  50. $this->_aQueryAppend[$this->_sFilterProfileName] = $this->_sFilterProfileValue;
  51. }
  52. $this->_sFilterActionName = 'action';
  53. $aActions = BxDolAuditQuery::getInstance()->getData(array('type' => 'action_list'));
  54. $this->_aFilterActionValues[''] = _t('_sys_audit_filter_action_select');
  55. foreach($aActions as $sAction){
  56. $this->_aFilterActionValues[$sAction] = _t($sAction);
  57. }
  58. $sFilterAction = bx_get($this->_sFilterActionName);
  59. if(!empty($sFilterAction)) {
  60. $this->_sFilterActionValue = bx_process_input($sFilterAction);
  61. $this->_aQueryAppend[$this->_sFilterActionName] = $this->_sFilterActionValue;
  62. }
  63. $this->_sFilterFromDateName = 'from_date';
  64. $this->_sFilterToDateName = 'to_date';
  65. parent::__construct ($aOptions, $oTemplate);
  66. $this->_sParamsDivider = '#-#';
  67. $this->_sDefaultSortingOrder = 'DESC';
  68. $this->oDb = new BxDolStudioFormsQuery();
  69. }
  70. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  71. {
  72. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  73. list($this->_sFilter1Value, $this->_sFilterProfileValue, $this->_sFilterActionValue, $this->_sFilterFromDateValue, $this->_sFilterToDateValue, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  74. if($this->_sFilter1Value != '')
  75. $this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `content_module` = ?", $this->_sFilter1Value);
  76. if($this->_sFilterProfileValue != '')
  77. $this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `profile_id` = ?", $this->_sFilterProfileValue);
  78. if($this->_sFilterActionValue != '')
  79. $this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `action_lang_key` = ?", $this->_sFilterActionValue);
  80. if($this->_sFilterFromDateValue != '')
  81. $this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `added` > ?", strtotime($this->_sFilterFromDateValue));
  82. if($this->_sFilterToDateValue != '')
  83. $this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `added` <= ?", strtotime($this->_sFilterToDateValue));
  84. if(bx_get('content_id') && is_numeric(bx_get('content_id')))
  85. $this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `content_id` = ?", (int)bx_get('content_id'));
  86. if(bx_get('context_id') && is_numeric(bx_get('context_id')))
  87. $this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `context_profile_id` = ?", (int)bx_get('context_id'));
  88. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  89. }
  90. }
  91. /** @} */