Zwischenstand
This commit is contained in:
60
Classes/Domain/Validator/RatingValidator.php
Normal file
60
Classes/Domain/Validator/RatingValidator.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the package thucke/th-rating.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Validator;
|
||||
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator;
|
||||
|
||||
/**
|
||||
* A validator for Ratings
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @scope singleton
|
||||
*/
|
||||
class RatingValidator extends AbstractValidator
|
||||
{
|
||||
/**
|
||||
* This validator always needs to be executed even if the given value is empty.
|
||||
* See AbstractValidator::validate()
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $acceptsEmptyValues = false;
|
||||
|
||||
/**
|
||||
* If the given Rating is valid
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating $rating
|
||||
* @noinspection PhpUnnecessaryFullyQualifiedNameInspection
|
||||
*/
|
||||
protected function isValid($rating): void
|
||||
{
|
||||
/** @noinspection NotOptimalIfConditionsInspection */
|
||||
if (!$this->isEmpty($rating) && $rating instanceof Rating) {
|
||||
$ratedobjectuid = $rating->getRatedobjectuid();
|
||||
if (empty($ratedobjectuid)) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate('error.validator.rating.ratedobjectuid', 'ThRating'),
|
||||
1283536994
|
||||
);
|
||||
}
|
||||
if (!$rating->getRatingobject() instanceof Ratingobject) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate('error.validator.rating.ratingobject', 'ThRating'),
|
||||
1283538549
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->addError(LocalizationUtility::translate('error.validator.rating.empty', 'ThRating'), 1568138421);
|
||||
}
|
||||
}
|
||||
}
|
54
Classes/Domain/Validator/RatingobjectValidator.php
Normal file
54
Classes/Domain/Validator/RatingobjectValidator.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the package thucke/th-rating.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Validator;
|
||||
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator;
|
||||
|
||||
/**
|
||||
* A validator for Ratingobjects
|
||||
*
|
||||
* @copyright Copyright belongs to the respective author
|
||||
* @scope singleton
|
||||
*/
|
||||
class RatingobjectValidator extends AbstractValidator
|
||||
{
|
||||
/**
|
||||
* If the given Ratingobject is valid
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject $ratingobject The ratingobject
|
||||
*/
|
||||
protected function isValid($ratingobject)
|
||||
{
|
||||
/** @var string $ratetable */
|
||||
$ratetable = $ratingobject->getRatetable();
|
||||
/** @var string $ratefield */
|
||||
$ratefield = $ratingobject->getRatefield();
|
||||
|
||||
if (empty($ratetable)) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate(
|
||||
'error.validator.ratingobject_table_extbase',
|
||||
'ThRating'
|
||||
),
|
||||
1283528638
|
||||
);
|
||||
}
|
||||
if (empty($ratefield)) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate(
|
||||
'error.validator.ratingobject_field_extbase',
|
||||
'ThRating'
|
||||
),
|
||||
1283536038
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
185
Classes/Domain/Validator/StepconfValidator.php
Normal file
185
Classes/Domain/Validator/StepconfValidator.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the package thucke/th-rating.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Validator;
|
||||
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepconfRepository;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepnameRepository;
|
||||
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator;
|
||||
|
||||
/**
|
||||
* A validator for Ratings
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @scope singleton
|
||||
*/
|
||||
class StepconfValidator extends AbstractValidator
|
||||
{
|
||||
/**
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepconfRepository
|
||||
*/
|
||||
protected $stepconfRepository;
|
||||
|
||||
/**
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepconfRepository $stepconfRepository
|
||||
*/
|
||||
public function injectStepconfRepository(StepconfRepository $stepconfRepository)
|
||||
{
|
||||
$this->stepconfRepository = $stepconfRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepnameRepository
|
||||
*/
|
||||
protected $stepnameRepository;
|
||||
|
||||
/**
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepnameRepository $stepnameRepository
|
||||
*/
|
||||
public function injectStepnameRepository(StepnameRepository $stepnameRepository)
|
||||
{
|
||||
$this->stepnameRepository = $stepnameRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the given step is valid
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf $stepconf
|
||||
* @throws InvalidQueryException
|
||||
*/
|
||||
protected function isValid($stepconf): void
|
||||
{
|
||||
/** @noinspection NotOptimalIfConditionsInspection */
|
||||
if (!$this->isEmpty($stepconf) && $stepconf instanceof Stepconf) {
|
||||
$this->checkRatingobject($stepconf);
|
||||
if (!$this->result->hasErrors()) {
|
||||
$this->checkSteporder($stepconf);
|
||||
}
|
||||
if (!$this->result->hasErrors()) {
|
||||
$this->validateStepnames($stepconf);
|
||||
}
|
||||
} else {
|
||||
$this->addError(LocalizationUtility::translate('error.validator.stepconf.empty', 'ThRating'), 1568139528);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A stepconf object must have a ratingobject
|
||||
* @param Stepconf $stepconf
|
||||
*/
|
||||
protected function checkRatingobject(Stepconf $stepconf): void
|
||||
{
|
||||
if (!$stepconf->getRatingobject() instanceof Ratingobject) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate('error.validator.stepconf.ratingobject', 'ThRating'),
|
||||
1284700846
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* At least a steporder value must be set and a positive integer ( >0 ) and valid regaing existing values
|
||||
* @param Stepconf $stepconf
|
||||
*/
|
||||
protected function checkSteporder(Stepconf $stepconf): void
|
||||
{
|
||||
$steporder = $stepconf->getSteporder();
|
||||
if (empty($steporder)) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate('error.validator.stepconf.steps', 'ThRating'),
|
||||
1284700903
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_int($stepconf->getSteporder()) || $stepconf->getSteporder() < 1) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate(
|
||||
'error.validator.stepconf.invalidSteporderNumber',
|
||||
'ThRating'
|
||||
),
|
||||
1368123953
|
||||
);
|
||||
}
|
||||
|
||||
//check if given steporder is valid (integer, maximum +1)
|
||||
/** @var object $maxSteporderStepconfobject */
|
||||
$maxSteporderStepconfobject = $this->stepconfRepository->findByRatingobject($stepconf->getRatingobject());
|
||||
$maxSteporder = $maxSteporderStepconfobject[$maxSteporderStepconfobject->count() - 1]->getSteporder();
|
||||
if ($stepconf->getSteporder() > $maxSteporder + 1) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate('error.validator.stepconf.maxSteporder', 'ThRating'),
|
||||
1368123970
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the given step is valid
|
||||
*
|
||||
* @param Stepconf $stepconf
|
||||
* @throws InvalidQueryException
|
||||
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
|
||||
*/
|
||||
protected function validateStepnames($stepconf): void
|
||||
{
|
||||
//check if a stepname is given that at least has the default language definition
|
||||
//TODO move to query on stepname repository
|
||||
$stepname = $stepconf->getStepname();
|
||||
$countNames = 0;
|
||||
if ($stepname instanceof ObjectStorage) {
|
||||
$countNames = $stepname->count();
|
||||
}
|
||||
if ($countNames != 0) {
|
||||
/** @var \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepname $firstStepname */
|
||||
$firstStepname = $stepname->current();
|
||||
|
||||
/** @var \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepname|object $defaultName */
|
||||
$defaultName = $this->stepnameRepository->findDefaultStepname($firstStepname);
|
||||
if (!$defaultName->isValid()) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate(
|
||||
'error.validator.stepconf.defaultStepname',
|
||||
'ThRating',
|
||||
[$firstStepname->getStepconf()->getUid()]
|
||||
),
|
||||
1384374165
|
||||
);
|
||||
} else {
|
||||
//Finally check on language consistency
|
||||
$checkConsistency = $this->stepnameRepository->checkConsistency($firstStepname);
|
||||
if ($checkConsistency['doubleLang']) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate(
|
||||
'error.validator.stepconf.doubleLangEntry',
|
||||
'ThRating',
|
||||
[$firstStepname->getStepconf()->getUid()]
|
||||
),
|
||||
1384374589
|
||||
);
|
||||
} elseif ($checkConsistency['existLang']) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate(
|
||||
'error.validator.stepconf.notExistingLanguage',
|
||||
'ThRating',
|
||||
[$firstStepname->getUid()]
|
||||
),
|
||||
1384374589
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
72
Classes/Domain/Validator/StepnameValidator.php
Normal file
72
Classes/Domain/Validator/StepnameValidator.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the package thucke/th-rating.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/** @noinspection PhpFullyQualifiedNameUsageInspection */
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Validator;
|
||||
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepname;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator;
|
||||
|
||||
/**
|
||||
* A validator for Ratings
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @scope singleton
|
||||
*/
|
||||
class StepnameValidator extends AbstractValidator
|
||||
{
|
||||
/**
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepnameRepository
|
||||
*/
|
||||
protected $stepnameRepository;
|
||||
|
||||
/**
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepnameRepository $stepnameRepository
|
||||
*/
|
||||
public function injectStepnameRepository(\WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepnameRepository $stepnameRepository)
|
||||
{
|
||||
$this->stepnameRepository = $stepnameRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the given step is valid
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepname $stepname
|
||||
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
|
||||
*/
|
||||
protected function isValid($stepname): void
|
||||
{
|
||||
//a stepname object must have a stepconf
|
||||
if (!$stepname->getStepconf() instanceof Stepconf) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate('error.validator.stepname.stepconf', 'ThRating'),
|
||||
1382895072
|
||||
);
|
||||
}
|
||||
|
||||
//check if given languagecode exists in website
|
||||
if (!$this->stepnameRepository->checkStepnameLanguage($stepname)) {
|
||||
$this->addError(LocalizationUtility::translate('error.validator.stepname.sysLang', 'ThRating'), 1382895089);
|
||||
}
|
||||
|
||||
//now check if entry for default language exists
|
||||
$langUid = $stepname->getSysLanguageUid();
|
||||
if (!empty($langUid)) {
|
||||
$defaultStepname = $this->stepnameRepository->findDefaultStepname($stepname);
|
||||
if (get_class($defaultStepname) !== Stepname::class || $this->validate($defaultStepname)->hasErrors()) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate('error.validator.stepname.defaultLang', 'ThRating'),
|
||||
1382895097
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
79
Classes/Domain/Validator/VoteValidator.php
Normal file
79
Classes/Domain/Validator/VoteValidator.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the package thucke/th-rating.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Validator;
|
||||
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Voter;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator;
|
||||
|
||||
/**
|
||||
* A validator for Votes
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @scope singleton
|
||||
*/
|
||||
class VoteValidator extends AbstractValidator
|
||||
{
|
||||
/**
|
||||
* This validator always needs to be executed even if the given value is empty.
|
||||
* See AbstractValidator::validate()
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $acceptsEmptyValues = false;
|
||||
|
||||
/**
|
||||
* If the given Vote is valid
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote $vote The vote
|
||||
*/
|
||||
protected function isValid($vote)
|
||||
{
|
||||
/** @noinspection NotOptimalIfConditionsInspection */
|
||||
if (!$this->isEmpty($vote) && $vote instanceof Vote) {
|
||||
//a vote object must have a vote
|
||||
if (!$vote->getVote() instanceof Stepconf) {
|
||||
$this->addError(LocalizationUtility::translate('error.validator.vote.vote', 'ThRating'), 1283537235);
|
||||
} else {
|
||||
//a vote must have a valid voter
|
||||
if (!$vote->getVoter() instanceof Voter) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate('error.validator.vote.voter', 'ThRating'),
|
||||
1283540684
|
||||
);
|
||||
}
|
||||
//check if the given vote is a valid step for this ratingobject
|
||||
if (!$vote->getRating()->getRatingobject()->getStepconfs()->contains($vote->getVote())) {
|
||||
$this->addError(
|
||||
LocalizationUtility::translate('error.validator.vote.stepconf', 'ThRating'),
|
||||
1283612492
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->addError(LocalizationUtility::translate('error.validator.vote.empty', 'ThRating'), 1568141014);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the given Vote is set
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote $vote The vote
|
||||
* @return bool
|
||||
*/
|
||||
public function isObjSet($vote)
|
||||
{
|
||||
$result = !$this->isEmpty($vote) && $vote instanceof Vote;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user