[CLEANUP] Rework/simplify copyright header and remove @package
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Widget / Controller / AutocompleteController.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * Class AutocompleteController
21 *
22 */
23 class AutocompleteController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController {
24
25 /**
26 * @return void
27 */
28 public function indexAction() {
29 $this->view->assign('id', $this->widgetConfiguration['for']);
30 }
31
32 /**
33 * @param string $term
34 * @return string
35 */
36 public function autocompleteAction($term) {
37 $searchProperty = $this->widgetConfiguration['searchProperty'];
38 $query = $this->widgetConfiguration['objects']->getQuery();
39 $constraint = $query->getConstraint();
40 if ($constraint !== NULL) {
41 $query->matching($query->logicalAnd($constraint, $query->like($searchProperty, '%' . $term . '%', FALSE)));
42 } else {
43 $query->matching($query->like($searchProperty, '%' . $term . '%', FALSE));
44 }
45 $results = $query->execute();
46 $output = array();
47 foreach ($results as $singleResult) {
48 $val = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($singleResult, $searchProperty);
49 $output[] = array(
50 'id' => $val,
51 'label' => $val,
52 'value' => $val
53 );
54 }
55 return json_encode($output);
56 }
57 }