File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ services:
7272 class : phpbb\ideas\controller\livesearch_controller
7373 parent : phpbb.ideas.controller.base
7474 calls :
75- - [get_entity, ['@phpbb.ideas.ideas ']]
75+ - [get_entity, ['@phpbb.ideas.livesearch ']]
7676
7777# ----- Idea Factory Classes -----
7878 phpbb.ideas.base :
@@ -96,6 +96,10 @@ services:
9696 class : phpbb\ideas\factory\idea
9797 parent : phpbb.ideas.base
9898
99+ phpbb.ideas.livesearch :
100+ class : phpbb\ideas\factory\livesearch
101+ parent : phpbb.ideas.base
102+
99103 phpbb.ideas.linkhelper :
100104 class : phpbb\ideas\factory\linkhelper
101105 arguments :
Original file line number Diff line number Diff line change 1515 */
1616class livesearch_controller extends base
1717{
18- /* @var \phpbb\ideas\factory\ideas */
18+ /* @var \phpbb\ideas\factory\livesearch */
1919 protected $ entity ;
2020
2121 /**
@@ -27,7 +27,7 @@ public function title_search()
2727 {
2828 $ title_chars = $ this ->request ->variable ('duplicateeditinput ' , '' , true );
2929
30- $ matches = $ this ->ideas -> livesearch ($ title_chars , 10 );
30+ $ matches = $ this ->entity -> title_search ($ title_chars , 10 );
3131
3232 return new \Symfony \Component \HttpFoundation \JsonResponse ([
3333 'keyword ' => $ title_chars ,
Original file line number Diff line number Diff line change @@ -219,35 +219,6 @@ protected function query_count()
219219 return $ count ;
220220 }
221221
222- /**
223- * Do a live search on idea titles. Return any matches based on a given search query.
224- *
225- * @param string $search The string of characters to search using LIKE
226- * @param int $limit The number of results to return
227- *
228- * @return array An array of matching idea id/key and title/values
229- */
230- public function livesearch ($ search , $ limit = 10 )
231- {
232- $ results = [];
233- $ sql = 'SELECT idea_title, idea_id
234- FROM ' . $ this ->table_ideas . '
235- WHERE idea_title ' . $ this ->db ->sql_like_expression ($ this ->db ->get_any_char () . $ search . $ this ->db ->get_any_char ());
236- $ result = $ this ->db ->sql_query_limit ($ sql , $ limit );
237- while ($ row = $ this ->db ->sql_fetchrow ($ result ))
238- {
239- $ results [] = [
240- 'idea_id ' => $ row ['idea_id ' ],
241- 'result ' => $ row ['idea_id ' ],
242- 'clean_title ' => $ row ['idea_title ' ],
243- 'display ' => "<span> {$ row ['idea_title ' ]}</span> " , // spans are expected in phpBB's live search JS
244- ];
245- }
246- $ this ->db ->sql_freeresult ($ result );
247-
248- return $ results ;
249- }
250-
251222 /**
252223 * Get a user's votes from a group of ideas
253224 *
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ *
4+ * Ideas extension for the phpBB Forum Software package.
5+ *
6+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
7+ * @license GNU General Public License, version 2 (GPL-2.0)
8+ *
9+ */
10+
11+ namespace phpbb \ideas \factory ;
12+
13+ /**
14+ * Class for handling multiple ideas
15+ */
16+ class livesearch extends base
17+ {
18+ /** @var array */
19+ protected $ sql ;
20+
21+ /**
22+ * Do a live search on idea titles. Return any matches based on a given search query.
23+ *
24+ * @param string $search The string of characters to search using LIKE
25+ * @param int $limit The number of results to return
26+ *
27+ * @return array An array of matching idea id/key and title/values
28+ */
29+ public function title_search ($ search , $ limit = 10 )
30+ {
31+ $ results = [];
32+ $ sql = 'SELECT idea_title, idea_id
33+ FROM ' . $ this ->table_ideas . '
34+ WHERE idea_title ' . $ this ->db ->sql_like_expression ($ this ->db ->get_any_char () . $ search . $ this ->db ->get_any_char ());
35+ $ result = $ this ->db ->sql_query_limit ($ sql , $ limit );
36+ while ($ row = $ this ->db ->sql_fetchrow ($ result ))
37+ {
38+ $ results [] = [
39+ 'idea_id ' => $ row ['idea_id ' ],
40+ 'result ' => $ row ['idea_id ' ],
41+ 'clean_title ' => $ row ['idea_title ' ],
42+ 'display ' => "<span> {$ row ['idea_title ' ]}</span> " , // spans are expected in phpBB's live search JS
43+ ];
44+ }
45+ $ this ->db ->sql_freeresult ($ result );
46+
47+ return $ results ;
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments