@@ -16,65 +16,65 @@ |
||
16 | 16 | |
17 | 17 | class PageExpandedRequestList extends InternalPageBase |
18 | 18 | { |
19 | - use RequestListData; |
|
19 | + use RequestListData; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Main function for this page, when no specific actions are called. |
|
23 | - * @return void |
|
24 | - * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
25 | - */ |
|
26 | - protected function main() |
|
27 | - { |
|
28 | - $config = $this->getSiteConfiguration(); |
|
21 | + /** |
|
22 | + * Main function for this page, when no specific actions are called. |
|
23 | + * @return void |
|
24 | + * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
25 | + */ |
|
26 | + protected function main() |
|
27 | + { |
|
28 | + $config = $this->getSiteConfiguration(); |
|
29 | 29 | |
30 | - $requestedStatus = WebRequest::getString('status'); |
|
31 | - $requestStates = $config->getRequestStates(); |
|
30 | + $requestedStatus = WebRequest::getString('status'); |
|
31 | + $requestStates = $config->getRequestStates(); |
|
32 | 32 | |
33 | - if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
|
33 | + if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
|
34 | 34 | |
35 | - $this->assignCSRFToken(); |
|
35 | + $this->assignCSRFToken(); |
|
36 | 36 | |
37 | - $database = $this->getDatabase(); |
|
37 | + $database = $this->getDatabase(); |
|
38 | 38 | |
39 | - $help = $requestStates[$requestedStatus]['queuehelp']; |
|
40 | - $this->assign('queuehelp', $help); |
|
39 | + $help = $requestStates[$requestedStatus]['queuehelp']; |
|
40 | + $this->assign('queuehelp', $help); |
|
41 | 41 | |
42 | - if ($config->getEmailConfirmationEnabled()) { |
|
43 | - $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
44 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
45 | - } |
|
46 | - else { |
|
47 | - $query = "SELECT * FROM request WHERE status = :type;"; |
|
48 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
49 | - } |
|
42 | + if ($config->getEmailConfirmationEnabled()) { |
|
43 | + $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
44 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
45 | + } |
|
46 | + else { |
|
47 | + $query = "SELECT * FROM request WHERE status = :type;"; |
|
48 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
49 | + } |
|
50 | 50 | |
51 | - $statement = $database->prepare($query); |
|
52 | - $totalRequestsStatement = $database->prepare($totalQuery); |
|
51 | + $statement = $database->prepare($query); |
|
52 | + $totalRequestsStatement = $database->prepare($totalQuery); |
|
53 | 53 | |
54 | - $statement->bindValue(":type", $requestedStatus); |
|
55 | - $statement->execute(); |
|
54 | + $statement->bindValue(":type", $requestedStatus); |
|
55 | + $statement->execute(); |
|
56 | 56 | |
57 | - $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
57 | + $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
58 | 58 | |
59 | - /** @var Request $req */ |
|
60 | - foreach ($requests as $req) { |
|
61 | - $req->setDatabase($database); |
|
62 | - } |
|
59 | + /** @var Request $req */ |
|
60 | + foreach ($requests as $req) { |
|
61 | + $req->setDatabase($database); |
|
62 | + } |
|
63 | 63 | |
64 | - $this->assign('requests', $this->prepareRequestData($requests)); |
|
65 | - $this->assign('header', $requestedStatus); |
|
66 | - $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
67 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
64 | + $this->assign('requests', $this->prepareRequestData($requests)); |
|
65 | + $this->assign('header', $requestedStatus); |
|
66 | + $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
67 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
68 | 68 | |
69 | - $totalRequestsStatement->bindValue(':type', $requestedStatus); |
|
70 | - $totalRequestsStatement->execute(); |
|
71 | - $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
72 | - $totalRequestsStatement->closeCursor(); |
|
73 | - $this->assign('totalRequests', $totalRequests); |
|
69 | + $totalRequestsStatement->bindValue(':type', $requestedStatus); |
|
70 | + $totalRequestsStatement->execute(); |
|
71 | + $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
72 | + $totalRequestsStatement->closeCursor(); |
|
73 | + $this->assign('totalRequests', $totalRequests); |
|
74 | 74 | |
75 | 75 | |
76 | - $this->setHtmlTitle('{$header|escape}{if $totalRequests > 0} [{$totalRequests|escape}]{/if}'); |
|
77 | - $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
78 | - } |
|
79 | - } |
|
76 | + $this->setHtmlTitle('{$header|escape}{if $totalRequests > 0} [{$totalRequests|escape}]{/if}'); |
|
77 | + $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | } |
@@ -19,54 +19,54 @@ discard block |
||
19 | 19 | |
20 | 20 | class PageMain extends InternalPageBase |
21 | 21 | { |
22 | - use RequestListData; |
|
23 | - |
|
24 | - /** |
|
25 | - * Main function for this page, when no actions are called. |
|
26 | - */ |
|
27 | - protected function main() |
|
28 | - { |
|
29 | - $this->assignCSRFToken(); |
|
30 | - |
|
31 | - $config = $this->getSiteConfiguration(); |
|
32 | - $database = $this->getDatabase(); |
|
33 | - $currentUser = User::getCurrent($database); |
|
34 | - |
|
35 | - // general template configuration |
|
36 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
37 | - $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
38 | - |
|
39 | - $seeAllRequests = $this->barrierTest('seeAllRequests', $currentUser, PageViewRequest::class); |
|
40 | - |
|
41 | - // Fetch request data |
|
42 | - $requestSectionData = array(); |
|
43 | - if ($seeAllRequests) { |
|
44 | - $this->setupStatusSections($database, $config, $requestSectionData); |
|
45 | - $this->setupHospitalQueue($database, $config, $requestSectionData); |
|
46 | - $this->setupJobQueue($database, $config, $requestSectionData); |
|
47 | - } |
|
48 | - $this->setupLastFiveClosedData($database, $seeAllRequests); |
|
49 | - |
|
50 | - // Assign data to template |
|
51 | - $this->assign('requestSectionData', $requestSectionData); |
|
52 | - |
|
53 | - $this->setTemplate('mainpage/mainpage.tpl'); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param PdoDatabase $database |
|
58 | - * @param bool $seeAllRequests |
|
59 | - * |
|
60 | - * @internal param User $currentUser |
|
61 | - */ |
|
62 | - private function setupLastFiveClosedData(PdoDatabase $database, $seeAllRequests) |
|
63 | - { |
|
64 | - $this->assign('showLastFive', $seeAllRequests); |
|
65 | - if (!$seeAllRequests) { |
|
66 | - return; |
|
67 | - } |
|
68 | - |
|
69 | - $query = <<<SQL |
|
22 | + use RequestListData; |
|
23 | + |
|
24 | + /** |
|
25 | + * Main function for this page, when no actions are called. |
|
26 | + */ |
|
27 | + protected function main() |
|
28 | + { |
|
29 | + $this->assignCSRFToken(); |
|
30 | + |
|
31 | + $config = $this->getSiteConfiguration(); |
|
32 | + $database = $this->getDatabase(); |
|
33 | + $currentUser = User::getCurrent($database); |
|
34 | + |
|
35 | + // general template configuration |
|
36 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
37 | + $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
38 | + |
|
39 | + $seeAllRequests = $this->barrierTest('seeAllRequests', $currentUser, PageViewRequest::class); |
|
40 | + |
|
41 | + // Fetch request data |
|
42 | + $requestSectionData = array(); |
|
43 | + if ($seeAllRequests) { |
|
44 | + $this->setupStatusSections($database, $config, $requestSectionData); |
|
45 | + $this->setupHospitalQueue($database, $config, $requestSectionData); |
|
46 | + $this->setupJobQueue($database, $config, $requestSectionData); |
|
47 | + } |
|
48 | + $this->setupLastFiveClosedData($database, $seeAllRequests); |
|
49 | + |
|
50 | + // Assign data to template |
|
51 | + $this->assign('requestSectionData', $requestSectionData); |
|
52 | + |
|
53 | + $this->setTemplate('mainpage/mainpage.tpl'); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param PdoDatabase $database |
|
58 | + * @param bool $seeAllRequests |
|
59 | + * |
|
60 | + * @internal param User $currentUser |
|
61 | + */ |
|
62 | + private function setupLastFiveClosedData(PdoDatabase $database, $seeAllRequests) |
|
63 | + { |
|
64 | + $this->assign('showLastFive', $seeAllRequests); |
|
65 | + if (!$seeAllRequests) { |
|
66 | + return; |
|
67 | + } |
|
68 | + |
|
69 | + $query = <<<SQL |
|
70 | 70 | SELECT request.id, request.name, request.updateversion |
71 | 71 | FROM request /* PageMain::main() */ |
72 | 72 | JOIN log ON log.objectid = request.id AND log.objecttype = 'Request' |
@@ -75,111 +75,111 @@ discard block |
||
75 | 75 | LIMIT 5; |
76 | 76 | SQL; |
77 | 77 | |
78 | - $statement = $database->prepare($query); |
|
79 | - $statement->execute(); |
|
80 | - |
|
81 | - $last5result = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
82 | - |
|
83 | - $this->assign('lastFive', $last5result); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param PdoDatabase $database |
|
88 | - * @param SiteConfiguration $config |
|
89 | - * @param $requestSectionData |
|
90 | - */ |
|
91 | - private function setupHospitalQueue( |
|
92 | - PdoDatabase $database, |
|
93 | - SiteConfiguration $config, |
|
94 | - &$requestSectionData |
|
95 | - ) { |
|
96 | - $search = RequestSearchHelper::get($database) |
|
97 | - ->limit($config->getMiserModeLimit()) |
|
98 | - ->excludingStatus('Closed') |
|
99 | - ->isHospitalised(); |
|
100 | - |
|
101 | - if ($config->getEmailConfirmationEnabled()) { |
|
102 | - $search->withConfirmedEmail(); |
|
103 | - } |
|
104 | - |
|
105 | - $results = $search->getRecordCount($requestCount)->fetch(); |
|
106 | - |
|
107 | - if($requestCount > 0) { |
|
108 | - $requestSectionData['Hospital - Requests failed auto-creation'] = array( |
|
109 | - 'requests' => $this->prepareRequestData($results), |
|
110 | - 'total' => $requestCount, |
|
111 | - 'api' => 'hospital', |
|
112 | - 'type' => 'hospital', |
|
113 | - 'special' => 'Job Queue', |
|
114 | - 'help' => 'This queue lists all the requests which have been attempted to be created in the background, but for which this has failed for one reason or another. Check the job queue to find the error. Requests here may need to be created manually, or it may be possible to re-queue the request for auto-creation by the tool, or it may have been created already. Use your own technical discretion here.', |
|
115 | - 'showAll' => false |
|
116 | - ); |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param PdoDatabase $database |
|
122 | - * @param SiteConfiguration $config |
|
123 | - * @param $requestSectionData |
|
124 | - */ |
|
125 | - private function setupJobQueue( |
|
126 | - PdoDatabase $database, |
|
127 | - SiteConfiguration $config, |
|
128 | - &$requestSectionData |
|
129 | - ) { |
|
130 | - $search = RequestSearchHelper::get($database) |
|
131 | - ->limit($config->getMiserModeLimit()) |
|
132 | - ->byStatus(RequestStatus::JOBQUEUE); |
|
133 | - |
|
134 | - if ($config->getEmailConfirmationEnabled()) { |
|
135 | - $search->withConfirmedEmail(); |
|
136 | - } |
|
137 | - |
|
138 | - $results = $search->getRecordCount($requestCount)->fetch(); |
|
139 | - |
|
140 | - if($requestCount > 0) { |
|
141 | - $requestSectionData['Requests queued in the Job Queue'] = array( |
|
142 | - 'requests' => $this->prepareRequestData($results), |
|
143 | - 'total' => $requestCount, |
|
144 | - 'api' => 'JobQueue', |
|
145 | - 'type' => 'JobQueue', |
|
146 | - 'special' => 'Job Queue', |
|
147 | - 'help' => 'This section lists all the requests which are currently waiting to be created by the tool. Requests should automatically disappear from here within a few minutes.', |
|
148 | - 'showAll' => false |
|
149 | - ); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @param PdoDatabase $database |
|
155 | - * @param SiteConfiguration $config |
|
156 | - * @param $requestSectionData |
|
157 | - */ |
|
158 | - private function setupStatusSections( |
|
159 | - PdoDatabase $database, |
|
160 | - SiteConfiguration $config, |
|
161 | - &$requestSectionData |
|
162 | - ) { |
|
163 | - $search = RequestSearchHelper::get($database)->limit($config->getMiserModeLimit())->notHospitalised(); |
|
164 | - |
|
165 | - if ($config->getEmailConfirmationEnabled()) { |
|
166 | - $search->withConfirmedEmail(); |
|
167 | - } |
|
168 | - |
|
169 | - $allRequestStates = $config->getRequestStates(); |
|
170 | - $requestsByStatus = $search->fetchByStatus(array_keys($allRequestStates)); |
|
171 | - |
|
172 | - foreach ($allRequestStates as $requestState => $requestStateConfig) { |
|
173 | - |
|
174 | - $requestSectionData[$requestStateConfig['header']] = array( |
|
175 | - 'requests' => $this->prepareRequestData($requestsByStatus[$requestState]['data']), |
|
176 | - 'total' => $requestsByStatus[$requestState]['count'], |
|
177 | - 'api' => $requestStateConfig['api'], |
|
178 | - 'type' => $requestState, |
|
179 | - 'special' => null, |
|
180 | - 'help' => $requestStateConfig['queuehelp'], |
|
181 | - 'showAll' => true |
|
182 | - ); |
|
183 | - } |
|
184 | - } |
|
78 | + $statement = $database->prepare($query); |
|
79 | + $statement->execute(); |
|
80 | + |
|
81 | + $last5result = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
82 | + |
|
83 | + $this->assign('lastFive', $last5result); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param PdoDatabase $database |
|
88 | + * @param SiteConfiguration $config |
|
89 | + * @param $requestSectionData |
|
90 | + */ |
|
91 | + private function setupHospitalQueue( |
|
92 | + PdoDatabase $database, |
|
93 | + SiteConfiguration $config, |
|
94 | + &$requestSectionData |
|
95 | + ) { |
|
96 | + $search = RequestSearchHelper::get($database) |
|
97 | + ->limit($config->getMiserModeLimit()) |
|
98 | + ->excludingStatus('Closed') |
|
99 | + ->isHospitalised(); |
|
100 | + |
|
101 | + if ($config->getEmailConfirmationEnabled()) { |
|
102 | + $search->withConfirmedEmail(); |
|
103 | + } |
|
104 | + |
|
105 | + $results = $search->getRecordCount($requestCount)->fetch(); |
|
106 | + |
|
107 | + if($requestCount > 0) { |
|
108 | + $requestSectionData['Hospital - Requests failed auto-creation'] = array( |
|
109 | + 'requests' => $this->prepareRequestData($results), |
|
110 | + 'total' => $requestCount, |
|
111 | + 'api' => 'hospital', |
|
112 | + 'type' => 'hospital', |
|
113 | + 'special' => 'Job Queue', |
|
114 | + 'help' => 'This queue lists all the requests which have been attempted to be created in the background, but for which this has failed for one reason or another. Check the job queue to find the error. Requests here may need to be created manually, or it may be possible to re-queue the request for auto-creation by the tool, or it may have been created already. Use your own technical discretion here.', |
|
115 | + 'showAll' => false |
|
116 | + ); |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param PdoDatabase $database |
|
122 | + * @param SiteConfiguration $config |
|
123 | + * @param $requestSectionData |
|
124 | + */ |
|
125 | + private function setupJobQueue( |
|
126 | + PdoDatabase $database, |
|
127 | + SiteConfiguration $config, |
|
128 | + &$requestSectionData |
|
129 | + ) { |
|
130 | + $search = RequestSearchHelper::get($database) |
|
131 | + ->limit($config->getMiserModeLimit()) |
|
132 | + ->byStatus(RequestStatus::JOBQUEUE); |
|
133 | + |
|
134 | + if ($config->getEmailConfirmationEnabled()) { |
|
135 | + $search->withConfirmedEmail(); |
|
136 | + } |
|
137 | + |
|
138 | + $results = $search->getRecordCount($requestCount)->fetch(); |
|
139 | + |
|
140 | + if($requestCount > 0) { |
|
141 | + $requestSectionData['Requests queued in the Job Queue'] = array( |
|
142 | + 'requests' => $this->prepareRequestData($results), |
|
143 | + 'total' => $requestCount, |
|
144 | + 'api' => 'JobQueue', |
|
145 | + 'type' => 'JobQueue', |
|
146 | + 'special' => 'Job Queue', |
|
147 | + 'help' => 'This section lists all the requests which are currently waiting to be created by the tool. Requests should automatically disappear from here within a few minutes.', |
|
148 | + 'showAll' => false |
|
149 | + ); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @param PdoDatabase $database |
|
155 | + * @param SiteConfiguration $config |
|
156 | + * @param $requestSectionData |
|
157 | + */ |
|
158 | + private function setupStatusSections( |
|
159 | + PdoDatabase $database, |
|
160 | + SiteConfiguration $config, |
|
161 | + &$requestSectionData |
|
162 | + ) { |
|
163 | + $search = RequestSearchHelper::get($database)->limit($config->getMiserModeLimit())->notHospitalised(); |
|
164 | + |
|
165 | + if ($config->getEmailConfirmationEnabled()) { |
|
166 | + $search->withConfirmedEmail(); |
|
167 | + } |
|
168 | + |
|
169 | + $allRequestStates = $config->getRequestStates(); |
|
170 | + $requestsByStatus = $search->fetchByStatus(array_keys($allRequestStates)); |
|
171 | + |
|
172 | + foreach ($allRequestStates as $requestState => $requestStateConfig) { |
|
173 | + |
|
174 | + $requestSectionData[$requestStateConfig['header']] = array( |
|
175 | + 'requests' => $this->prepareRequestData($requestsByStatus[$requestState]['data']), |
|
176 | + 'total' => $requestsByStatus[$requestState]['count'], |
|
177 | + 'api' => $requestStateConfig['api'], |
|
178 | + 'type' => $requestState, |
|
179 | + 'special' => null, |
|
180 | + 'help' => $requestStateConfig['queuehelp'], |
|
181 | + 'showAll' => true |
|
182 | + ); |
|
183 | + } |
|
184 | + } |
|
185 | 185 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | $results = $search->getRecordCount($requestCount)->fetch(); |
106 | 106 | |
107 | - if($requestCount > 0) { |
|
107 | + if ($requestCount > 0) { |
|
108 | 108 | $requestSectionData['Hospital - Requests failed auto-creation'] = array( |
109 | 109 | 'requests' => $this->prepareRequestData($results), |
110 | 110 | 'total' => $requestCount, |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | |
138 | 138 | $results = $search->getRecordCount($requestCount)->fetch(); |
139 | 139 | |
140 | - if($requestCount > 0) { |
|
140 | + if ($requestCount > 0) { |
|
141 | 141 | $requestSectionData['Requests queued in the Job Queue'] = array( |
142 | 142 | 'requests' => $this->prepareRequestData($results), |
143 | 143 | 'total' => $requestCount, |
@@ -18,144 +18,144 @@ |
||
18 | 18 | |
19 | 19 | class PageSearch extends InternalPageBase |
20 | 20 | { |
21 | - use RequestListData; |
|
22 | - |
|
23 | - /** |
|
24 | - * Main function for this page, when no specific actions are called. |
|
25 | - */ |
|
26 | - protected function main() |
|
27 | - { |
|
28 | - $this->setHtmlTitle('Search'); |
|
29 | - |
|
30 | - // Dual-mode page |
|
31 | - if (WebRequest::wasPosted()) { |
|
32 | - $searchType = WebRequest::postString('type'); |
|
33 | - $searchTerm = WebRequest::postString('term'); |
|
34 | - |
|
35 | - $validationError = ""; |
|
36 | - if (!$this->validateSearchParameters($searchType, $searchTerm, $validationError)) { |
|
37 | - SessionAlert::error($validationError, "Search error"); |
|
38 | - $this->redirect("search"); |
|
39 | - |
|
40 | - return; |
|
41 | - } |
|
42 | - |
|
43 | - $results = array(); |
|
44 | - |
|
45 | - switch ($searchType) { |
|
46 | - case 'name': |
|
47 | - $results = $this->getNameSearchResults($searchTerm); |
|
48 | - break; |
|
49 | - case 'email': |
|
50 | - $results = $this->getEmailSearchResults($searchTerm); |
|
51 | - break; |
|
52 | - case 'ip': |
|
53 | - $results = $this->getIpSearchResults($searchTerm); |
|
54 | - break; |
|
55 | - } |
|
56 | - |
|
57 | - // deal with results |
|
58 | - $this->assign('requests', $this->prepareRequestData($results)); |
|
59 | - $this->assign('resultCount', count($results)); |
|
60 | - $this->assign('term', $searchTerm); |
|
61 | - $this->assign('target', $searchType); |
|
62 | - |
|
63 | - $this->assignCSRFToken(); |
|
64 | - $this->setTemplate('search/searchResult.tpl'); |
|
65 | - } |
|
66 | - else { |
|
67 | - $this->assignCSRFToken(); |
|
68 | - $this->setTemplate('search/searchForm.tpl'); |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Gets search results by name |
|
74 | - * |
|
75 | - * @param string $searchTerm |
|
76 | - * |
|
77 | - * @returns Request[] |
|
78 | - */ |
|
79 | - private function getNameSearchResults($searchTerm) |
|
80 | - { |
|
81 | - $padded = '%' . $searchTerm . '%'; |
|
82 | - |
|
83 | - /** @var Request[] $requests */ |
|
84 | - $requests = RequestSearchHelper::get($this->getDatabase()) |
|
85 | - ->byName($padded) |
|
86 | - ->fetch(); |
|
87 | - |
|
88 | - return $requests; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Gets search results by email |
|
93 | - * |
|
94 | - * @param string $searchTerm |
|
95 | - * |
|
96 | - * @return Request[] |
|
97 | - * @throws ApplicationLogicException |
|
98 | - */ |
|
99 | - private function getEmailSearchResults($searchTerm) |
|
100 | - { |
|
101 | - if ($searchTerm === "@") { |
|
102 | - throw new ApplicationLogicException('The search term "@" is not valid for email address searches!'); |
|
103 | - } |
|
104 | - |
|
105 | - $padded = '%' . $searchTerm . '%'; |
|
106 | - |
|
107 | - /** @var Request[] $requests */ |
|
108 | - $requests = RequestSearchHelper::get($this->getDatabase()) |
|
109 | - ->byEmailAddress($padded) |
|
110 | - ->excludingPurgedData($this->getSiteConfiguration()) |
|
111 | - ->fetch(); |
|
112 | - |
|
113 | - return $requests; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Gets search results by IP address or XFF IP address |
|
118 | - * |
|
119 | - * @param string $searchTerm |
|
120 | - * |
|
121 | - * @returns Request[] |
|
122 | - */ |
|
123 | - private function getIpSearchResults($searchTerm) |
|
124 | - { |
|
125 | - /** @var Request[] $requests */ |
|
126 | - $requests = RequestSearchHelper::get($this->getDatabase()) |
|
127 | - ->byIp($searchTerm) |
|
128 | - ->excludingPurgedData($this->getSiteConfiguration()) |
|
129 | - ->fetch(); |
|
130 | - |
|
131 | - return $requests; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @param string $searchType |
|
136 | - * @param string $searchTerm |
|
137 | - * |
|
138 | - * @param string $errorMessage |
|
139 | - * |
|
140 | - * @return bool true if parameters are valid |
|
141 | - * @throws ApplicationLogicException |
|
142 | - */ |
|
143 | - protected function validateSearchParameters($searchType, $searchTerm, &$errorMessage) |
|
144 | - { |
|
145 | - if (!in_array($searchType, array('name', 'email', 'ip'))) { |
|
146 | - $errorMessage = 'Unknown search type'; |
|
147 | - |
|
148 | - return false; |
|
149 | - } |
|
150 | - |
|
151 | - if ($searchTerm === '%' || $searchTerm === '' || $searchTerm === null) { |
|
152 | - $errorMessage = 'No search term specified entered'; |
|
153 | - |
|
154 | - return false; |
|
155 | - } |
|
156 | - |
|
157 | - $errorMessage = ""; |
|
158 | - |
|
159 | - return true; |
|
160 | - } |
|
21 | + use RequestListData; |
|
22 | + |
|
23 | + /** |
|
24 | + * Main function for this page, when no specific actions are called. |
|
25 | + */ |
|
26 | + protected function main() |
|
27 | + { |
|
28 | + $this->setHtmlTitle('Search'); |
|
29 | + |
|
30 | + // Dual-mode page |
|
31 | + if (WebRequest::wasPosted()) { |
|
32 | + $searchType = WebRequest::postString('type'); |
|
33 | + $searchTerm = WebRequest::postString('term'); |
|
34 | + |
|
35 | + $validationError = ""; |
|
36 | + if (!$this->validateSearchParameters($searchType, $searchTerm, $validationError)) { |
|
37 | + SessionAlert::error($validationError, "Search error"); |
|
38 | + $this->redirect("search"); |
|
39 | + |
|
40 | + return; |
|
41 | + } |
|
42 | + |
|
43 | + $results = array(); |
|
44 | + |
|
45 | + switch ($searchType) { |
|
46 | + case 'name': |
|
47 | + $results = $this->getNameSearchResults($searchTerm); |
|
48 | + break; |
|
49 | + case 'email': |
|
50 | + $results = $this->getEmailSearchResults($searchTerm); |
|
51 | + break; |
|
52 | + case 'ip': |
|
53 | + $results = $this->getIpSearchResults($searchTerm); |
|
54 | + break; |
|
55 | + } |
|
56 | + |
|
57 | + // deal with results |
|
58 | + $this->assign('requests', $this->prepareRequestData($results)); |
|
59 | + $this->assign('resultCount', count($results)); |
|
60 | + $this->assign('term', $searchTerm); |
|
61 | + $this->assign('target', $searchType); |
|
62 | + |
|
63 | + $this->assignCSRFToken(); |
|
64 | + $this->setTemplate('search/searchResult.tpl'); |
|
65 | + } |
|
66 | + else { |
|
67 | + $this->assignCSRFToken(); |
|
68 | + $this->setTemplate('search/searchForm.tpl'); |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Gets search results by name |
|
74 | + * |
|
75 | + * @param string $searchTerm |
|
76 | + * |
|
77 | + * @returns Request[] |
|
78 | + */ |
|
79 | + private function getNameSearchResults($searchTerm) |
|
80 | + { |
|
81 | + $padded = '%' . $searchTerm . '%'; |
|
82 | + |
|
83 | + /** @var Request[] $requests */ |
|
84 | + $requests = RequestSearchHelper::get($this->getDatabase()) |
|
85 | + ->byName($padded) |
|
86 | + ->fetch(); |
|
87 | + |
|
88 | + return $requests; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Gets search results by email |
|
93 | + * |
|
94 | + * @param string $searchTerm |
|
95 | + * |
|
96 | + * @return Request[] |
|
97 | + * @throws ApplicationLogicException |
|
98 | + */ |
|
99 | + private function getEmailSearchResults($searchTerm) |
|
100 | + { |
|
101 | + if ($searchTerm === "@") { |
|
102 | + throw new ApplicationLogicException('The search term "@" is not valid for email address searches!'); |
|
103 | + } |
|
104 | + |
|
105 | + $padded = '%' . $searchTerm . '%'; |
|
106 | + |
|
107 | + /** @var Request[] $requests */ |
|
108 | + $requests = RequestSearchHelper::get($this->getDatabase()) |
|
109 | + ->byEmailAddress($padded) |
|
110 | + ->excludingPurgedData($this->getSiteConfiguration()) |
|
111 | + ->fetch(); |
|
112 | + |
|
113 | + return $requests; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Gets search results by IP address or XFF IP address |
|
118 | + * |
|
119 | + * @param string $searchTerm |
|
120 | + * |
|
121 | + * @returns Request[] |
|
122 | + */ |
|
123 | + private function getIpSearchResults($searchTerm) |
|
124 | + { |
|
125 | + /** @var Request[] $requests */ |
|
126 | + $requests = RequestSearchHelper::get($this->getDatabase()) |
|
127 | + ->byIp($searchTerm) |
|
128 | + ->excludingPurgedData($this->getSiteConfiguration()) |
|
129 | + ->fetch(); |
|
130 | + |
|
131 | + return $requests; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @param string $searchType |
|
136 | + * @param string $searchTerm |
|
137 | + * |
|
138 | + * @param string $errorMessage |
|
139 | + * |
|
140 | + * @return bool true if parameters are valid |
|
141 | + * @throws ApplicationLogicException |
|
142 | + */ |
|
143 | + protected function validateSearchParameters($searchType, $searchTerm, &$errorMessage) |
|
144 | + { |
|
145 | + if (!in_array($searchType, array('name', 'email', 'ip'))) { |
|
146 | + $errorMessage = 'Unknown search type'; |
|
147 | + |
|
148 | + return false; |
|
149 | + } |
|
150 | + |
|
151 | + if ($searchTerm === '%' || $searchTerm === '' || $searchTerm === null) { |
|
152 | + $errorMessage = 'No search term specified entered'; |
|
153 | + |
|
154 | + return false; |
|
155 | + } |
|
156 | + |
|
157 | + $errorMessage = ""; |
|
158 | + |
|
159 | + return true; |
|
160 | + } |
|
161 | 161 | } |
@@ -16,14 +16,14 @@ |
||
16 | 16 | */ |
17 | 17 | class RequestList |
18 | 18 | { |
19 | - public $requests; |
|
20 | - public $showPrivateData; |
|
21 | - public $dataClearEmail; |
|
22 | - public $dataClearIp; |
|
23 | - public $relatedEmailRequests; |
|
24 | - public $relatedIpRequests; |
|
25 | - public $requestTrustedIp; |
|
26 | - public $canBan; |
|
27 | - public $canBreakReservation; |
|
28 | - public $userList; |
|
19 | + public $requests; |
|
20 | + public $showPrivateData; |
|
21 | + public $dataClearEmail; |
|
22 | + public $dataClearIp; |
|
23 | + public $relatedEmailRequests; |
|
24 | + public $relatedIpRequests; |
|
25 | + public $requestTrustedIp; |
|
26 | + public $canBan; |
|
27 | + public $canBreakReservation; |
|
28 | + public $userList; |
|
29 | 29 | } |
@@ -18,71 +18,71 @@ |
||
18 | 18 | |
19 | 19 | trait RequestListData |
20 | 20 | { |
21 | - // function imports from InternalPageBase etc. |
|
22 | - protected abstract function getDatabase(); |
|
23 | - |
|
24 | - protected abstract function getXffTrustProvider(); |
|
25 | - |
|
26 | - protected abstract function getSiteConfiguration(); |
|
27 | - |
|
28 | - protected abstract function barrierTest($action, User $user, $pageName = null); |
|
29 | - |
|
30 | - /** |
|
31 | - * @param Request[] $requests |
|
32 | - * |
|
33 | - * @return RequestList |
|
34 | - */ |
|
35 | - protected function prepareRequestData(array $requests) : RequestList |
|
36 | - { |
|
37 | - $requestList = new RequestList(); |
|
38 | - $requestList->requests = $requests; |
|
39 | - |
|
40 | - $userIds = array_map( |
|
41 | - function(Request $entry) { |
|
42 | - return $entry->getReserved(); |
|
43 | - }, |
|
44 | - $requests |
|
45 | - ); |
|
46 | - |
|
47 | - $requestList->userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
48 | - |
|
49 | - $requestList->requestTrustedIp = []; |
|
50 | - $requestList->relatedIpRequests = []; |
|
51 | - $requestList->relatedEmailRequests = []; |
|
52 | - |
|
53 | - foreach ($requests as $request) { |
|
54 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
55 | - $request->getIp(), |
|
56 | - $request->getForwardedIp() |
|
57 | - ); |
|
58 | - |
|
59 | - RequestSearchHelper::get($this->getDatabase()) |
|
60 | - ->byIp($trustedIp) |
|
61 | - ->withConfirmedEmail() |
|
62 | - ->excludingPurgedData($this->getSiteConfiguration()) |
|
63 | - ->excludingRequest($request->getId()) |
|
64 | - ->getRecordCount($ipCount); |
|
65 | - |
|
66 | - RequestSearchHelper::get($this->getDatabase()) |
|
67 | - ->byEmailAddress($request->getEmail()) |
|
68 | - ->withConfirmedEmail() |
|
69 | - ->excludingPurgedData($this->getSiteConfiguration()) |
|
70 | - ->excludingRequest($request->getId()) |
|
71 | - ->getRecordCount($emailCount); |
|
72 | - |
|
73 | - $requestList->requestTrustedIp[$request->getId()] = $trustedIp; |
|
74 | - $requestList->relatedEmailRequests[$request->getId()] = $emailCount; |
|
75 | - $requestList->relatedIpRequests[$request->getId()] = $ipCount; |
|
76 | - } |
|
77 | - |
|
78 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
79 | - |
|
80 | - $requestList->canBan = $this->barrierTest('set', $currentUser, PageBan::class); |
|
81 | - $requestList->canBreakReservation = $this->barrierTest('force', $currentUser, PageBreakReservation::class); |
|
82 | - $requestList->showPrivateData = $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData'); |
|
83 | - $requestList->dataClearEmail = $this->getSiteConfiguration()->getDataClearEmail(); |
|
84 | - $requestList->dataClearIp = $this->getSiteConfiguration()->getDataClearIp(); |
|
85 | - |
|
86 | - return $requestList; |
|
87 | - } |
|
21 | + // function imports from InternalPageBase etc. |
|
22 | + protected abstract function getDatabase(); |
|
23 | + |
|
24 | + protected abstract function getXffTrustProvider(); |
|
25 | + |
|
26 | + protected abstract function getSiteConfiguration(); |
|
27 | + |
|
28 | + protected abstract function barrierTest($action, User $user, $pageName = null); |
|
29 | + |
|
30 | + /** |
|
31 | + * @param Request[] $requests |
|
32 | + * |
|
33 | + * @return RequestList |
|
34 | + */ |
|
35 | + protected function prepareRequestData(array $requests) : RequestList |
|
36 | + { |
|
37 | + $requestList = new RequestList(); |
|
38 | + $requestList->requests = $requests; |
|
39 | + |
|
40 | + $userIds = array_map( |
|
41 | + function(Request $entry) { |
|
42 | + return $entry->getReserved(); |
|
43 | + }, |
|
44 | + $requests |
|
45 | + ); |
|
46 | + |
|
47 | + $requestList->userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
48 | + |
|
49 | + $requestList->requestTrustedIp = []; |
|
50 | + $requestList->relatedIpRequests = []; |
|
51 | + $requestList->relatedEmailRequests = []; |
|
52 | + |
|
53 | + foreach ($requests as $request) { |
|
54 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
55 | + $request->getIp(), |
|
56 | + $request->getForwardedIp() |
|
57 | + ); |
|
58 | + |
|
59 | + RequestSearchHelper::get($this->getDatabase()) |
|
60 | + ->byIp($trustedIp) |
|
61 | + ->withConfirmedEmail() |
|
62 | + ->excludingPurgedData($this->getSiteConfiguration()) |
|
63 | + ->excludingRequest($request->getId()) |
|
64 | + ->getRecordCount($ipCount); |
|
65 | + |
|
66 | + RequestSearchHelper::get($this->getDatabase()) |
|
67 | + ->byEmailAddress($request->getEmail()) |
|
68 | + ->withConfirmedEmail() |
|
69 | + ->excludingPurgedData($this->getSiteConfiguration()) |
|
70 | + ->excludingRequest($request->getId()) |
|
71 | + ->getRecordCount($emailCount); |
|
72 | + |
|
73 | + $requestList->requestTrustedIp[$request->getId()] = $trustedIp; |
|
74 | + $requestList->relatedEmailRequests[$request->getId()] = $emailCount; |
|
75 | + $requestList->relatedIpRequests[$request->getId()] = $ipCount; |
|
76 | + } |
|
77 | + |
|
78 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
79 | + |
|
80 | + $requestList->canBan = $this->barrierTest('set', $currentUser, PageBan::class); |
|
81 | + $requestList->canBreakReservation = $this->barrierTest('force', $currentUser, PageBreakReservation::class); |
|
82 | + $requestList->showPrivateData = $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData'); |
|
83 | + $requestList->dataClearEmail = $this->getSiteConfiguration()->getDataClearEmail(); |
|
84 | + $requestList->dataClearIp = $this->getSiteConfiguration()->getDataClearIp(); |
|
85 | + |
|
86 | + return $requestList; |
|
87 | + } |
|
88 | 88 | } |