[BUGFIX] Namespace switch LiveSearch main patch
[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 * @package TYPO3
36 * @subpackage t3lib
37 */
38 class LiveSearchDataProvider {
39
40 /**
41 * @var array
42 */
43 protected $searchResults = array(
44 'pageJump' => '',
45 'searchItems' => array()
46 );
47
48 /**
49 * @var \TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch
50 */
51 protected $liveSearch = NULL;
52
53 /**
54 * @var \TYPO3\CMS\Backend\Search\LiveSearch\QueryParser
55 */
56 protected $queryParser = NULL;
57
58 /**
59 * Initialize the live search
60 */
61 public function __construct() {
62 // @todo Use the autoloader for this. Not sure why its not working.
63 require_once PATH_t3lib . 'search/class.t3lib_search_livesearch_queryParser.php';
64 $this->liveSearch = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Search\\LiveSearch\\LiveSearch');
65 $this->queryParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Search\\LiveSearch\\QueryParser');
66 }
67
68 /**
69 * @param stdClass $command
70 * @return array
71 */
72 public function find($command) {
73 $this->liveSearch->setStartCount($command->start);
74 $this->liveSearch->setLimitCount($command->limit);
75 $this->liveSearch->setQueryString($command->query);
76 // Jump & edit - find page and retrieve an edit link (this is only for pages
77 if ($this->queryParser->isValidPageJump($command->query)) {
78 $this->searchResults['pageJump'] = $this->liveSearch->findPage($command->query);
79 $commandQuery = $this->queryParser->getCommandForPageJump($command->query);
80 if ($commandQuery) {
81 $command->query = $commandQuery;
82 }
83 }
84 // Search through the database and find records who match to the given search string
85 $resultArray = $this->liveSearch->find($command->query);
86 foreach ($resultArray as $resultFromTable) {
87 foreach ($resultFromTable as $item) {
88 $this->searchResults['searchItems'][] = $item;
89 }
90 }
91 return $this->searchResults;
92 }
93
94 }
95
96
97 ?>