Merge remote-tracking branch 'origin/fluid-template-skill-grouping'

This commit is contained in:
Markus Klein 2023-07-21 10:51:47 +02:00
commit b6e99f84ed

View file

@ -84,21 +84,30 @@ class SkillGroupingViewHelper extends AbstractViewHelper
*/ */
protected static function group(array $skills): array protected static function group(array $skills): array
{ {
$domainTags = []; $domainTagsWithId = [];
foreach ($skills as $skill) { foreach ($skills as $skill) {
$domainTags[] = isset($skill->toArray()['domainTag']) ? $skill->toArray()['domainTag']['title'] : "none"; if (!isset($skill->toArray()['domainTag'])) {
$domainTagsWithId[] = [
'uid' => 0,
'title' => 'none'
];
continue;
} }
$domainTags = array_unique($domainTags); $domainTagsWithId[] = $skill->toArray()['domainTag'];
}
//remove items with duplicate title
$domainTagsWithId = array_map('unserialize', array_unique(array_map('serialize', $domainTagsWithId)));
$result = []; $result = [];
foreach ($domainTags as $domainTag) { foreach ($domainTagsWithId as $domainTag) {
$result[] = [ $result[] = [
'title' => $domainTag, 'title' => $domainTag['title'],
'skills' => array_filter($skills, function (Skill $skill) use ($domainTag) { 'uid' => $domainTag['uid'],
'skills' => array_filter($skills, function ($skill) use ($domainTag) {
if (!isset($skill->toArray()['domainTag'])) { if (!isset($skill->toArray()['domainTag'])) {
return $domainTag === "none"; return $domainTag['title'] === 'none';
} }
return $skill->toArray()['domainTag']['title'] === $domainTag; return $skill->toArray()['domainTag']['title'] === $domainTag['title'];
}) })
]; ];
} }