1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Tag controller |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace HDNET\Tagger\Controller; |
8
|
|
|
|
9
|
|
|
use HDNET\Tagger\Domain\Model\Tag; |
10
|
|
|
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser; |
11
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
12
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
13
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class TagController |
17
|
|
|
*/ |
18
|
|
|
class TagController extends ActionController |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Tag repository |
23
|
|
|
* |
24
|
|
|
* @var \HDNET\Tagger\Domain\Repository\TagRepository |
25
|
|
|
* @inject |
26
|
|
|
*/ |
27
|
|
|
protected $tagRepository; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Render the textcloud |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function textcloudAction() |
35
|
|
|
{ |
36
|
|
|
$tags = $this->getTags(); |
37
|
|
|
$this->view->assign('tags', $tags); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Render a simple list |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function listAction() |
46
|
|
|
{ |
47
|
|
|
$tags = $this->getTags(); |
48
|
|
|
$this->view->assign('tags', $tags); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get the Tags by the current configuration |
53
|
|
|
* |
54
|
|
|
* @return array|QueryResultInterface |
55
|
|
|
* @throws \Exception |
56
|
|
|
* @todo Move the link to a pseudo field |
57
|
|
|
* @todo Sort the preparation |
58
|
|
|
* @todo weightscale |
59
|
|
|
*/ |
60
|
|
|
protected function getTags() |
61
|
|
|
{ |
62
|
|
|
// Get the tags |
63
|
|
|
$tags = $this->tagRepository->findByConfiguration( |
64
|
|
|
$this->settings['selection']['relation'], |
65
|
|
|
$this->settings['selection']['sorting'], |
66
|
|
|
$this->settings['selection']['ordering'], |
67
|
|
|
$this->settings['selection']['amount'] |
68
|
|
|
) |
69
|
|
|
->toArray(); |
70
|
|
|
|
71
|
|
|
// Data preperation (link) |
72
|
|
|
foreach ($tags as $tag) { |
73
|
|
|
/** @var $tag Tag */ |
74
|
|
|
if (trim($tag->getLink()) == '') { |
75
|
|
|
$tag->setLink($this->getLink($tag)); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
// Data preperation (weightscale) |
80
|
|
|
// Data preperation (sorting) |
81
|
|
|
switch ($this->settings['preperation']['sorting']) { |
82
|
|
|
case 'random': |
83
|
|
|
shuffle($tags); |
84
|
|
|
break; |
85
|
|
|
case 'weight': |
86
|
|
|
shuffle($tags); |
87
|
|
|
break; |
88
|
|
|
case 'alphabethicaly': |
89
|
|
|
shuffle($tags); |
90
|
|
|
break; |
91
|
|
|
default: |
92
|
|
|
throw new \Exception('No valid preperation->sorting: ' . $this->settings['preperation']['sorting'], 241724618941); |
93
|
|
|
break; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// Data preperation (ordering) |
97
|
|
|
if ($this->settings['preperation']['ordering'] == 'desc') { |
98
|
|
|
$tags = array_reverse($tags); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $tags; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get link |
106
|
|
|
* |
107
|
|
|
* @param Tag $tag |
108
|
|
|
* |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
protected function getLink(Tag $tag) |
112
|
|
|
{ |
113
|
|
|
$configuration = $this->settings['preperation']['linkconfiguration']; |
114
|
|
|
|
115
|
|
|
$parser = GeneralUtility::makeInstance(TypoScriptParser::class); |
116
|
|
|
$parser->parse($configuration); |
117
|
|
|
|
118
|
|
|
$configuration = [ |
119
|
|
|
'value' => '', |
120
|
|
|
'typolink.' => $parser->setup |
121
|
|
|
]; |
122
|
|
|
$configuration['typolink.']['returnLast'] = 'url'; |
123
|
|
|
|
124
|
|
|
// check if (array) works |
125
|
|
|
// get_object_vars() |
126
|
|
|
return $this->renderSingle((array)$tag, $configuration); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Parses data through typoscript. |
131
|
|
|
* |
132
|
|
|
* @param array $data |
133
|
|
|
* @param array $configuration |
134
|
|
|
* @param string $type |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
protected function renderSingle(array $data, array $configuration, $type = 'TEXT') |
139
|
|
|
{ |
140
|
|
|
$cObj = $this->configurationManager->getContentObject(); |
141
|
|
|
$cObj->data = $data; |
142
|
|
|
return $cObj->cObjGetSingle($type, $configuration); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.