BxDolCmtsGridAdministration.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 BxDolCmtsGridAdministration extends BxTemplGrid
  11. {
  12. protected $_aCmts;
  13. protected $_bShowModule;
  14. protected $_sManageType;
  15. protected $_sParamsDivider;
  16. protected $_sFilter1Name;
  17. protected $_sFilter1Value;
  18. protected $_aFilter1Values;
  19. public function __construct ($aOptions, $oTemplate = false)
  20. {
  21. $this->_aCmts = [];
  22. $this->_bShowModule = false;
  23. $this->_sFilter1Name = 'filter1';
  24. $this->_aFilter1Values = [];
  25. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  26. foreach($aModules as $aModule) {
  27. $oModule = BxDolModule::getInstance($aModule['name']);
  28. if(!$oModule || !isset($oModule->_oConfig->CNF['OBJECT_COMMENTS']))
  29. continue;
  30. $this->_aFilter1Values[$aModule['name']] = $aModule['title'];
  31. }
  32. $sFilter1 = bx_get($this->_sFilter1Name);
  33. if(!empty($sFilter1)) {
  34. $this->_sFilter1Value = bx_process_input($sFilter1);
  35. $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
  36. }
  37. if(!$oTemplate)
  38. $oTemplate = BxDolTemplate::getInstance();
  39. parent::__construct ($aOptions, $oTemplate);
  40. $this->_sManageType = BX_DOL_MANAGE_TOOLS_ADMINISTRATION;
  41. $this->_sParamsDivider = '#-#';
  42. $this->_sDefaultSortingOrder = 'DESC';
  43. }
  44. protected function _switcherChecked2State($isChecked)
  45. {
  46. return $isChecked ? 'active' : 'hidden';
  47. }
  48. protected function _switcherState2Checked($mixedState)
  49. {
  50. return 'active' == $mixedState ? true : false;
  51. }
  52. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  53. {
  54. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  55. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  56. if(empty($this->_sFilter1Value)) {
  57. $aCmtsQueries = [];
  58. $aCmtsSystems = BxDolCmts::getSystems();
  59. foreach($aCmtsSystems as $aCmtsSystem)
  60. if(($sQuery = $this->_getDataSqlByModule($aCmtsSystem['name'])) != '')
  61. $aCmtsQueries[] = $sQuery;
  62. if(empty($aCmtsQueries) || !is_array($aCmtsQueries))
  63. return '';
  64. $this->_aOptions['source'] = '(' . implode(') UNION (', $aCmtsQueries) . ')';
  65. $this->_bShowModule = true;
  66. }
  67. else
  68. $this->_aOptions['source'] = $this->_getDataSqlByModule($this->_sFilter1Value);
  69. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  70. }
  71. protected function _getDataSqlByModule($sModule)
  72. {
  73. $oModule = BxDolModule::getInstance($sModule);
  74. if(!$oModule)
  75. return '';
  76. $oCmts = BxDolCmts::getObjectInstance($oModule->_oConfig->CNF['OBJECT_COMMENTS'], 0, false);
  77. if(!$oCmts || !$oCmts->isEnabled())
  78. return '';
  79. $iCmtsSystemId = $oCmts->getSystemId();
  80. $this->_aCmts[$iCmtsSystemId] = $oCmts;
  81. return $oModule->_oDb->prepareAsString("SELECT
  82. `sys_cmts_ids`.`id`, `sys_cmts_ids`.`system_id` AS `cmt_system_id`, `to`.`Module` AS `cmt_module`, `sys_cmts_ids`.`cmt_id`, `cmts`.`cmt_author_id`, `cmts`.`cmt_object_id`, `cmts`.`cmt_text`, `cmts`.`cmt_time`, `sys_cmts_ids`.`reports`, `sys_cmts_ids`.`status_admin`, `sys_accounts`.`email`
  83. FROM `sys_cmts_ids`
  84. INNER JOIN `sys_objects_cmts` AS `to` ON `sys_cmts_ids`.`system_id`=`to`.`ID`
  85. INNER JOIN " . $oCmts->getCommentsTableName() . " AS `cmts` ON `cmts`.`cmt_id`=`sys_cmts_ids`.`cmt_id`
  86. LEFT JOIN `sys_profiles` ON `cmts`.`cmt_author_id`=`sys_profiles`.`id`
  87. LEFT JOIN `sys_accounts` ON `sys_profiles`.`account_id`=`sys_accounts`.`id`
  88. WHERE `sys_cmts_ids`.`system_id`=?", $iCmtsSystemId);
  89. }
  90. }
  91. /** @} */