1
|
|
|
<?php |
2
|
|
|
namespace EWW\Dpf\Controller; |
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
|
|
|
use EWW\Dpf\Domain\Model\InputOptionList; |
18
|
|
|
use EWW\Dpf\Services\FeUser\GndDataService; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* DataServiceAjaxController |
22
|
|
|
*/ |
23
|
|
|
class DataServiceAjaxController extends \EWW\Dpf\Controller\AbstractController |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param string $searchTerm |
27
|
|
|
* @return false|string |
28
|
|
|
*/ |
29
|
|
|
public function searchGndKeywordAction(string $searchTerm) { |
30
|
|
|
$gndUserDataService = new GndDataService(); |
31
|
|
|
$result = $gndUserDataService->searchKeywordRequest($searchTerm); |
32
|
|
|
|
33
|
|
|
$listArray = array(); |
34
|
|
|
$i = 0; |
35
|
|
|
foreach ($result as $value) { |
36
|
|
|
$listArray[$i]['value'] = $value->label; |
37
|
|
|
$listArray[$i]['label'] = htmlentities($value->label); |
38
|
|
|
$listArray[$i]['key'] = $value->id; |
39
|
|
|
$i++; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return json_encode($listArray); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param InputOptionList $inputOptionList |
47
|
|
|
* @param string $searchTerm |
48
|
|
|
* @return false|string |
49
|
|
|
*/ |
50
|
|
|
public function autocompleteAction(InputOptionList $inputOptionList, string $searchTerm) |
51
|
|
|
{ |
52
|
|
|
$listArray = array(); |
53
|
|
|
$i = 0; |
54
|
|
|
|
55
|
|
|
if ( |
56
|
|
|
!empty( |
57
|
|
|
$arr = preg_grep( |
58
|
|
|
'/.*?'.$searchTerm.'.*?/i', $inputOptionList->getInputOptions() |
59
|
|
|
) |
60
|
|
|
) |
61
|
|
|
) { |
62
|
|
|
foreach ($arr as $key => $value) { |
63
|
|
|
$listArray[$i]['value'] = $value; |
64
|
|
|
$listArray[$i]['label'] = htmlentities($value); |
65
|
|
|
$listArray[$i]['key'] = $key; |
66
|
|
|
$i++; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return json_encode($listArray); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|