XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
SearchResultsForm.class.php
1<?php
10
11if (!defined('XOOPS_ROOT_PATH')) {
12 exit();
13}
14
15require_once XOOPS_ROOT_PATH . '/core/XCube_ActionForm.class.php';
16require_once XOOPS_MODULE_PATH . '/legacy/class/Legacy_Validator.class.php';
17
19{
20 public $mQueries = [];
21 public $_mKeywordMin = 0;
22
23 public function __construct($keywordMin)
24 {
25 parent::__construct();
26 $this->_mKeywordMin = (int)$keywordMin;
27 }
28
29 public function prepare()
30 {
31 //
32 // Set form properties
33 //
34 $this->mFormProperties['mids'] =new XCube_IntArrayProperty('mids');
35 $this->mFormProperties['andor'] =new XCube_StringProperty('andor');
36 $this->mFormProperties['query'] =new XCube_StringProperty('query');
37
38 //
39 // Set field properties
40 //
41 $this->mFieldProperties['andor'] =new XCube_FieldProperty($this);
42 $this->mFieldProperties['andor']->setDependsByArray(['mask']);
43 $this->mFieldProperties['andor']->addMessage('mask', _MD_LEGACY_ERROR_MASK, _MD_LEGACY_LANG_ANDOR);
44 $this->mFieldProperties['andor']->addVar('mask', '/^(AND|OR|exact)$/i');
45 }
46
47 public function fetch()
48 {
49 parent::fetch();
50
51 $t_queries = [];
52
54 if ('exact' == $this->get('andor') && strlen($this->get('query')) >= $this->_mKeywordMin) {
55 $this->mQueries[] = $myts->addSlashes($this->get('query'));
56 } else {
57 $query = $this->get('query');
58 if (defined('XOOPS_USE_MULTIBYTES')) {
59 $query = xoops_trim($query);
60 }
61
62 $separator = '/[\s,]+/';
63 if (defined('_MD_LEGACY_FORMAT_SEARCH_SEPARATOR')) {
64 $separator = _MD_LEGACY_FORMAT_SEARCH_SEPARATOR;
65 }
66
67 $tmpArr = preg_split($separator, $query);
68 foreach ($tmpArr as $tmp) {
69 if (strlen($tmp) >= $this->_mKeywordMin) {
70 $this->mQueries[] = $myts->addSlashes($tmp);
71 }
72 }
73 }
74
75 $this->set('query', implode(' ', $this->mQueries));
76 }
77
78 public function fetchAndor()
79 {
80 if ('' == $this->get('andor')) {
81 $this->set('andor', 'AND');
82 }
83 }
84
85 public function validate()
86 {
87 parent::validate();
88
89 if (!count($this->mQueries)) {
90 $this->addErrorMessage(_MD_LEGACY_ERROR_SEARCH_QUERY_REQUIRED);
91 }
92 }
93
94 public function update(&$params)
95 {
96 $mids = $this->get('mids');
97 if ((is_countable($mids) ? count($mids) : 0) > 0) {
98 $params['mids'] = $mids;
99 }
100
101 $params['queries'] = $this->mQueries;
102 $params['andor'] = $this->get('andor');
103 $params['maxhit'] = LEGACY_SEARCH_RESULT_MAXHIT;
104 }
105}
validate()
Validates fetched values.
update(&$params)
[Abstract] Updates an object with properties values.
prepare()
[Abstract] Set up form properties and field properties.
fetch()
Fetches values through the request object.
addErrorMessage( $message)
Adds a message to the form's error message buffer.
[Abstract] Used for validating member property values of XCube_ActionForm.
Represents int[] property. XCube_GenericArrayProperty<XCube_IntProperty>.
Represents string property.