BxDolAuditGrid.php 4.8 KB

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