5 use wcf\acp\form\UserOptionListForm
;
6 use wcf\data\search\SearchEditor
;
7 use wcf\system\database\util\PreparedStatementConditionBuilder
;
8 use wcf\system\exception\UserInputException
;
9 use wcf\system\option\user\UserOptionHandler
;
10 use wcf\system\page\PageLocationManager
;
11 use wcf\system\request\LinkHandler
;
13 use wcf\util\HeaderUtil
;
14 use wcf\util\StringUtil
;
17 * Shows the user search form.
20 * @copyright 2001-2019 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
23 * @property UserOptionHandler $optionHandler
25 class UserSearchForm
extends UserOptionListForm
30 public $neededModules = ['MODULE_MEMBERS_LIST'];
36 public $username = '';
45 * condition builder object
46 * @var PreparedStatementConditionBuilder
60 public $maxResults = 1000;
66 public $optionTree = [];
71 public function readFormParameters()
73 parent
::readFormParameters();
75 if (isset($_POST['username'])) {
76 $this->username
= StringUtil
::trim($_POST['username']);
83 protected function initOptionHandler()
85 /** @noinspection PhpUndefinedMethodInspection */
86 $this->optionHandler
->enableSearchMode();
87 $this->optionHandler
->init();
93 public function readData()
97 $this->readOptionTree();
100 if (MODULE_MEMBERS_LIST
) {
101 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.MembersList');
106 * Reads option tree on page init.
108 protected function readOptionTree()
110 $this->optionTree
= $this->optionHandler
->getOptionTree();
116 public function assignVariables()
118 parent
::assignVariables();
120 WCF
::getTPL()->assign([
121 'username' => $this->username
,
122 'optionTree' => $this->optionTree
,
129 public function save()
133 // store search result in database
134 $search = SearchEditor
::create([
135 'userID' => WCF
::getUser()->userID ?
: null,
136 'searchData' => \
serialize(['matches' => $this->matches
]),
137 'searchTime' => TIME_NOW
,
138 'searchType' => 'users',
142 $this->searchID
= $search->searchID
;
145 // forward to result page
146 $url = LinkHandler
::getInstance()->getLink('MembersList', ['id' => $this->searchID
]);
147 HeaderUtil
::redirect($url);
155 public function validate()
157 AbstractForm
::validate();
162 if (empty($this->matches
)) {
163 throw new UserInputException('search', 'noMatches');
168 * Search for users which fit to the search values.
170 protected function search()
174 // build search condition
175 $this->conditions
= new PreparedStatementConditionBuilder();
178 $this->buildStaticConditions();
181 $this->buildDynamicConditions();
183 // if no conditions exists, no need to send query
184 if (!$this->conditions
->__toString()) {
189 $sql = "SELECT user_table.userID
190 FROM wcf" . WCF_N
. "_user user_table
191 LEFT JOIN wcf" . WCF_N
. "_user_option_value option_value
192 ON option_value.userID = user_table.userID
193 {$this->conditions}";
194 $statement = WCF
::getDB()->prepareStatement($sql, $this->maxResults
);
195 $statement->execute($this->conditions
->getParameters());
196 $this->matches
= $statement->fetchAll(\PDO
::FETCH_COLUMN
);
200 * Builds the static conditions.
202 protected function buildStaticConditions()
204 if (!empty($this->username
)) {
205 $this->conditions
->add("user_table.username LIKE ?", ['%' . \addcslashes
($this->username
, '_%') . '%']);
210 * Builds the dynamic conditions.
212 protected function buildDynamicConditions()
214 foreach ($this->optionHandler
->getCategoryOptions('profile') as $option) {
215 $option = $option['object'];
217 $value = $this->optionHandler
->optionValues
[$option->optionName
] ??
null;
218 /** @noinspection PhpUndefinedMethodInspection */
219 $this->optionHandler
->getTypeObject($option->optionType
)->getCondition($this->conditions
, $option, $value);