[TASK] Remove not necessary require_once in LiveSearchDataProvider
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Search / LiveSearch / ExtDirect / LiveSearchDataProvider.php
1 <?php
2 namespace TYPO3\CMS\Backend\Search\LiveSearch\ExtDirect;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2011 Michael Klapper <michael.klapper@aoemedia.de>
8 * (c) 2010-2011 Jeff Segars <jeff@webempoweredchurch.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * ExtDirect Class for handling backend live search.
32 *
33 * @author Michael Klapper <michael.klapper@aoemedia.de>
34 * @author Jeff Segars <jeff@webempoweredchurch.org>
35 */
36 class LiveSearchDataProvider {
37
38 /**
39 * @var array
40 */
41 protected $searchResults = array(
42 'pageJump' => '',
43 'searchItems' => array()
44 );
45
46 /**
47 * @var \TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch
48 */
49 protected $liveSearch = NULL;
50
51 /**
52 * @var \TYPO3\CMS\Backend\Search\LiveSearch\QueryParser
53 */
54 protected $queryParser = NULL;
55
56 /**
57 * Initialize the live search
58 */
59 public function __construct() {
60 $this->liveSearch = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Search\\LiveSearch\\LiveSearch');
61 $this->queryParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Search\\LiveSearch\\QueryParser');
62 }
63
64 /**
65 * @param stdClass $command
66 * @return array
67 */
68 public function find($command) {
69 $this->liveSearch->setStartCount($command->start);
70 $this->liveSearch->setLimitCount($command->limit);
71 $this->liveSearch->setQueryString($command->query);
72 // Jump & edit - find page and retrieve an edit link (this is only for pages
73 if ($this->queryParser->isValidPageJump($command->query)) {
74 $this->searchResults['pageJump'] = $this->liveSearch->findPage($command->query);
75 $commandQuery = $this->queryParser->getCommandForPageJump($command->query);
76 if ($commandQuery) {
77 $command->query = $commandQuery;
78 }
79 }
80 // Search through the database and find records who match to the given search string
81 $resultArray = $this->liveSearch->find($command->query);
82 foreach ($resultArray as $resultFromTable) {
83 foreach ($resultFromTable as $item) {
84 $this->searchResults['searchItems'][] = $item;
85 }
86 }
87 return $this->searchResults;
88 }
89
90 }
91
92
93 ?>