BxBaseModGeneralGrid.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. * @{
  9. */
  10. class BxBaseModGeneralGrid extends BxTemplGrid
  11. {
  12. protected $MODULE;
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_sTableAlias;
  16. protected $_sParamsDivider;
  17. protected $_sJsObject;
  18. public function __construct ($aOptions, $oTemplate = false)
  19. {
  20. $this->MODULE = $this->MODULE ?: $this->_sModule;
  21. $this->_sModule = $this->_sModule ?: $this->MODULE;
  22. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  23. parent::__construct ($aOptions, $oTemplate ?: $this->_oModule->_oTemplate);
  24. $this->_sTableAlias = '';
  25. $this->_sParamsDivider = '#-#';
  26. }
  27. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, $mixedAddSelectOne = true, $bAsArray = false)
  28. {
  29. $CNF = &$this->_oModule->_oConfig->CNF;
  30. if($mixedAddSelectOne === true && ($sKey = $CNF['T']['filter_item_select_one_' . $sFilterName] ?? ''))
  31. $mixedAddSelectOne = $sKey;
  32. return parent::_getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, $mixedAddSelectOne, $bAsArray);
  33. }
  34. protected function _initFilter($iNumber, $aValues = [])
  35. {
  36. $sFfName = '_sFilter' . $iNumber . 'Name';
  37. $sFfValue = '_sFilter' . $iNumber . 'Value';
  38. if(!property_exists($this, $sFfName) || !property_exists($this, $sFfValue))
  39. return;
  40. $this->$sFfName = 'filter' . $iNumber;
  41. if(($sFfValues = '_aFilter' . $iNumber . 'Values') && property_exists($this, $sFfValues))
  42. $this->$sFfValues = $aValues ?: [];
  43. if(($sValue = bx_get($this->$sFfName)) !== false) {
  44. $this->$sFfValue = bx_process_input($sValue);
  45. $this->_aQueryAppend[$this->$sFfName] = $this->$sFfValue;
  46. }
  47. }
  48. protected function _setFilterValue($iNumber, $mixedValue)
  49. {
  50. $sFfName = '_sFilter' . $iNumber . 'Name';
  51. $sFfValue = '_sFilter' . $iNumber . 'Value';
  52. $this->$sFfValue = bx_process_input($mixedValue);
  53. $this->_aQueryAppend[$this->$sFfName] = $this->$sFfValue;
  54. }
  55. protected function _parseFilterValue(&$sFilter)
  56. {
  57. $iFilterParts = substr_count($sFilter, $this->_sParamsDivider);
  58. if(!$iFilterParts)
  59. return;
  60. $aFilterParts = explode($this->_sParamsDivider, $sFilter);
  61. for($i = 1; $i <= $iFilterParts; $i++)
  62. if(($sField = '_sFilter' . $i . 'Value') && property_exists($this, $sField))
  63. $this->$sField = $aFilterParts[$i - 1];
  64. $sFilter = $aFilterParts[$iFilterParts];
  65. }
  66. protected function _getSqlField($sField)
  67. {
  68. return ($this->_sTableAlias ? '`' . $this->_sTableAlias . '`.' : '') . '`' . $sField . '`';
  69. }
  70. }
  71. /** @} */