Zwischenstand
This commit is contained in:
parent
fde2759722
commit
ce6b9e38dc
51
.editorconfig
Normal file
51
.editorconfig
Normal file
@ -0,0 +1,51 @@
|
||||
# EditorConfig is awesome: http://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# TS/JS-Files
|
||||
[*.{ts,js}]
|
||||
indent_size = 2
|
||||
|
||||
# JSON-Files
|
||||
[*.json]
|
||||
indent_style = tab
|
||||
|
||||
# ReST-Files
|
||||
[*.rst]
|
||||
indent_size = 3
|
||||
max_line_length = 80
|
||||
|
||||
# YAML-Files
|
||||
[*.{yaml,yml}]
|
||||
indent_size = 2
|
||||
|
||||
# package.json
|
||||
[package.json]
|
||||
indent_size = 2
|
||||
|
||||
# TypoScript
|
||||
[*.{typoscript,tsconfig}]
|
||||
indent_size = 2
|
||||
|
||||
# XLF-Files
|
||||
[*.xlf]
|
||||
indent_style = tab
|
||||
|
||||
# SQL-Files
|
||||
[*.sql]
|
||||
indent_style = tab
|
||||
indent_size = 2
|
||||
|
||||
# .htaccess
|
||||
[{_.htaccess,.htaccess}]
|
||||
indent_style = tab
|
@ -7,10 +7,10 @@
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace WapplerSystems\BookmarkPages\Controller;
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Controller;
|
||||
|
||||
use WapplerSystems\BookmarkPages\Model\Bookmark;
|
||||
use WapplerSystems\BookmarkPages\Model\Bookmarks;
|
||||
use WapplerSystems\BookmarksLikesRatings\Model\Bookmark;
|
||||
use WapplerSystems\BookmarksLikesRatings\Model\Bookmarks;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
|
||||
|
1316
Classes/Controller/VoteController.php
Normal file
1316
Classes/Controller/VoteController.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,7 @@
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace WapplerSystems\BookmarkPages\Model;
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Model;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
@ -47,7 +47,7 @@ class Bookmark
|
||||
* @param null $pid page id
|
||||
* @param null $parameter
|
||||
*/
|
||||
public function __construct($url, $title=null, $pid=null, $parameter=null)
|
||||
public function __construct($url, $title = null, $pid = null, $parameter = null)
|
||||
{
|
||||
if (is_array($url)) {
|
||||
$this->id = $url['id'];
|
||||
@ -223,7 +223,7 @@ class Bookmark
|
||||
*/
|
||||
protected static function getCurrentPageTitle()
|
||||
{
|
||||
return self::getFrontend()->altPageTitle? self::getFrontend()->altPageTitle : self::getFrontend()->page['title'];
|
||||
return self::getFrontend()->altPageTitle ? self::getFrontend()->altPageTitle : self::getFrontend()->page['title'];
|
||||
}
|
||||
|
||||
/**
|
@ -7,7 +7,7 @@
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace WapplerSystems\BookmarkPages\Model;
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Model;
|
||||
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
410
Classes/Domain/Model/Rating.php
Normal file
410
Classes/Domain/Model/Rating.php
Normal file
@ -0,0 +1,410 @@
|
||||
<?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\Model;
|
||||
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Repository\VoteRepository;
|
||||
use WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService;
|
||||
use WapplerSystems\BookmarksLikesRatings\Service\JsonService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
|
||||
/**
|
||||
* Model for object rating
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
|
||||
* @entity
|
||||
*/
|
||||
class Rating extends AbstractEntity
|
||||
{
|
||||
//TODO check deleted referenced records
|
||||
|
||||
/**
|
||||
* @Extbase\Validate("\WapplerSystems\BookmarksLikesRatings\Domain\Validator\RatingobjectValidator")
|
||||
* @Extbase\Validate("NotEmpty")
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject
|
||||
*/
|
||||
protected $ratingobject;
|
||||
|
||||
/**
|
||||
* The ratings uid of this object
|
||||
*
|
||||
* @Extbase\Validate("NumberRange", options={"minimum": 1})
|
||||
* @Extbase\Validate("NotEmpty")
|
||||
* @var int
|
||||
*/
|
||||
protected $ratedobjectuid;
|
||||
|
||||
/**
|
||||
* The ratings of this object
|
||||
*
|
||||
* @Extbase\ORM\Lazy
|
||||
* @Extbase\ORM\Cascade("remove")
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote>
|
||||
*/
|
||||
protected $votes;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
/**
|
||||
* @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
|
||||
*/
|
||||
/** @noinspection PhpUnused */
|
||||
public function injectObjectManager(ObjectManagerInterface $objectManager)
|
||||
{
|
||||
$this->objectManager = $objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Service\JsonService
|
||||
*/
|
||||
protected $jsonService;
|
||||
/**
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Service\JsonService $jsonService
|
||||
*/
|
||||
public function injectJsonService(JsonService $jsonService)
|
||||
{
|
||||
$this->jsonService = $jsonService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Repository\VoteRepository
|
||||
*/
|
||||
protected $voteRepository;
|
||||
/**
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Repository\VoteRepository $voteRepository
|
||||
*/
|
||||
public function injectVoteRepository(VoteRepository $voteRepository)
|
||||
{
|
||||
$this->voteRepository = $voteRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService
|
||||
*/
|
||||
protected $extensionHelperService;
|
||||
|
||||
/**
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService $extensionHelperService
|
||||
*/
|
||||
/** @noinspection PhpUnused */
|
||||
public function injectExtensionHelperService(ExtensionHelperService $extensionHelperService)
|
||||
{
|
||||
$this->extensionHelperService = $extensionHelperService;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current calculated rates
|
||||
*
|
||||
* Redundant information to enhance performance in displaying calculated information
|
||||
* This is a JSON encoded string with the following keys
|
||||
* - votecounts(1...n) vote counts of the specific ratingstep
|
||||
* It be updated every time a vote is created, changed or deleted.
|
||||
* Specific handling must be defined when ratingsteps are added or removed or stepweights are changed
|
||||
* Calculation of ratings:
|
||||
* currentrate = ( sum of all ( stepweight(n) * votecounts(n) ) ) / number of all votes
|
||||
* currentwidth = round (currentrate * 100 / number of ratingsteps, 1)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $currentrates;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* Constructs a new rating object
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject|null $ratingobject
|
||||
* @param int|null $ratedobjectuid
|
||||
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
|
||||
*/
|
||||
public function __construct(Ratingobject $ratingobject = null, $ratedobjectuid = null)
|
||||
{
|
||||
if ($ratingobject) {
|
||||
$this->setRatingobject($ratingobject);
|
||||
}
|
||||
if ($ratedobjectuid) {
|
||||
$this->setRatedobjectuid($ratedobjectuid);
|
||||
}
|
||||
$this->initializeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new rating object
|
||||
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
|
||||
*/
|
||||
public function initializeObject()
|
||||
{
|
||||
if (empty($this->objectManager)) {
|
||||
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||
}
|
||||
$this->settings = $this->objectManager
|
||||
->get(ConfigurationManager::class)
|
||||
->getConfiguration('Settings', 'thRating', 'pi1');
|
||||
|
||||
//Initialize vote storage if rating is new
|
||||
if (!is_object($this->votes)) {
|
||||
$this->votes = new ObjectStorage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ratingobject this rating is part of
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject $ratingobject The Rating
|
||||
*/
|
||||
public function setRatingobject(Ratingobject $ratingobject)
|
||||
{
|
||||
$this->ratingobject = $ratingobject;
|
||||
$this->setPid($ratingobject->getPid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ratingobject this rating is part of
|
||||
*
|
||||
* @return \WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject The ratingobject this rating is part of
|
||||
*/
|
||||
public function getRatingobject(): Ratingobject
|
||||
{
|
||||
return $this->ratingobject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rating object uid
|
||||
*
|
||||
* @param int $ratedobjectuid
|
||||
*/
|
||||
public function setRatedobjectuid($ratedobjectuid)
|
||||
{
|
||||
$this->ratedobjectuid = $ratedobjectuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rating object uid
|
||||
*
|
||||
* @return int Rating object row uid field value
|
||||
*/
|
||||
public function getRatedobjectuid()
|
||||
{
|
||||
return $this->ratedobjectuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a vote to this rating
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote $vote
|
||||
*/
|
||||
public function addVote(Vote $vote)
|
||||
{
|
||||
$this->votes->attach($vote);
|
||||
$this->addCurrentrate($vote);
|
||||
$this->extensionHelperService->persistRepository(VoteRepository::class, $vote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing vote to this rating
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote $existingVote
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote $newVote
|
||||
*/
|
||||
public function updateVote(Vote $existingVote, Vote $newVote)
|
||||
{
|
||||
$this->removeCurrentrate($existingVote);
|
||||
$existingVote->setVote($newVote->getVote());
|
||||
$this->addCurrentrate($existingVote);
|
||||
$this->extensionHelperService->persistRepository(VoteRepository::class, $existingVote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a vote from this rating
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote $voteToRemove The vote to be removed
|
||||
*/
|
||||
/** @noinspection PhpUnused */
|
||||
public function removeVote(Vote $voteToRemove)
|
||||
{
|
||||
$this->removeCurrentrate($voteToRemove);
|
||||
$this->votes->detach($voteToRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all votes from this rating
|
||||
*/
|
||||
/** @noinspection PhpUnused */
|
||||
public function removeAllVotes()
|
||||
{
|
||||
$this->votes = new ObjectStorage();
|
||||
unset($this->currentrates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all votes in this rating
|
||||
*
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote>
|
||||
*/
|
||||
public function getVotes()
|
||||
{
|
||||
return clone $this->votes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks all votes of this rating and sets currentrates accordingly
|
||||
*
|
||||
* This method is used for maintenance to assure consistency
|
||||
*/
|
||||
public function checkCurrentrates()
|
||||
{
|
||||
$currentratesDecoded['weightedVotes'] = [];
|
||||
$currentratesDecoded['sumWeightedVotes'] = [];
|
||||
$numAllVotes = 0;
|
||||
$numAllAnonymousVotes = 0;
|
||||
foreach ($this->getRatingobject()->getStepconfs() as $stepConf) {
|
||||
$stepOrder = $stepConf->getSteporder();
|
||||
$voteCount = $this->voteRepository->countByMatchingRatingAndVote($this, $stepConf);
|
||||
$anonymousCount = $this->voteRepository->countAnonymousByMatchingRatingAndVote(
|
||||
$this,
|
||||
$stepConf,
|
||||
$this->settings['mapAnonymous']
|
||||
);
|
||||
$currentratesDecoded['weightedVotes'][$stepOrder] = $voteCount * $stepConf->getStepweight();
|
||||
$currentratesDecoded['sumWeightedVotes'][$stepOrder] =
|
||||
$currentratesDecoded['weightedVotes'][$stepOrder] * $stepOrder;
|
||||
$numAllVotes += $voteCount;
|
||||
$numAllAnonymousVotes += $anonymousCount;
|
||||
}
|
||||
$currentratesDecoded['numAllVotes'] = $numAllVotes;
|
||||
$currentratesDecoded['anonymousVotes'] = $numAllAnonymousVotes;
|
||||
$this->currentrates = $this->jsonService->encodeToJson($currentratesDecoded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a vote to the calculations of this rating
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote $voting The vote to be added
|
||||
*/
|
||||
public function addCurrentrate(Vote $voting)
|
||||
{
|
||||
if (empty($this->currentrates)) {
|
||||
$this->checkCurrentrates(); //initialize entry
|
||||
}
|
||||
$currentratesDecoded = $this->jsonService->decodeJsonToArray($this->currentrates);
|
||||
$currentratesDecoded['numAllVotes']++;
|
||||
if ($voting->isAnonymous()) {
|
||||
$currentratesDecoded['anonymousVotes']++;
|
||||
}
|
||||
$votingStep = $voting->getVote();
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$votingSteporder = $votingStep->getSteporder();
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$votingStepweight = $votingStep->getStepweight();
|
||||
$currentratesDecoded['weightedVotes'][$votingSteporder] += $votingStepweight;
|
||||
$currentratesDecoded['sumWeightedVotes'][$votingSteporder] += $votingStepweight * $votingSteporder;
|
||||
$this->currentrates = $this->jsonService->encodeToJson($currentratesDecoded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a vote to the calculations of this rating
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote $voting The vote to be removed
|
||||
*/
|
||||
public function removeCurrentrate(Vote $voting)
|
||||
{
|
||||
if (empty($this->currentrates)) {
|
||||
$this->checkCurrentrates(); //initialize entry
|
||||
}
|
||||
$currentratesDecoded = $this->jsonService->decodeJsonToArray($this->currentrates);
|
||||
$currentratesDecoded['numAllVotes']--;
|
||||
if ($voting->isAnonymous()) {
|
||||
$currentratesDecoded['anonymousVotes']--;
|
||||
}
|
||||
$votingStep = $voting->getVote();
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$votingSteporder = $votingStep->getSteporder();
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$votingStepweight = $votingStep->getStepweight();
|
||||
$currentratesDecoded['weightedVotes'][$votingSteporder] -= $votingStepweight;
|
||||
$currentratesDecoded['sumWeightedVotes'][$votingSteporder] -= $votingStepweight * $votingSteporder;
|
||||
$this->currentrates = $this->jsonService->encodeToJson($currentratesDecoded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the calculated rating
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrentrates(): array
|
||||
{
|
||||
$currentratesDecoded = $this->jsonService->decodeJsonToArray($this->currentrates);
|
||||
if (empty($currentratesDecoded['numAllVotes'])) {
|
||||
$this->checkCurrentrates();
|
||||
$currentratesDecoded = $this->jsonService->decodeJsonToArray($this->currentrates);
|
||||
}
|
||||
$numAllVotes = $currentratesDecoded['numAllVotes'];
|
||||
if (!empty($numAllVotes)) {
|
||||
$currentrate = array_sum($currentratesDecoded['sumWeightedVotes']) / $numAllVotes;
|
||||
} else {
|
||||
$currentrate = 0;
|
||||
$numAllVotes = 0;
|
||||
}
|
||||
|
||||
$sumAllWeightedVotes = array_sum($currentratesDecoded['weightedVotes']);
|
||||
|
||||
//initialize array to handle missing stepconfs correctly
|
||||
$currentPollDimensions = [];
|
||||
|
||||
foreach ($this->getRatingobject()->getStepconfs() as $stepConf) {
|
||||
if (empty($sumAllWeightedVotes)) {
|
||||
//set current polling styles to zero percent and prevent division by zero error in lower formula
|
||||
$currentPollDimensions[$stepConf->getStepOrder()]['pctValue'] = 0;
|
||||
} else {
|
||||
/* calculate current polling styles -> holds a percent value for usage in CSS
|
||||
to display polling relations */
|
||||
$currentPollDimensions[$stepConf->getStepOrder()]['pctValue'] =
|
||||
round(
|
||||
($currentratesDecoded['weightedVotes'][$stepConf->getStepOrder()] * 100) /
|
||||
$sumAllWeightedVotes,
|
||||
1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return ['currentrate' => $currentrate,
|
||||
'weightedVotes' => $currentratesDecoded['weightedVotes'],
|
||||
'sumWeightedVotes' => $currentratesDecoded['sumWeightedVotes'],
|
||||
'anonymousVotes' => $currentratesDecoded['anonymousVotes'],
|
||||
'currentPollDimensions' => $currentPollDimensions,
|
||||
'numAllVotes' => $numAllVotes, ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the calculated rating in percent
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCalculatedRate(): int
|
||||
{
|
||||
$currentrate = $this->getCurrentrates();
|
||||
if (!empty($currentrate['weightedVotes'])) {
|
||||
$calculatedRate = round(($currentrate['currentrate'] * 100) / count($currentrate['weightedVotes']), 1);
|
||||
} else {
|
||||
$calculatedRate = 0;
|
||||
}
|
||||
return $calculatedRate;
|
||||
}
|
||||
}
|
196
Classes/Domain/Model/RatingImage.php
Normal file
196
Classes/Domain/Model/RatingImage.php
Normal file
@ -0,0 +1,196 @@
|
||||
<?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\Model;
|
||||
|
||||
use TYPO3\CMS\Core\Core\Environment;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
use TYPO3\CMS\Frontend\Imaging\GifBuilder;
|
||||
|
||||
/**
|
||||
* Model for rating votes
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
|
||||
* @entity
|
||||
*/
|
||||
class RatingImage extends AbstractEntity
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $isBuilderObject = false;
|
||||
/**
|
||||
* The filename of the final image
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $imageFile;
|
||||
/**
|
||||
* The typoscript image configuration array
|
||||
* Only the top level node ['GIFBUILDER'] will be used for building the image
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $conf;
|
||||
/**
|
||||
* @var GifBuilder
|
||||
*/
|
||||
protected $gifBuilder;
|
||||
|
||||
/**
|
||||
* @param GifBuilder $gifBuilder
|
||||
*/
|
||||
public function injectGifBuilder(GifBuilder $gifBuilder)
|
||||
{
|
||||
$this->gifBuilder = $gifBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new image object
|
||||
*
|
||||
* @param mixed $conf either an array consisting of GIFBUILDER typoscript or a plain string having the filename
|
||||
*/
|
||||
public function __construct($conf = null)
|
||||
{
|
||||
$this->initializeObject();
|
||||
if (!empty($conf)) {
|
||||
$this->setConf($conf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the new vote object
|
||||
*/
|
||||
public function initializeObject()
|
||||
{
|
||||
if (empty($this->gifBuilder)) {
|
||||
$this->injectGifBuilder(GeneralUtility::makeInstance(GifBuilder::class));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the typoscript configuration for the GIFBUILDER object
|
||||
*
|
||||
* @param mixed $conf either an array consisting of GIFBUILDER typoscript or a plain string having the filename
|
||||
*/
|
||||
public function setConf($conf)
|
||||
{
|
||||
switch (gettype($conf)) {
|
||||
case 'string':
|
||||
$this->setImageFile($conf);
|
||||
break;
|
||||
case 'array':
|
||||
$this->conf = $conf;
|
||||
$this->generateImage();
|
||||
break;
|
||||
default:
|
||||
//TODO: Error message
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current typoscript configuration of the GIFBUILDER object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConf(): array
|
||||
{
|
||||
if (empty($this->conf)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filename of the image
|
||||
*
|
||||
* @param string $imageFile
|
||||
*/
|
||||
public function setImageFile($imageFile)
|
||||
{
|
||||
$fullImagePath = Environment::getPublicPath() . '/' . $imageFile;
|
||||
if (file_exists($fullImagePath)) {
|
||||
$this->imageFile = $imageFile;
|
||||
$this->isBuilderObject = false;
|
||||
} else {
|
||||
//clear path if given file is invalid
|
||||
unset($this->imageFile, $this->isBuilderObject);
|
||||
//TODO: error handling
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename of the image
|
||||
*
|
||||
* @param mixed $fullPath
|
||||
* @return string
|
||||
*/
|
||||
public function getImageFile($fullPath = false)
|
||||
{
|
||||
$checkedFile = $this->gifBuilder->checkFile($this->imageFile);
|
||||
if (empty($checkedFile)) {
|
||||
//clear image if file doe not exist
|
||||
$this->setImageFile('xxx');
|
||||
}
|
||||
return $fullPath ? Environment::getPublicPath() . '/' . $this->imageFile : $this->imageFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the image using the given typoscript
|
||||
*
|
||||
* @return bool The result; true if the given the image has been created successfully; otherwise false
|
||||
*/
|
||||
public function generateImage()
|
||||
{
|
||||
if (!empty($this->conf)) {
|
||||
$this->gifBuilder->start($this->getConf(), []);
|
||||
$genImageFile = $this->gifBuilder->gifBuild();
|
||||
if (!file_exists($genImageFile)) {
|
||||
//TODO: error handling
|
||||
return false;
|
||||
}
|
||||
$this->setImageFile($genImageFile);
|
||||
$this->isBuilderObject = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename of the image
|
||||
*
|
||||
* @var bool switch if absolute path should be returned
|
||||
* @return array('width','height')
|
||||
*/
|
||||
public function getImageDimensions()
|
||||
{
|
||||
if ($this->isBuilderObject) {
|
||||
[$width, $height] = $this->gifBuilder->getImageDimensions($this->imageFile);
|
||||
} else {
|
||||
[$width, $height] = getimagesize($this->getImageFile(true));
|
||||
}
|
||||
|
||||
return ['width' => $width, 'height' => $height, 'builderObject' => $this->isBuilderObject];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to use Object as plain string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->imageFile;
|
||||
}
|
||||
}
|
257
Classes/Domain/Model/Ratingobject.php
Normal file
257
Classes/Domain/Model/Ratingobject.php
Normal file
@ -0,0 +1,257 @@
|
||||
<?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\Model;
|
||||
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Repository\RatingRepository;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepconfRepository;
|
||||
use WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService;
|
||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
|
||||
/**
|
||||
* Aggregate object for rating of content objects
|
||||
*
|
||||
* @version $Id:$
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
|
||||
* @entity
|
||||
*/
|
||||
class Ratingobject extends AbstractEntity
|
||||
{
|
||||
/**
|
||||
* Table name of the cObj
|
||||
* Defaults to Typo3 tablename of pages
|
||||
*
|
||||
* @Extbase\Validate("StringLength", options={"minimum": 3})
|
||||
* @Extbase\Validate("StringLength", options={"maximum": 60})
|
||||
* @Extbase\Validate("NotEmpty")
|
||||
* @var string
|
||||
*/
|
||||
protected $ratetable;
|
||||
|
||||
/**
|
||||
* Fieldname within the table of the cObj
|
||||
* Defaults to the field 'uid'
|
||||
*
|
||||
* @Extbase\Validate("StringLength", options={"minimum": 3})
|
||||
* @Extbase\Validate("StringLength", options={"maximum": 60})
|
||||
* @Extbase\Validate("NotEmpty")
|
||||
* @var string
|
||||
*/
|
||||
protected $ratefield;
|
||||
|
||||
/**
|
||||
* The stepconfs of this object
|
||||
*
|
||||
* @Extbase\ORM\Lazy
|
||||
* @Extbase\ORM\Cascade("remove")
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf>
|
||||
*/
|
||||
protected $stepconfs;
|
||||
|
||||
/**
|
||||
* The ratings of this object
|
||||
*
|
||||
* @Extbase\ORM\Lazy
|
||||
* @Extbase\ORM\Cascade("remove")
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating>
|
||||
*/
|
||||
protected $ratings;
|
||||
|
||||
/**
|
||||
* @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\Service\ExtensionHelperService
|
||||
*/
|
||||
protected $extensionHelperService;
|
||||
|
||||
/**
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService $extensionHelperService
|
||||
*/
|
||||
/** @noinspection PhpUnused */
|
||||
public function injectExtensionHelperService(ExtensionHelperService $extensionHelperService)
|
||||
{
|
||||
$this->extensionHelperService = $extensionHelperService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new rating object
|
||||
* @param string $ratetable The rating objects table name
|
||||
* @param string $ratefield The rating objects field name
|
||||
* @Extbase\Validate("StringLength", options={"minimum": 3}, param="ratetable")
|
||||
* @Extbase\Validate("StringLength", options={"maximum": 60}, param="ratetable")
|
||||
* @Extbase\Validate("StringLength", options={"minimum": 3}, param="ratefield")
|
||||
* @Extbase\Validate("StringLength", options={"maximum": 60}, param="ratefield")
|
||||
*/
|
||||
public function __construct($ratetable = null, $ratefield = null)
|
||||
{
|
||||
if ($ratetable) {
|
||||
$this->setRatetable($ratetable);
|
||||
}
|
||||
if ($ratefield) {
|
||||
$this->setRatefield($ratefield);
|
||||
}
|
||||
$this->initializeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new ratingobject
|
||||
*/
|
||||
public function initializeObject()
|
||||
{
|
||||
//Initialize rating storage if ratingobject is new
|
||||
if (!is_object($this->ratings)) {
|
||||
$this->ratings = new ObjectStorage();
|
||||
}
|
||||
//Initialize stepconf storage if ratingobject is new
|
||||
if (!is_object($this->stepconfs)) {
|
||||
$this->stepconfs = new ObjectStorage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rating table name
|
||||
*
|
||||
* @param string $ratetable
|
||||
*/
|
||||
public function setRatetable($ratetable)
|
||||
{
|
||||
$this->ratetable = $ratetable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rating table name
|
||||
*
|
||||
* @return string Rating object table name
|
||||
*/
|
||||
public function getRatetable()
|
||||
{
|
||||
return $this->ratetable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rating field name
|
||||
*
|
||||
* @param string $ratefield
|
||||
*/
|
||||
public function setRatefield($ratefield)
|
||||
{
|
||||
$this->ratefield = $ratefield;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rating field name
|
||||
*
|
||||
* @return string Rating object field name
|
||||
*/
|
||||
public function getRatefield()
|
||||
{
|
||||
return $this->ratefield;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a rating to this object
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating $rating
|
||||
*/
|
||||
/** @noinspection PhpUnused */
|
||||
public function addRating(Rating $rating)
|
||||
{
|
||||
$this->ratings->attach($rating);
|
||||
$this->extensionHelperService->persistRepository(RatingRepository::class, $rating);
|
||||
$this->extensionHelperService->clearDynamicCssFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a rating from this object
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating $rating The rating to be removed
|
||||
*/
|
||||
public function removeRating(Rating $rating): void
|
||||
{
|
||||
$this->ratings->detach($rating);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all ratings from this object
|
||||
*/
|
||||
public function removeAllRatings(): void
|
||||
{
|
||||
$this->ratings = new ObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a stepconf to this object
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf $stepconf
|
||||
*/
|
||||
public function addStepconf(Stepconf $stepconf): void
|
||||
{
|
||||
if (!$this->stepconfRepository->existStepconf($stepconf)) {
|
||||
$this->stepconfs->attach($stepconf);
|
||||
$this->extensionHelperService->persistRepository(StepconfRepository::class, $stepconf);
|
||||
$this->extensionHelperService->clearDynamicCssFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all ratings of this ratingobject
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf> $stepconfs
|
||||
* The step configurations for this ratingobject
|
||||
*/
|
||||
public function setStepconfs(ObjectStorage $stepconfs)
|
||||
{
|
||||
$this->stepconfs = $stepconfs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all ratings in this object
|
||||
*
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf>
|
||||
*/
|
||||
public function getStepconfs()
|
||||
{
|
||||
return clone $this->stepconfs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all ratings of this ratingobject
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating> $ratings
|
||||
* The ratings of the organization
|
||||
*/
|
||||
public function setRatings(ObjectStorage $ratings)
|
||||
{
|
||||
$this->ratings = $ratings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all ratings in this object
|
||||
*
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating>
|
||||
*/
|
||||
public function getRatings()
|
||||
{
|
||||
return clone $this->ratings;
|
||||
}
|
||||
}
|
271
Classes/Domain/Model/Stepconf.php
Normal file
271
Classes/Domain/Model/Stepconf.php
Normal file
@ -0,0 +1,271 @@
|
||||
<?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\Model;
|
||||
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepconfRepository;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepnameRepository;
|
||||
use WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService;
|
||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
||||
use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
|
||||
/**
|
||||
* Model for ratingstep configuration
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
|
||||
* @entity
|
||||
*/
|
||||
class Stepconf extends AbstractEntity
|
||||
{
|
||||
/**
|
||||
* @Extbase\Validate("\WapplerSystems\BookmarksLikesRatings\Domain\Validator\RatingobjectValidator")
|
||||
* @Extbase\Validate("NotEmpty")
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject
|
||||
*/
|
||||
protected $ratingobject;
|
||||
|
||||
/**
|
||||
* The order of this config entry
|
||||
*
|
||||
* @Extbase\Validate("NumberRange", options={"minimum": 1})
|
||||
* @Extbase\Validate("NotEmpty")
|
||||
* @var int discrete order of ratingsteps
|
||||
*/
|
||||
protected $steporder;
|
||||
|
||||
/**
|
||||
* The weight of this config entry
|
||||
*
|
||||
* @Extbase\Validate("Integer")
|
||||
* @Extbase\Validate("NumberRange", options={"minimum": 1})
|
||||
* @var int default is 1 which is equal weight
|
||||
*/
|
||||
protected $stepweight;
|
||||
|
||||
/**
|
||||
* The value of this config entry
|
||||
*
|
||||
* @Extbase\ORM\Lazy
|
||||
* @Extbase\ORM\Cascade("remove")
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepname
|
||||
*/
|
||||
protected $stepname;
|
||||
|
||||
/**
|
||||
* The ratings of this object
|
||||
*
|
||||
* @Extbase\ORM\Lazy
|
||||
* @Extbase\ORM\Cascade("remove")
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote>
|
||||
*/
|
||||
protected $votes;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
|
||||
*/
|
||||
public function injectObjectManager(ObjectManagerInterface $objectManager)
|
||||
{
|
||||
$this->objectManager = $objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepnameRepository $stepnameRepository
|
||||
*/
|
||||
protected $stepnameRepository;
|
||||
|
||||
/**
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Repository\StepnameRepository $stepnameRepository
|
||||
*/
|
||||
public function injectStepnameRepository(StepnameRepository $stepnameRepository)
|
||||
{
|
||||
$this->stepnameRepository = $stepnameRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService
|
||||
*/
|
||||
protected $extensionHelperService;
|
||||
|
||||
/**
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService $extensionHelperService
|
||||
*/
|
||||
public function injectExtensionHelperService(ExtensionHelperService $extensionHelperService)
|
||||
{
|
||||
$this->extensionHelperService = $extensionHelperService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new stepconfig object
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject|null $ratingobject
|
||||
* @param int|null $steporder
|
||||
*/
|
||||
public function __construct(Ratingobject $ratingobject = null, $steporder = null)
|
||||
{
|
||||
if ($ratingobject) {
|
||||
$this->setRatingobject($ratingobject);
|
||||
}
|
||||
if ($steporder) {
|
||||
$this->setSteporder($steporder);
|
||||
}
|
||||
$this->initializeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new stepconf object
|
||||
*/
|
||||
public function initializeObject()
|
||||
{
|
||||
//Initialize vote storage if rating is new
|
||||
if (!is_object($this->votes)) {
|
||||
$this->votes = new ObjectStorage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ratingobject this rating is part of
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject $ratingobject The Rating
|
||||
*/
|
||||
public function setRatingobject(Ratingobject $ratingobject)
|
||||
{
|
||||
$this->ratingobject = $ratingobject;
|
||||
$this->setPid($ratingobject->getPid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ratingobject this rating is part of
|
||||
*
|
||||
* @return \WapplerSystems\BookmarksLikesRatings\Domain\Model\Ratingobject|null
|
||||
*/
|
||||
public function getRatingobject()
|
||||
{
|
||||
return $this->ratingobject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the stepconfig order
|
||||
*
|
||||
* @param int $steporder
|
||||
*/
|
||||
public function setSteporder($steporder)
|
||||
{
|
||||
$this->steporder = $steporder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stepconfig order
|
||||
*
|
||||
* @return int stepconfig position
|
||||
*/
|
||||
public function getSteporder(): int
|
||||
{
|
||||
return $this->steporder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the stepconfig value
|
||||
*
|
||||
* @param int $stepweight
|
||||
*/
|
||||
public function setStepweight($stepweight)
|
||||
{
|
||||
$this->stepweight = $stepweight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stepconfig value
|
||||
* If not set steporder is copied
|
||||
*
|
||||
* @return int Stepconfig value
|
||||
*/
|
||||
public function getStepweight()
|
||||
{
|
||||
empty($this->stepweight) && $this->stepweight = $this->steporder;
|
||||
return $this->stepweight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a localized stepname to this stepconf
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepname $stepname
|
||||
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
|
||||
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
|
||||
* @return bool
|
||||
*/
|
||||
public function addStepname(Stepname $stepname): bool
|
||||
{
|
||||
$success = true;
|
||||
$stepname->setStepconf($this);
|
||||
if (!$this->stepnameRepository->existStepname($stepname)) {
|
||||
$defaultLanguageObject = $this->stepnameRepository->findDefaultStepname($stepname);
|
||||
if (is_object($defaultLanguageObject)) {
|
||||
//handle localization if an entry for the default language exists
|
||||
$stepname->setL18nParent($defaultLanguageObject->getUid());
|
||||
}
|
||||
$this->stepnameRepository->add($stepname);
|
||||
$this->extensionHelperService->persistRepository(StepnameRepository::class, $stepname);
|
||||
$stepname->getStepconf()->getStepname();
|
||||
$this->extensionHelperService->persistRepository(StepconfRepository::class, $this);
|
||||
$this->extensionHelperService->clearDynamicCssFile();
|
||||
$this->stepname = $stepname;
|
||||
} else {
|
||||
//warning - existing stepname entry for a language will not be overwritten
|
||||
$success = false;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the localized stepname object of this stepconf
|
||||
*
|
||||
* @return \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepname|null
|
||||
*/
|
||||
public function getStepname(): ?Stepname
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
if ($this->stepname instanceof LazyLoadingProxy) {
|
||||
$this->stepname = $this->stepname->_loadRealInstance();
|
||||
}
|
||||
return $this->stepname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all votes in this rating
|
||||
*
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote>
|
||||
*/
|
||||
public function getVotes()
|
||||
{
|
||||
return clone $this->votes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to use Object as plain string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$stepnameText = $this->getStepname();
|
||||
if (!$stepnameText) {
|
||||
$stepnameText = $this->getSteporder();
|
||||
}
|
||||
return (string)$stepnameText;
|
||||
}
|
||||
}
|
158
Classes/Domain/Model/Stepname.php
Normal file
158
Classes/Domain/Model/Stepname.php
Normal file
@ -0,0 +1,158 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
/*
|
||||
* 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\Model;
|
||||
|
||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
|
||||
/**
|
||||
* Model for ratingstep configuration names
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
|
||||
* @entity
|
||||
*/
|
||||
class Stepname extends AbstractEntity
|
||||
{
|
||||
/**
|
||||
* @Extbase\Validate("\WapplerSystems\BookmarksLikesRatings\Domain\Validator\StepconfValidator")
|
||||
* @Extbase\Validate("NotEmpty")
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf
|
||||
*/
|
||||
protected $stepconf;
|
||||
|
||||
/**
|
||||
* The name of this config entry
|
||||
*
|
||||
* @var string Name or description to display
|
||||
*/
|
||||
protected $stepname;
|
||||
|
||||
/**
|
||||
* Localization entry
|
||||
* workaround to help avoiding bug in Typo 4.7 handling localized objects
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $l18nParent;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $sysLanguageUid;
|
||||
|
||||
/**
|
||||
* Sets the stepconf this rating is part of
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf $stepconf The Rating
|
||||
*/
|
||||
public function setStepconf(Stepconf $stepconf): void
|
||||
{
|
||||
$this->stepconf = $stepconf;
|
||||
$this->setPid($stepconf->getPid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stepconf this rating is part of
|
||||
*
|
||||
* @return \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf The stepconf this rating is part of
|
||||
*/
|
||||
public function getStepconf(): Stepconf
|
||||
{
|
||||
return $this->stepconf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the stepconfig name
|
||||
*
|
||||
* @param string $stepname
|
||||
*/
|
||||
public function setStepname($stepname): void
|
||||
{
|
||||
$this->stepname = $stepname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stepconfig name
|
||||
* If not set stepweight is copied
|
||||
*
|
||||
* @return string Stepconfig name
|
||||
*/
|
||||
public function getStepname(): string
|
||||
{
|
||||
$value = $this->stepname;
|
||||
if (stripos($value, 'LLL:') === 0) {
|
||||
$value = 'stepnames.' . substr($value, 4);
|
||||
$value = LocalizationUtility::translate($value, 'ThRating');
|
||||
}
|
||||
if (empty($value)) {
|
||||
$value = (string)$this->getStepconf()->getSteporder();
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
/** @noinspection PhpUnused */
|
||||
public function getL18nParent(): int
|
||||
{
|
||||
return $this->l18nParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $l18nParent
|
||||
*/
|
||||
public function setL18nParent($l18nParent): void
|
||||
{
|
||||
$this->l18nParent = $l18nParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sys language
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSysLanguageUid(): int
|
||||
{
|
||||
return $this->_languageUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sys language
|
||||
*
|
||||
* @param int $sysLanguageUid language uid
|
||||
*/
|
||||
public function setSysLanguageUid($sysLanguageUid): void
|
||||
{
|
||||
$this->_languageUid = $sysLanguageUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(): bool
|
||||
{
|
||||
return !empty($this->stepconf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to use Object as plain string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->getStepname();
|
||||
}
|
||||
}
|
242
Classes/Domain/Model/Vote.php
Normal file
242
Classes/Domain/Model/Vote.php
Normal file
@ -0,0 +1,242 @@
|
||||
<?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\Model;
|
||||
|
||||
use WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
||||
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
||||
|
||||
/**
|
||||
* Model for rating votes
|
||||
*
|
||||
* @copyright Copyright belongs to the respective authors
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
|
||||
* @entity
|
||||
*/
|
||||
class Vote extends AbstractEntity
|
||||
{
|
||||
/**
|
||||
* @Extbase\Validate("\WapplerSystems\BookmarksLikesRatings\Domain\Validator\RatingValidator")
|
||||
* @Extbase\Validate("NotEmpty")
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating
|
||||
*/
|
||||
protected $rating;
|
||||
|
||||
/**
|
||||
* The voter of this object
|
||||
*
|
||||
* @Extbase\Validate("NotEmpty")
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Model\Voter
|
||||
*/
|
||||
protected $voter;
|
||||
|
||||
/**
|
||||
* The actual voting of this object
|
||||
*
|
||||
* @Extbase\Validate("\WapplerSystems\BookmarksLikesRatings\Domain\Validator\StepconfValidator")
|
||||
* @Extbase\Validate("NotEmpty")
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf
|
||||
*/
|
||||
protected $vote;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Core\Log\Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
|
||||
*/
|
||||
public function injectObjectManager(ObjectManagerInterface $objectManager)
|
||||
{
|
||||
$this->objectManager = $objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService
|
||||
*/
|
||||
protected $extensionHelperService;
|
||||
/**
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService $extensionHelperService
|
||||
*/
|
||||
public function injectExtensionHelperService(ExtensionHelperService $extensionHelperService): void
|
||||
{
|
||||
$this->extensionHelperService = $extensionHelperService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new rating object
|
||||
*
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating|null $rating
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Voter|null $voter
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf|null $vote
|
||||
* @throws InvalidConfigurationTypeException
|
||||
*/
|
||||
/** @noinspection PhpUnused */
|
||||
public function __construct(
|
||||
Rating $rating = null,
|
||||
Voter $voter = null,
|
||||
Stepconf $vote = null
|
||||
) {
|
||||
if ($rating) {
|
||||
$this->setRating($rating);
|
||||
}
|
||||
if ($voter) {
|
||||
$this->setVoter($voter);
|
||||
}
|
||||
if ($vote) {
|
||||
$this->setVote($vote);
|
||||
}
|
||||
$this->initializeObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the new vote object
|
||||
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
|
||||
*/
|
||||
public function initializeObject()
|
||||
{
|
||||
if (empty($this->objectManager)) {
|
||||
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||
}
|
||||
if (empty($this->extensionHelperService)) {
|
||||
$this->extensionHelperService = GeneralUtility::makeInstance(ExtensionHelperService::class);
|
||||
}
|
||||
$this->logger = $this->extensionHelperService->getLogger(__CLASS__);
|
||||
$this->settings = $this->objectManager->get(ConfigurationManager::class)->getConfiguration(
|
||||
'Settings',
|
||||
'thRating',
|
||||
'pi1'
|
||||
);
|
||||
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this,get_class($this).' initializeObject');
|
||||
}
|
||||
|
||||
/**
|