3 use wcf\acp\form\UserOptionListForm
;
4 use wcf\data\search\SearchEditor
;
5 use wcf\system\breadcrumb\Breadcrumb
;
6 use wcf\system\dashboard\DashboardHandler
;
7 use wcf\system\database\util\PreparedStatementConditionBuilder
;
8 use wcf\system\exception\UserInputException
;
9 use wcf\system\request\LinkHandler
;
10 use wcf\system\user\collapsible\content\UserCollapsibleContentHandler
;
12 use wcf\util\HeaderUtil
;
13 use wcf\util\StringUtil
;
16 * Shows the user search form.
19 * @copyright 2001-2014 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package com.woltlab.wcf
23 * @category Community Framework
25 class UserSearchForm
extends UserOptionListForm
{
27 * @see \wcf\page\AbstractPage::$activeMenuItem
29 public $activeMenuItem = 'wcf.user.search';
32 * @see \wcf\page\AbstractPage::$neededModules
34 public $neededModules = array('MODULE_MEMBERS_LIST');
40 public $username = '';
46 public $matches = array();
49 * condtion builder object
50 * @var \wcf\system\database\condition\PreparedStatementConditionBuilder
52 public $conditions = null;
64 public $maxResults = 1000;
67 * @see \wcf\form\IForm::readFormParameters()
69 public function readFormParameters() {
70 parent
::readFormParameters();
72 if (isset($_POST['username'])) $this->username
= StringUtil
::trim($_POST['username']);
76 * @see \wcf\acp\form\AbstractOptionListForm::initOptionHandler()
78 protected function initOptionHandler() {
79 $this->optionHandler
->enableSearchMode();
80 $this->optionHandler
->init();
84 * @see \wcf\page\IPage::readData()
86 public function readData() {
89 $this->readOptionTree();
92 WCF
::getBreadcrumbs()->add(new Breadcrumb(WCF
::getLanguage()->get('wcf.user.members'), LinkHandler
::getInstance()->getLink('MembersList')));
96 * Reads option tree on page init.
98 protected function readOptionTree() {
99 $this->optionTree
= $this->optionHandler
->getOptionTree();
103 * @see \wcf\page\IPage::assignVariables()
105 public function assignVariables() {
106 parent
::assignVariables();
108 DashboardHandler
::getInstance()->loadBoxes('com.woltlab.wcf.user.MembersListPage', $this);
110 WCF
::getTPL()->assign(array(
111 'username' => $this->username
,
112 'optionTree' => $this->optionTree
,
113 'sidebarCollapsed' => UserCollapsibleContentHandler
::getInstance()->isCollapsed('com.woltlab.wcf.collapsibleSidebar', 'com.woltlab.wcf.user.MembersListPage'),
114 'sidebarName' => 'com.woltlab.wcf.user.MembersListPage'
119 * @see \wcf\form\IForm::save()
121 public function save() {
124 // store search result in database
125 $search = SearchEditor
::create(array(
126 'userID' => WCF
::getUser()->userID ?
: null,
127 'searchData' => serialize(array('matches' => $this->matches
)),
128 'searchTime' => TIME_NOW
,
129 'searchType' => 'users'
133 $this->searchID
= $search->searchID
;
136 // forward to result page
137 $url = LinkHandler
::getInstance()->getLink('MembersList', array('id' => $this->searchID
));
138 HeaderUtil
::redirect($url);
143 * @see \wcf\form\IForm::validate()
145 public function validate() {
146 AbstractForm
::validate();
151 if (empty($this->matches
)) {
152 throw new UserInputException('search', 'noMatches');
157 * Search for users which fit to the search values.
159 protected function search() {
160 $this->matches
= array();
161 $sql = "SELECT user_table.userID
162 FROM wcf".WCF_N
."_user user_table
163 LEFT JOIN wcf".WCF_N
."_user_option_value option_value
164 ON (option_value.userID = user_table.userID)";
166 // build search condition
167 $this->conditions
= new PreparedStatementConditionBuilder();
170 $this->buildStaticConditions();
173 $this->buildDynamicConditions();
175 // if no conditions exists, no need to send query
176 if (!count($this->conditions
->getParameters())) {
181 $statement = WCF
::getDB()->prepareStatement($sql.$this->conditions
, $this->maxResults
);
182 $statement->execute($this->conditions
->getParameters());
183 while ($row = $statement->fetchArray()) {
184 $this->matches
[] = $row['userID'];
189 * Builds the static conditions.
191 protected function buildStaticConditions() {
192 if (!empty($this->username
)) {
193 $this->conditions
->add("user_table.username LIKE ?", array('%'.addcslashes($this->username
, '_%').'%'));
198 * Builds the dynamic conditions.
200 protected function buildDynamicConditions() {
201 foreach ($this->optionHandler
->getCategoryOptions('profile') as $option) {
202 $option = $option['object'];
204 $value = isset($this->optionHandler
->optionValues
[$option->optionName
]) ?
$this->optionHandler
->optionValues
[$option->optionName
] : null;
205 $this->optionHandler
->getTypeObject($option->optionType
)->getCondition($this->conditions
, $option, $value);