Skip to content

Commit 0f33ca0

Browse files
authored
Merge pull request #42 from evoWeb/feature/suggest-tag-for-session
[FEATURE] Suggest tag for session
2 parents 3703164 + 9f7bd9f commit 0f33ca0

10 files changed

Lines changed: 127 additions & 6 deletions

File tree

Classes/Domain/Factory/SuggestFormFactory.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Evoweb\Sessionplaner\Domain\Factory;
1313

1414
use Evoweb\Sessionplaner\Domain\Finisher\SuggestFormFinisher;
15+
use Evoweb\Sessionplaner\Domain\Repository\TagRepository;
1516
use Evoweb\Sessionplaner\Enum\SessionLevelEnum;
1617
use Evoweb\Sessionplaner\Enum\SessionRequestTypeEnum;
1718
use Evoweb\Sessionplaner\Enum\SessionTypeEnum;
@@ -35,12 +36,16 @@ class SuggestFormFactory extends AbstractFormFactory
3536

3637
protected ConfigurationManagerInterface $configurationManager;
3738

39+
protected TagRepository $tagRepository;
40+
3841
public function __construct(
3942
ConfigurationManagerInterface $configurationManager,
40-
ConfigurationService $formConfigurationService
43+
ConfigurationService $formConfigurationService,
44+
TagRepository $tagRepository
4145
) {
4246
$this->configurationManager = $configurationManager;
4347
$this->formConfigurationService = $formConfigurationService;
48+
$this->tagRepository = $tagRepository;
4449
}
4550

4651
public function build(array $configuration, string $prototypeName = null): FormDefinition
@@ -141,6 +146,30 @@ public function build(array $configuration, string $prototypeName = null): FormD
141146
$typeField->setProperty('options', $typeFieldOptions);
142147
}
143148

149+
if ($settings['suggest']['fields']['tag']['enable']) {
150+
$tags = $this->tagRepository->findBy(['suggestFormOption' => true]);
151+
if ($tags->current()) {
152+
/** @var GenericFormElement $tagField */
153+
$tagField = $sessionInformation->createElement('tag', 'SingleSelect');
154+
$tagField->setLabel($this->getLocalizedLabel($settings['suggest']['fields']['tag']['label']));
155+
$tagField->setProperty(
156+
'elementDescription',
157+
$this->getLocalizedLabel($settings['suggest']['fields']['tag']['description'])
158+
);
159+
$tagField->addValidator(GeneralUtility::makeInstance(NotEmptyValidator::class));
160+
$tagFieldOptions = [];
161+
foreach ($tags as $tag) {
162+
$tagFieldOptions[$tag->getUid()] = $tag->getLabel();
163+
}
164+
$prependOptionLabel = ' ';
165+
if (!empty($settings['suggest']['fields']['tag']['prependOptionLabel'])) {
166+
$prependOptionLabel = $this->getLocalizedLabel($settings['suggest']['fields']['tag']['prependOptionLabel']);
167+
}
168+
$tagField->setProperty('prependOptionLabel', $prependOptionLabel);
169+
$tagField->setProperty('options', $tagFieldOptions);
170+
}
171+
}
172+
144173
/** @var GenericFormElement $titleField */
145174
$titleField = $sessionInformation->createElement('title', 'Text');
146175
$titleField->setLabel($this->getLocalizedLabel($settings['suggest']['fields']['title']['label']));

Classes/Domain/Finisher/SuggestFormFinisher.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Evoweb\Sessionplaner\Domain\Model\Speaker;
1616
use Evoweb\Sessionplaner\Domain\Repository\SessionRepository;
1717
use Evoweb\Sessionplaner\Domain\Repository\SpeakerRepository;
18+
use Evoweb\Sessionplaner\Domain\Repository\TagRepository;
1819
use TYPO3\CMS\Core\Utility\GeneralUtility;
1920
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
2021
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
@@ -28,6 +29,8 @@ class SuggestFormFinisher extends AbstractFinisher
2829

2930
protected ?SessionRepository $sessionRepository = null;
3031

32+
protected ?TagRepository $tagRepository = null;
33+
3134
protected ?PersistenceManagerInterface $persistenceManager = null;
3235

3336
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
@@ -45,6 +48,11 @@ public function injectSessionRepository(SessionRepository $sessionRepository)
4548
$this->sessionRepository = $sessionRepository;
4649
}
4750

51+
public function injectTagRepository(TagRepository $tagRepository)
52+
{
53+
$this->tagRepository = $tagRepository;
54+
}
55+
4856
public function injectPersistenceManager(PersistenceManagerInterface $persistenceManager)
4957
{
5058
$this->persistenceManager = $persistenceManager;
@@ -84,6 +92,9 @@ protected function executeInternal()
8492
if (!empty($data['type'])) {
8593
$session->setType($data['type']);
8694
}
95+
if (!empty($data['tag']) && null !== ($tag = $this->tagRepository->findByUid($data['tag']))) {
96+
$session->addTag($tag);
97+
}
8798
if (!empty($data['level'])) {
8899
$session->setLevel($data['level']);
89100
}

Classes/Domain/Model/Session.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ public function getTags(): ObjectStorage
327327
return $this->tags;
328328
}
329329

