diff --git a/Classes/ViewHelpers/SkillGroupingViewHelper.php b/Classes/ViewHelpers/SkillGroupingViewHelper.php new file mode 100644 index 0000000..a5540c2 --- /dev/null +++ b/Classes/ViewHelpers/SkillGroupingViewHelper.php @@ -0,0 +1,107 @@ + + * {domainGroup.title}
+ * + * {skill.name}
+ *
+ * + */ +class SkillGroupingViewHelper extends AbstractViewHelper +{ + use CompileWithRenderStatic; + + protected $escapeOutput = false; + + public function initializeArguments(): void + { + $this->registerArgument('skills', 'array', 'An array of skills to group', false, []); + $this->registerArgument('skillSet', SkillSet::class, 'The skills of this skill set will be grouped'); + $this->registerArgument('as', 'string', 'The name of the iteration variable', true); + } + + public static function renderStatic( + array $arguments, + Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ) { + /** @var Skill[] $skills */ + $skills = $arguments['skills']; + /** @var SkillSet|null $skillSet */ + $skillSet = $arguments['skillSet']; + $as = $arguments['as']; + + if ($skillSet) { + $groups = self::group($skillSet->getSkills()); + } else { + $groups = self::group($skills); + } + + $templateVariableContainer = $renderingContext->getVariableProvider(); + $output = ''; + foreach ($groups as $group) { + $templateVariableContainer->add($as, $group); + $output .= $renderChildrenClosure(); + $templateVariableContainer->remove($as); + } + return $output; + } + + /** + * @param Skill[] $skills + * @return array + */ + protected static function group(array $skills): array + { + $domainTags = []; + foreach ($skills as $skill) { + $domainTags[] = isset($skill->toArray()['domainTag']) ? $skill->toArray()['domainTag']['title'] : "none"; + } + $domainTags = array_unique($domainTags); + + $result = []; + foreach ($domainTags as $domainTag) { + $result[] = [ + 'title' => $domainTag, + 'skills' => array_filter($skills, function (Skill $skill) use ($domainTag) { + if (!isset($skill->toArray()['domainTag'])) { + return $domainTag === "none"; + } + return $skill->toArray()['domainTag']['title'] === $domainTag; + }) + ]; + } + return $result; + } +} diff --git a/Classes/ViewHelpers/VerificationViewHelper.php b/Classes/ViewHelpers/VerificationViewHelper.php index 46f1778..6878855 100644 --- a/Classes/ViewHelpers/VerificationViewHelper.php +++ b/Classes/ViewHelpers/VerificationViewHelper.php @@ -36,7 +36,7 @@ abstract class VerificationViewHelper extends AbstractViewHelper protected $escapeOutput = false; - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('skill', 'integer', 'ID of the Skill.'); $this->registerArgument('skillSet', 'integer', 'ID of the SkillSet.'); diff --git a/Resources/Private/Templates/ContentElements/SkillDisplaySkillSet.html b/Resources/Private/Templates/ContentElements/SkillDisplaySkillSet.html index bb1e3c0..28d1736 100644 --- a/Resources/Private/Templates/ContentElements/SkillDisplaySkillSet.html +++ b/Resources/Private/Templates/ContentElements/SkillDisplaySkillSet.html @@ -1,14 +1,25 @@ - - {f:render(partial: 'VerificationBox', arguments: { - title: skillSet.name, - count: '{skillSet.skills -> f:count()}', - detailUrl: 'https://my.skilldisplay.eu/skillset/{skillSet.id}', - brandLogoUrl: skillSet.brand.logoPublicUrl, - verificationUrl: '{sd:verification.url(skillSet: skillSet.id, campaign: data.skilldisplay_campaign)}', - description: skillSet.description - })} + xmlns:sd="http://typo3.org/ns/SkillDisplay/SkilldisplayContent/ViewHelpers" + data-namespace-typo3-fluid="true"> + + + {domainGroup.title}
+ + {skill.title}
+
+
+ +
+ + + {f:render(partial: 'VerificationBox', arguments: { + title: skillSet.name, + count: '{skillSet.skills -> f:count()}', + detailUrl: 'https://my.skilldisplay.eu/skillset/{skillSet.id}', + brandLogoUrl: skillSet.brand.logoPublicUrl, + verificationUrl: '{sd:verification.url(skillSet: skillSet.id, campaign: data.skilldisplay_campaign)}', + description: skillSet.description + })} +