BxBaseSearch.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  10. class BxBaseSearch extends BxDolSearch
  11. {
  12. protected $_oTemplate;
  13. protected $_sIdForm = 'sys_search_form';
  14. protected $_sIdResults = 'sys_search_results';
  15. protected $_sSuffixLiveSearch = '_quick';
  16. public function __construct($aChoice, $oTemplate)
  17. {
  18. if (!is_array($aChoice) && $aChoice != '')
  19. $aChoice = array($aChoice);
  20. parent::__construct($aChoice);
  21. $this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
  22. }
  23. public function getForm($iDesignBoxTemplate = BX_DB_PADDING_DEF, $sTitle = false)
  24. {
  25. if ($this->_sMetaType || $this->_sCategoryObject)
  26. return '';
  27. if (false === $sTitle)
  28. $sTitle = _t( "_Search");
  29. $aValues = array_merge(array('' => _t('_search_in_all_section')), $this->getKeyTitlesPairs());
  30. if (bx_get('type'))
  31. $aValue = bx_process_input(bx_get('type'));
  32. elseif (bx_get('section'))
  33. $aValue = bx_process_input(bx_get('section'));
  34. else
  35. $aValue = '';
  36. $sIdForm = $this->_sIdForm;
  37. $sIdResults = $this->_sIdResults;
  38. $sIdLoadingContainer = $sIdForm;
  39. $iKeywordMinLenth = 0;
  40. if($this->_bLiveSearch) {
  41. $sIdForm .= $this->_sSuffixLiveSearch;
  42. $sIdResults .= $this->_sSuffixLiveSearch;
  43. $sIdLoadingContainer = $sIdResults;
  44. $iKeywordMinLenth = (int)getParam('sys_search_keyword_min_len');
  45. }
  46. $sJsParams = "5, '#{$sIdForm}', '#{$sIdResults}', '#{$sIdLoadingContainer}', '{$this->_bLiveSearch}', {$iKeywordMinLenth}";
  47. $aForm = array(
  48. 'form_attrs' => array(
  49. 'id' => $sIdForm,
  50. 'action' => BX_DOL_URL_ROOT . 'searchKeyword.php',
  51. 'method' => 'post',
  52. ),
  53. 'params' => array(
  54. 'csrf' => array(
  55. 'disable' => true,
  56. ),
  57. ),
  58. 'inputs' => array(
  59. 'live_search' => array(
  60. 'type' => 'hidden',
  61. 'name' => 'live_search',
  62. 'value' => $this->_bLiveSearch ? 1 : 0,
  63. ),
  64. 'section' => array(
  65. 'type' => 'select',
  66. 'name' => 'section',
  67. 'caption' => _t('_Section'),
  68. 'values' => $aValues,
  69. 'value' => $aValue,
  70. ),
  71. 'keyword' => array(
  72. 'type' => 'text',
  73. 'name' => 'keyword',
  74. 'caption' => _t('_Keyword'),
  75. 'value' => bx_get('keyword') ? bx_process_input(bx_get('keyword')) : '',
  76. ),
  77. 'search' => array(
  78. 'type' => 'submit',
  79. 'name' => 'search',
  80. 'value' => _t('_Search'),
  81. )
  82. )
  83. );
  84. if ($this->_bLiveSearch) {
  85. unset($aForm['inputs']['section']);
  86. unset($aForm['inputs']['search']);
  87. unset($aForm['inputs']['keyword']['caption']);
  88. $aForm['inputs']['keyword']['attrs']['placeholder'] = _t('_sys_search_placeholder');
  89. $aForm['inputs']['keyword']['attrs']['onkeypress'] = "return bx_search_on_type(event, $sJsParams);";
  90. $aForm['inputs']['keyword']['attrs']['onpaste'] = $aForm['inputs']['keyword']['attrs']['onkeypress'];
  91. }
  92. $oForm = new BxTemplFormView($aForm);
  93. $sForm = $oForm->getCode();
  94. if (!$this->_bLiveSearch) {
  95. $o = new BxTemplPaginate(array());
  96. $o->addCssJs();
  97. }
  98. return '<div class="bx-page-block-container bx-def-padding-sec-topbottom bx-clearfix">' . DesignBoxContent($sTitle, $sForm, $iDesignBoxTemplate) . '</div>';
  99. }
  100. public function getResultsContainer($sCode = '')
  101. {
  102. $sIdResults = $this->_sIdResults . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
  103. return '<div id="' . $sIdResults . '">' . $sCode . '</div>';
  104. }
  105. protected function getKeyTitlesPairs ()
  106. {
  107. $a = array();
  108. foreach ($this->aClasses as $sKey => $r)
  109. if ($this->_sMetaType || $r['GlobalSearch'])
  110. $a[$sKey] = _t($r['title']);
  111. return $a;
  112. }
  113. }
  114. /** @} */