From 901b7ab2be119d3ce5e4983caf5ccf2a30cdb1ac Mon Sep 17 00:00:00 2001 From: Markus Klein Date: Fri, 7 Jul 2023 09:28:13 +0200 Subject: [PATCH 1/6] [FEATURE] VH to group skills by domain --- .../ViewHelpers/SkillGroupingViewHelper.php | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Classes/ViewHelpers/SkillGroupingViewHelper.php diff --git a/Classes/ViewHelpers/SkillGroupingViewHelper.php b/Classes/ViewHelpers/SkillGroupingViewHelper.php new file mode 100644 index 0000000..884903e --- /dev/null +++ b/Classes/ViewHelpers/SkillGroupingViewHelper.php @@ -0,0 +1,93 @@ + + * {domainGroup.title}
+ * + * {skill.name}
+ *
+ * + */ +class SkillGroupingViewHelper extends AbstractViewHelper +{ + use CompileWithRenderStatic; + + protected $escapeOutput = false; + + public function initializeArguments() + { + $this->registerArgument('skills', 'array', 'An array of skills to group', false, []); + $this->registerArgument('skillSet', 'array', 'The skills of this skill set will be grouped', false, []); + $this->registerArgument('as', 'string', 'The name of the iteration variable', true); + } + + public static function renderStatic( + array $arguments, + Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ) { + $skills = $arguments['skills']; + $skillSet = $arguments['skillSet']; + $as = $arguments['as']; + + if ($skillSet) { + $groups = self::group($skillSet['skills']); + } else { + $groups = self::group($skills); + } + + $templateVariableContainer = $renderingContext->getVariableProvider(); + $output = ''; + foreach ($groups['values'] as $groups => $group) { + $templateVariableContainer->add($as, $group); + $output .= $renderChildrenClosure(); + $templateVariableContainer->remove($as); + } + return $output; + } + + protected static function group(array $skills): array + { + $result = [ + /* + * [ + * 'title' => 'Domain 1', + * 'skills' => [...skills] + * ] + */ + ]; + + // todo group skills based on domainTag|title + return $result; + } +} From ffde64c04b95be67795fd71dbce80d81f265b8e4 Mon Sep 17 00:00:00 2001 From: Markus Klein Date: Fri, 7 Jul 2023 09:43:28 +0200 Subject: [PATCH 2/6] [TASK] Use types from SD PHP API --- Classes/ViewHelpers/SkillGroupingViewHelper.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Classes/ViewHelpers/SkillGroupingViewHelper.php b/Classes/ViewHelpers/SkillGroupingViewHelper.php index 884903e..1701ace 100644 --- a/Classes/ViewHelpers/SkillGroupingViewHelper.php +++ b/Classes/ViewHelpers/SkillGroupingViewHelper.php @@ -22,8 +22,8 @@ namespace SkillDisplay\SkilldisplayContent\ViewHelpers; */ use Closure; -use Exception; -use SkillDisplay\PHPToolKit\Verification\Link; +use SkillDisplay\PHPToolKit\Entity\Skill; +use SkillDisplay\PHPToolKit\Entity\SkillSet; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; @@ -47,7 +47,7 @@ class SkillGroupingViewHelper extends AbstractViewHelper public function initializeArguments() { $this->registerArgument('skills', 'array', 'An array of skills to group', false, []); - $this->registerArgument('skillSet', 'array', 'The skills of this skill set will be grouped', false, []); + $this->registerArgument('skillSet', SkillSet::class, 'The skills of this skill set will be grouped', false, []); $this->registerArgument('as', 'string', 'The name of the iteration variable', true); } @@ -56,19 +56,21 @@ class SkillGroupingViewHelper extends AbstractViewHelper Closure $renderChildrenClosure, RenderingContextInterface $renderingContext ) { + /** @var Skill[] $skills */ $skills = $arguments['skills']; + /** @var SkillSet $skillSet */ $skillSet = $arguments['skillSet']; $as = $arguments['as']; if ($skillSet) { - $groups = self::group($skillSet['skills']); + $groups = self::group($skillSet->getSkills()); } else { $groups = self::group($skills); } $templateVariableContainer = $renderingContext->getVariableProvider(); $output = ''; - foreach ($groups['values'] as $groups => $group) { + foreach ($groups as $group) { $templateVariableContainer->add($as, $group); $output .= $renderChildrenClosure(); $templateVariableContainer->remove($as); @@ -76,6 +78,10 @@ class SkillGroupingViewHelper extends AbstractViewHelper return $output; } + /** + * @param Skill[] $skills + * @return array + */ protected static function group(array $skills): array { $result = [ From 60931303c0d68ffd32cd5d9e014cdc18f99badd1 Mon Sep 17 00:00:00 2001 From: julianzangl Date: Fri, 7 Jul 2023 12:02:21 +0200 Subject: [PATCH 3/6] [TASK] added ViewHelper for grouping skills by their domainTag --- .../ViewHelpers/SkillGroupingViewHelper.php | 35 ++++++++++++------- .../ContentElements/SkillDisplaySkillSet.html | 33 +++++++++++------ 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/Classes/ViewHelpers/SkillGroupingViewHelper.php b/Classes/ViewHelpers/SkillGroupingViewHelper.php index 1701ace..e96da75 100644 --- a/Classes/ViewHelpers/SkillGroupingViewHelper.php +++ b/Classes/ViewHelpers/SkillGroupingViewHelper.php @@ -36,7 +36,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; * * {skill.name}
*
- * + * */ class SkillGroupingViewHelper extends AbstractViewHelper { @@ -52,10 +52,11 @@ class SkillGroupingViewHelper extends AbstractViewHelper } public static function renderStatic( - array $arguments, - Closure $renderChildrenClosure, + array $arguments, + Closure $renderChildrenClosure, RenderingContextInterface $renderingContext - ) { + ) + { /** @var Skill[] $skills */ $skills = $arguments['skills']; /** @var SkillSet $skillSet */ @@ -84,16 +85,24 @@ class SkillGroupingViewHelper extends AbstractViewHelper */ protected static function group(array $skills): array { - $result = [ - /* - * [ - * 'title' => 'Domain 1', - * 'skills' => [...skills] - * ] - */ - ]; + $domainTags = []; + foreach ($skills as $skill) { + $domainTags[] = isset($skill->toArray()['domainTag']) ? $skill->toArray()['domainTag']['title'] : "none"; + } + $domainTags = array_unique($domainTags); - // todo group skills based on domainTag|title + $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/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 + })} + From 9076aa0067a8092afb07ed5a40609d750f166702 Mon Sep 17 00:00:00 2001 From: julianzangl Date: Fri, 7 Jul 2023 12:08:28 +0200 Subject: [PATCH 4/6] [BUGFIX] if condition is always true --- Classes/ViewHelpers/SkillGroupingViewHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/ViewHelpers/SkillGroupingViewHelper.php b/Classes/ViewHelpers/SkillGroupingViewHelper.php index e96da75..2a2fdf4 100644 --- a/Classes/ViewHelpers/SkillGroupingViewHelper.php +++ b/Classes/ViewHelpers/SkillGroupingViewHelper.php @@ -47,7 +47,7 @@ class SkillGroupingViewHelper extends AbstractViewHelper public function initializeArguments() { $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', 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); } @@ -59,7 +59,7 @@ class SkillGroupingViewHelper extends AbstractViewHelper { /** @var Skill[] $skills */ $skills = $arguments['skills']; - /** @var SkillSet $skillSet */ + /** @var SkillSet|null $skillSet */ $skillSet = $arguments['skillSet']; $as = $arguments['as']; From eb432ddf9447c291b0dc3b7d9e81a66832451103 Mon Sep 17 00:00:00 2001 From: julianzangl Date: Fri, 7 Jul 2023 12:12:53 +0200 Subject: [PATCH 5/6] [BUGFIX] changed return types of initializeArguments functions --- Classes/ViewHelpers/SkillGroupingViewHelper.php | 2 +- Classes/ViewHelpers/VerificationViewHelper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/ViewHelpers/SkillGroupingViewHelper.php b/Classes/ViewHelpers/SkillGroupingViewHelper.php index 2a2fdf4..9720c34 100644 --- a/Classes/ViewHelpers/SkillGroupingViewHelper.php +++ b/Classes/ViewHelpers/SkillGroupingViewHelper.php @@ -44,7 +44,7 @@ class SkillGroupingViewHelper extends AbstractViewHelper protected $escapeOutput = false; - public function initializeArguments() + 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'); 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.'); From 0f0b7e3145ae5492ba9c42cb91e74ec0a0ac8994 Mon Sep 17 00:00:00 2001 From: julianzangl Date: Fri, 7 Jul 2023 12:16:23 +0200 Subject: [PATCH 6/6] [BUGFIX] formatting issues --- Classes/ViewHelpers/SkillGroupingViewHelper.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Classes/ViewHelpers/SkillGroupingViewHelper.php b/Classes/ViewHelpers/SkillGroupingViewHelper.php index 9720c34..a5540c2 100644 --- a/Classes/ViewHelpers/SkillGroupingViewHelper.php +++ b/Classes/ViewHelpers/SkillGroupingViewHelper.php @@ -52,11 +52,10 @@ class SkillGroupingViewHelper extends AbstractViewHelper } public static function renderStatic( - array $arguments, - Closure $renderChildrenClosure, + array $arguments, + Closure $renderChildrenClosure, RenderingContextInterface $renderingContext - ) - { + ) { /** @var Skill[] $skills */ $skills = $arguments['skills']; /** @var SkillSet|null $skillSet */