Passed
Pull Request — master (#213)
by
unknown
33:41 queued 23:20
created

DataServiceAjaxController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 23
dl 0
loc 48
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A autocompleteAction() 0 21 3
A searchGndKeywordAction() 0 14 2
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