mirror of
https://github.com/SkillDisplay/TYPO3ContentElements.git
synced 2024-11-21 19:16:08 +01:00
[TASK] Refactor SkillGroupingViewHelper
This commit is contained in:
parent
b6e99f84ed
commit
a4f0ba6d23
1 changed files with 13 additions and 30 deletions
|
@ -62,11 +62,7 @@ class SkillGroupingViewHelper extends AbstractViewHelper
|
||||||
$skillSet = $arguments['skillSet'];
|
$skillSet = $arguments['skillSet'];
|
||||||
$as = $arguments['as'];
|
$as = $arguments['as'];
|
||||||
|
|
||||||
if ($skillSet) {
|
$groups = self::group($skillSet ? $skillSet->getSkills() : $skills);
|
||||||
$groups = self::group($skillSet->getSkills());
|
|
||||||
} else {
|
|
||||||
$groups = self::group($skills);
|
|
||||||
}
|
|
||||||
|
|
||||||
$templateVariableContainer = $renderingContext->getVariableProvider();
|
$templateVariableContainer = $renderingContext->getVariableProvider();
|
||||||
$output = '';
|
$output = '';
|
||||||
|
@ -84,32 +80,19 @@ class SkillGroupingViewHelper extends AbstractViewHelper
|
||||||
*/
|
*/
|
||||||
protected static function group(array $skills): array
|
protected static function group(array $skills): array
|
||||||
{
|
{
|
||||||
$domainTagsWithId = [];
|
|
||||||
foreach ($skills as $skill) {
|
|
||||||
if (!isset($skill->toArray()['domainTag'])) {
|
|
||||||
$domainTagsWithId[] = [
|
|
||||||
'uid' => 0,
|
|
||||||
'title' => 'none'
|
|
||||||
];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$domainTagsWithId[] = $skill->toArray()['domainTag'];
|
|
||||||
}
|
|
||||||
//remove items with duplicate title
|
|
||||||
$domainTagsWithId = array_map('unserialize', array_unique(array_map('serialize', $domainTagsWithId)));
|
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($domainTagsWithId as $domainTag) {
|
foreach ($skills as $skill) {
|
||||||
$result[] = [
|
$skillAsArray = $skill->toArray();
|
||||||
'title' => $domainTag['title'],
|
$domainTag = !empty($skillAsArray['domainTag']) ? $skillAsArray['domainTag'] : ['uid' => 0, 'title' => ''];
|
||||||
'uid' => $domainTag['uid'],
|
|
||||||
'skills' => array_filter($skills, function ($skill) use ($domainTag) {
|
if (!isset($result[$domainTag['uid']])) {
|
||||||
if (!isset($skill->toArray()['domainTag'])) {
|
$result[$domainTag['uid']] = [
|
||||||
return $domainTag['title'] === 'none';
|
'uid' => $domainTag['uid'],
|
||||||
}
|
'title' => $domainTag['title'],
|
||||||
return $skill->toArray()['domainTag']['title'] === $domainTag['title'];
|
'skills' => [],
|
||||||
})
|
];
|
||||||
];
|
}
|
||||||
|
$result[$domainTag['uid']]['skills'][] = $skill;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue