[CLEANUP] Add phpDoc to properties in ext:backend
[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 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * ExtDirect Class for handling backend live search.
19 *
20 * @author Michael Klapper <michael.klapper@aoemedia.de>
21 * @author Jeff Segars <jeff@webempoweredchurch.org>
22 */
23 class LiveSearchDataProvider {
24
25 /**
26 * @var array
27 */
28 protected $searchResults = array(
29 'pageJump' => '',
30 'searchItems' => array()
31 );
32
33 /**
34 * @var \TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch
35 */
36 protected $liveSearch = NULL;
37
38 /**
39 * @var \TYPO3\CMS\Backend\Search\LiveSearch\QueryParser
40 */
41 protected $queryParser = NULL;
42
43 /**
44 * Initialize the live search
45 */
46 public function __construct() {
47 $this->liveSearch = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Search\\LiveSearch\\LiveSearch');
48 $this->queryParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Search\\LiveSearch\\QueryParser');
49 }
50
51 /**
52 * @param stdClass $command
53 * @return array
54 */
55 public function find($command) {
56 $this->liveSearch->setStartCount($command->start);
57 $this->liveSearch->setLimitCount($command->limit);
58 $this->liveSearch->setQueryString($command->query);
59 // Jump & edit - find page and retrieve an edit link (this is only for pages
60 if ($this->queryParser->isValidPageJump($command->query)) {
61 $this->searchResults['pageJump'] = $this->liveSearch->findPage($command->query);
62 $commandQuery = $this->queryParser->getCommandForPageJump($command->query);
63 if ($commandQuery) {
64 $command->query = $commandQuery;
65 }
66 }
67 // Search through the database and find records who match to the given search string
68 $resultArray = $this->liveSearch->find($command->query);
69 foreach ($resultArray as $resultFromTable) {
70 foreach ($resultFromTable as $item) {
71 $this->searchResults['searchItems'][] = $item;
72 }
73 }
74 return $this->searchResults;
75 }
76
77 }