|
7 | 7 | use In2code\Powermail\Domain\Repository\MailRepository; |
8 | 8 | use In2code\Powermail\Utility\FrontendUtility; |
9 | 9 | use In2code\Powermail\Utility\ObjectUtility; |
10 | | -use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; |
11 | | -use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; |
12 | 10 | use TYPO3\CMS\Extbase\Object\Exception; |
13 | | -use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException; |
14 | 11 |
|
15 | 12 | /** |
16 | 13 | * Class UniqueValidator |
| 14 | + * @noinspection PhpUnused |
17 | 15 | */ |
18 | 16 | class UniqueValidator extends AbstractValidator |
19 | 17 | { |
20 | | - |
21 | 18 | /** |
22 | | - * Validation of given Params |
23 | | - * |
24 | 19 | * @param Mail $mail |
25 | 20 | * @return bool |
26 | 21 | * @throws Exception |
27 | | - * @throws ExtensionConfigurationExtensionNotConfiguredException |
28 | | - * @throws ExtensionConfigurationPathDoesNotExistException |
29 | | - * @throws InvalidQueryException |
30 | 22 | */ |
31 | 23 | public function isValid($mail) |
32 | 24 | { |
33 | | - if (empty($this->settings['validation']['unique'])) { |
34 | | - return $this->isValidState(); |
35 | | - } |
36 | | - foreach ($this->settings['validation']['unique'] as $marker => $amount) { |
37 | | - if ((int)$amount === 0) { |
38 | | - continue; |
39 | | - } |
40 | | - foreach ($mail->getAnswers() as $answer) { |
41 | | - /** @var Answer $answer */ |
42 | | - if ($answer->getField()->getMarker() === $marker) { |
43 | | - $mailRepository = ObjectUtility::getObjectManager()->get(MailRepository::class); |
44 | | - $numberOfMails = $mailRepository->findByMarkerValueForm( |
45 | | - $marker, |
46 | | - $answer->getValue(), |
47 | | - $mail->getForm(), |
48 | | - FrontendUtility::getStoragePage($this->getStoragePid()) |
49 | | - )->count(); |
| 25 | + if (!empty($this->settings['validation']['unique'])) { |
| 26 | + foreach ($this->settings['validation']['unique'] as $marker => $amount) { |
| 27 | + if ($amount > 0) { |
| 28 | + foreach ($mail->getAnswers() as $answer) { |
| 29 | + /** @var Answer $answer */ |
| 30 | + if ($answer->getField()->getMarker() === $marker) { |
| 31 | + /** @var MailRepository $mailRepository */ |
| 32 | + $mailRepository = ObjectUtility::getObjectManager()->get(MailRepository::class); |
| 33 | + $numberOfMails = $mailRepository->findByMarkerValueForm( |
| 34 | + $marker, |
| 35 | + $answer->getValue(), |
| 36 | + $mail->getForm(), |
| 37 | + FrontendUtility::getStoragePage($this->getStoragePid()) |
| 38 | + )->count(); |
50 | 39 |
|
51 | | - if ($amount <= $numberOfMails) { |
52 | | - $this->setErrorAndMessage($answer->getField(), 'unique'); |
| 40 | + if ($amount <= $numberOfMails) { |
| 41 | + $this->setErrorAndMessage($answer->getField(), 'unique'); |
| 42 | + } |
| 43 | + } |
53 | 44 | } |
54 | 45 | } |
55 | 46 | } |
56 | 47 | } |
57 | | - |
58 | 48 | return $this->isValidState(); |
59 | 49 | } |
60 | 50 |
|
|
0 commit comments