330+
public function addTag(Tag $tag): void
331+
{
332+
$this->tags->attach($tag);
333+
}
334+
335+
public function removeTag(Tag $tag): void
336+
{
337+
$this->tags->detach($tag);
338+
}
339+
330340
public function toArray(): array
331341
{
332342
$data = [];

Classes/Domain/Model/Tag.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class Tag extends AbstractEntity
3636
*/
3737
protected string $slug = '';
3838

39+
/**
40+
* @var bool
41+
*/
42+
protected bool $suggestFormOption = false;
43+
3944
/**
4045
* @var ObjectStorage<Session>
4146
* @TYPO3\CMS\Extbase\Annotation\ORM\Lazy
@@ -92,6 +97,16 @@ public function getSlug(): string
9297
return $this->slug;
9398
}
9499

100+
public function setSuggestFormOption(bool $suggestFormOption): void
101+
{
102+
$this->suggestFormOption = $suggestFormOption;
103+
}
104+
105+
public function isSuggestFormOption(): bool
106+
{
107+
return $this->suggestFormOption;
108+
}
109+
95110
public function setSessions(ObjectStorage $sessions)
96111
{
97112
$this->sessions = $sessions;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the package evoweb/sessionplaner.
7+
*
8+
* For the full copyright and license information, please read the
9+
* LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace Evoweb\Sessionplaner\Domain\Repository;
13+
14+
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
15+
use TYPO3\CMS\Extbase\Persistence\Repository;
16+
17+
class TagRepository extends Repository
18+
{
19+
protected $defaultOrderings = [
20+
'label' => QueryInterface::ORDER_ASCENDING
21+
];
22+
}

Configuration/TCA/tx_sessionplaner_domain_model_tag.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@
9999
'default' => ''
100100
]
101101
],
102+
'suggest_form_option' => [
103+
'exclude' => false,
104+
'label' => $languageFile . 'tx_sessionplaner_domain_model_tag-suggest_form_option',
105+
'config' => [
106+
'type' => 'check',
107+
'renderType' => 'checkboxToggle',
108+
'items' => [
109+
[
110+
'label' => '',
111+
'invertStateDisplay' => false,
112+
],
113+
],
114+
'behaviour' => [
115+
'allowLanguageSynchronization' => true,
116+
],
117+
],
118+
],
102119
'sessions' => [
103120
'exclude' => false,
104121
'label' => $languageFile . 'tx_sessionplaner_domain_model_tag-sessions',
@@ -120,6 +137,7 @@
120137
path_segment,
121138
color,
122139
description,
140+
suggest_form_option,
123141
sessions
124142
'
125143
]

Configuration/TypoScript/setup.typoscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ plugin.tx_sessionplaner {
6464
description = LLL:EXT:sessionplaner/Resources/Private/Language/locallang.xlf:form.type.description
6565
prependOptionLabel =
6666
}
67+
tag {
68+
enable = 0
69+
label = LLL:EXT:sessionplaner/Resources/Private/Language/locallang.xlf:form.tag
70+
description = LLL:EXT:sessionplaner/Resources/Private/Language/locallang.xlf:form.tag.description
71+
prependOptionLabel =
72+
}
6773
title {
6874
label = LLL:EXT:sessionplaner/Resources/Private/Language/locallang.xlf:form.title
6975
description = LLL:EXT:sessionplaner/Resources/Private/Language/locallang.xlf:form.title.description

Resources/Private/Language/locallang.xlf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@
223223
<trans-unit id="form.type.description">
224224
<source>What type of session to you want to offer?</source>
225225
</trans-unit>
226+
<trans-unit id="form.tag">
227+
<source>Tag</source>
228+
</trans-unit>
229+
<trans-unit id="form.tag.description">
230+
<source>What tag would you like to add to your session?</source>
231+
</trans-unit>
226232
<trans-unit id="form.level">
227233
<source>Level</source>
228234
</trans-unit>

Resources/Private/Language/locallang_tca.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@
211211
<trans-unit id="tx_sessionplaner_domain_model_tag-path_segment" xml:space="preserve">
212212
<source>Path segment</source>
213213
</trans-unit>
214+
<trans-unit id="tx_sessionplaner_domain_model_tag-suggest_form_option" xml:space="preserve">
215+
<source>Use as option in suggest form</source>
216+
</trans-unit>
214217
<trans-unit id="tx_sessionplaner_domain_model_tag-sessions" xml:space="preserve">
215218
<source>Sessions</source>
216219
</trans-unit>

ext_tables.sql

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ CREATE TABLE tx_sessionplaner_domain_model_session
7373
#
7474
CREATE TABLE tx_sessionplaner_domain_model_tag
7575
(
76-
label varchar(255) DEFAULT '' NOT NULL,
77-
color varchar(255) DEFAULT '' NOT NULL,
78-
description text,
79-
path_segment varchar(2048),
80-
sessions int(11) unsigned DEFAULT '0' NOT NULL
76+
label varchar(255) DEFAULT '' NOT NULL,
77+
color varchar(255) DEFAULT '' NOT NULL,
78+
description text,
79+
path_segment varchar(2048),
80+
suggest_form_option smallint unsigned DEFAULT '0' NOT NULL,
81+
sessions int(11) unsigned DEFAULT '0' NOT NULL
8182
);
8283

8384
#

0 commit comments

Comments
 (0)