mirror of
https://github.com/SkillDisplay/TYPO3ContentElements.git
synced 2024-11-14 00:26:09 +01:00
Merge pull request #15 from SkillDisplay/skill-grouping-vh
Skill grouping vh
This commit is contained in:
commit
e2b7c980e5
3 changed files with 130 additions and 12 deletions
107
Classes/ViewHelpers/SkillGroupingViewHelper.php
Normal file
107
Classes/ViewHelpers/SkillGroupingViewHelper.php
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SkillDisplay\SkilldisplayContent\ViewHelpers;
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
use Closure;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Usage:
|
||||
*
|
||||
* <sd:skillGrouping skillSet="{skillSet}" as="domainGroup">
|
||||
* {domainGroup.title}<br />
|
||||
* <f:for each="{domainGroup.skills}" as="skill">
|
||||
* {skill.name}<br />
|
||||
* </f:for>
|
||||
* </sd:skillGrouping>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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.');
|
||||
|
|
|
@ -1,14 +1,25 @@
|
|||
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
|
||||
xmlns:sd="http://typo3.org/ns/SkillDisplay/SkilldisplayContent/ViewHelpers"
|
||||
data-namespace-typo3-fluid="true">
|
||||
<f:for each="{skillSets}" as="skillSet">
|
||||
{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">
|
||||
<f:for each="{skillSets}" as="skillSet">
|
||||
<sd:skillGrouping skillSet="{skillSet}" as="domainGroup">
|
||||
<b>{domainGroup.title}</b><br/>
|
||||
<f:for each="{domainGroup.skills}" as="skill">
|
||||
{skill.title}<br/>
|
||||
</f:for>
|
||||
</sd:skillGrouping>
|
||||
</f:for>
|
||||
|
||||
<hr>
|
||||
|
||||
<f:for each="{skillSets}" as="skillSet">
|
||||
{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
|
||||
})}
|
||||
</f:for>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue