Skip to content

Commit

Permalink
Merge pull request #39 from thucke/TYPO3v8
Browse files Browse the repository at this point in the history
General refactoring for TYPO3 8.x and 9.x using PHPStorm #37
  • Loading branch information
thucke authored Jan 27, 2019
2 parents 66aa44a + 8aa59f9 commit 8edd33c
Show file tree
Hide file tree
Showing 67 changed files with 3,958 additions and 4,109 deletions.
2,158 changes: 1,072 additions & 1,086 deletions Classes/Controller/VoteController.php

Large diffs are not rendered by default.

59 changes: 30 additions & 29 deletions Classes/Domain/Model/Rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ public function injectExtensionHelperService( \Thucke\ThRating\Service\Extension
* @var array
*/
protected $settings;

/**
* Constructs a new rating object
* @return void
*/
public function __construct( \Thucke\ThRating\Domain\Model\Ratingobject $ratingobject = NULL, $ratedobjectuid=NULL ) {

/**
* Constructs a new rating object
* @param Ratingobject|null $ratingobject
* @param null $ratedobjectuid
*/
public function __construct( Ratingobject $ratingobject = NULL, $ratedobjectuid=NULL ) {
if ($ratingobject) $this->setRatingobject( $ratingobject );
if ($ratedobjectuid) $this->setRatedobjectuid( $ratedobjectuid );
$this->initializeObject();
Expand All @@ -149,10 +150,10 @@ public function initializeObject() {
/**
* Sets the ratingobject this rating is part of
*
* @param \Thucke\ThRating\Domain\Model\Ratingobject $ratingobject The Rating
* @param Ratingobject $ratingobject The Rating
* @return void
*/
public function setRatingobject(\Thucke\ThRating\Domain\Model\Ratingobject $ratingobject) {
public function setRatingobject(Ratingobject $ratingobject) {
$this->ratingobject = $ratingobject;
$this->setPid($ratingobject->getPid());
}
Expand Down Expand Up @@ -191,7 +192,7 @@ public function getRatedobjectuid() {
* @param \Thucke\ThRating\Domain\Model\Vote $vote
* @return void
*/
public function addVote(\Thucke\ThRating\Domain\Model\Vote $vote) {
public function addVote(Vote $vote) {
$this->votes->attach($vote);
$this->addCurrentrate($vote);
$this->extensionHelperService->persistRepository('Thucke\ThRating\Domain\Repository\VoteRepository', $vote);
Expand All @@ -204,7 +205,7 @@ public function addVote(\Thucke\ThRating\Domain\Model\Vote $vote) {
* @param \Thucke\ThRating\Domain\Model\Vote $newVote
* @return void
*/
public function updateVote(\Thucke\ThRating\Domain\Model\Vote $existingVote, \Thucke\ThRating\Domain\Model\Vote $newVote) {
public function updateVote(Vote $existingVote, Vote $newVote) {
$this->removeCurrentrate($existingVote);
$existingVote->setVote($newVote->getVote());
$this->addCurrentrate($existingVote);
Expand All @@ -217,7 +218,7 @@ public function updateVote(\Thucke\ThRating\Domain\Model\Vote $existingVote, \Th
* @param \Thucke\ThRating\Domain\Model\Vote $voteToRemove The vote to be removed
* @return void
*/
public function removeVote(\Thucke\ThRating\Domain\Model\Vote $voteToRemove) {
public function removeVote(Vote $voteToRemove) {
$this->removeCurrentrate($voteToRemove);
$this->votes->detach($voteToRemove);
}
Expand All @@ -235,7 +236,7 @@ public function removeAllVotes() {
/**
* Returns all votes in this rating
*
* @return TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Thucke\ThRating\Domain\Model\Vote>
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Thucke\ThRating\Domain\Model\Vote>
*/
public function getVotes() {
return clone $this->votes;
Expand All @@ -248,16 +249,18 @@ public function getVotes() {
* @return void
*/
public function checkCurrentrates() {
$currentratesDecoded['weightedVotes'] = array();
$currentratesDecoded['sumWeightedVotes'] = array();
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['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;
Expand All @@ -271,7 +274,7 @@ public function checkCurrentrates() {
* @param \Thucke\ThRating\Domain\Model\Vote $voting The vote to be added
* @return void
*/
public function addCurrentrate(\Thucke\ThRating\Domain\Model\Vote $voting) {
public function addCurrentrate(Vote $voting) {
if ( empty($this->currentrates) ) {
$this->checkCurrentrates(); //initialize entry
}
Expand All @@ -294,7 +297,7 @@ public function addCurrentrate(\Thucke\ThRating\Domain\Model\Vote $voting) {
* @param \Thucke\ThRating\Domain\Model\Vote $voting The vote to be removed
* @return void
*/
public function removeCurrentrate(\Thucke\ThRating\Domain\Model\Vote $voting) {
public function removeCurrentrate(Vote $voting) {
if ( empty($this->currentrates) ) {
$this->checkCurrentrates(); //initialize entry
}
Expand Down Expand Up @@ -333,7 +336,7 @@ public function getCurrentrates() {
$sumAllWeightedVotes = array_sum($currentratesDecoded['weightedVotes']);

//initialize array to handle missing stepconfs correctly
$currentPollDimensions = array();
$currentPollDimensions = [];

foreach ( $this->getRatingobject()->getStepconfs() as $stepConf ) {
if ( empty($sumAllWeightedVotes) ) {
Expand All @@ -345,12 +348,12 @@ public function getCurrentrates() {
}
}

return array ( 'currentrate' => $currentrate,
return ['currentrate' => $currentrate,
'weightedVotes' => $currentratesDecoded['weightedVotes'],
'sumWeightedVotes' => $currentratesDecoded['sumWeightedVotes'],
'anonymousVotes' => $currentratesDecoded['anonymousVotes'],
'currentPollDimensions' => $currentPollDimensions ,
'numAllVotes' => $numAllVotes);
'numAllVotes' => $numAllVotes];
}

/**
Expand All @@ -369,5 +372,3 @@ public function getCalculatedRate() {
}

}

?>
43 changes: 23 additions & 20 deletions Classes/Domain/Model/RatingImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ public function injectGifBuilder(\TYPO3\CMS\Frontend\Imaging\GifBuilder $gifBuil
}

/**
* Constructs a new rating object
* Constructs a new image object
*
* @param mixed $conf either an array consisting of GIFBUILDER typoscript or a plain string having the filename
* @return void
*/
public function __construct($conf = NULL) {
$this->initializeObject();
If (!empty($conf)) $this->setConf($conf);
If (!empty($conf)) {
$this->setConf($conf);
}
}

/**
Expand All @@ -81,7 +83,8 @@ public function __construct($conf = NULL) {
*/
public function initializeObject() {
if ( empty($this->gifBuilder) ) {
$this->injectGifBuilder(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder'));
/** @noinspection PhpParamsInspection */
$this->injectGifBuilder(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class));
}
}

Expand All @@ -93,12 +96,12 @@ public function initializeObject() {
*/
public function setConf($conf) {
switch (gettype($conf)) {
case "string":
case 'string':
$this->setImageFile($conf);
break;
case "array":
case 'array':
$this->conf = $conf;
$this->generateImage($this->conf);
$this->generateImage();
break;
default:
//TODO: Error message
Expand All @@ -110,7 +113,9 @@ public function setConf($conf) {
* @return array
*/
public function getConf() {
If (empty($this->conf)) return array();
If (empty($this->conf)) {
return [];
}
return $this->conf;
}
/**
Expand All @@ -126,9 +131,8 @@ public function setImageFile($imageFile) {
$this->isBuilderObject = false;
} else {
//clear path if given file is invalid
unset($this->imageFile);
unset($this->isBuilderObject);
//TODO: error handling
unset($this->imageFile, $this->isBuilderObject);
//TODO: error handling
}
}
/**
Expand All @@ -152,7 +156,7 @@ public function getImageFile($fullPath = false) {
*/
public function generateImage() {
If (!empty($this->conf)) {
$this->gifBuilder->start($this->getConf(), array());
$this->gifBuilder->start($this->getConf(), []);
$genImageFile = $this->gifBuilder->gifBuild();
If (!file_exists($genImageFile)) {
//TODO: error handling
Expand All @@ -161,10 +165,10 @@ public function generateImage() {
$this->setImageFile($genImageFile);
$this->isBuilderObject = true;
return true;
} else {
return false;
}
}

return false;
}

/**
* Returns the filename of the image
Expand All @@ -174,11 +178,11 @@ public function generateImage() {
*/
public function getImageDimensions() {
If ($this->isBuilderObject) {
list($width, $height) = $this->gifBuilder->getImageDimensions($this->imageFile);
[$width, $height] = $this->gifBuilder->getImageDimensions($this->imageFile);
} else {
list($width, $height) = getimagesize($this->getImageFile(true));
[$width, $height] = getimagesize($this->getImageFile(true));
}
return array('width'=>$width, 'height'=>$height, 'builderObject'=>$this->isBuilderObject);
return ['width'=>$width, 'height'=>$height, 'builderObject'=>$this->isBuilderObject];
}


Expand All @@ -187,8 +191,7 @@ public function getImageDimensions() {
*
* @return string
*/
public function __toString() {
return strval($this->getVote());
public function __toString() {
return $this->imageFile;
}
}
?>
25 changes: 6 additions & 19 deletions Classes/Domain/Model/Ratingobject.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,6 @@ class Ratingobject extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
*/
protected $ratings;

/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
*/
protected $objectManager;
/**
* @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
* @return void
*/
public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) {
$this->objectManager = $objectManager;
}

/**
* @var \Thucke\ThRating\Domain\Repository\StepconfRepository
*/
Expand Down Expand Up @@ -180,10 +168,10 @@ public function getRatefield() {
/**
* Adds a raiting to this object
*
* @param \Thucke\ThRating\Domain\Model\Rating $rating
* @param Rating $rating
* @return void
*/
public function addRating(\Thucke\ThRating\Domain\Model\Rating $rating) {
public function addRating(Rating $rating) {
$this->ratings->attach($rating);
$this->extensionHelperService->persistRepository('Thucke\ThRating\Domain\Repository\RatingRepository', $rating);
$this->extensionHelperService->clearDynamicCssFile();
Expand All @@ -192,10 +180,10 @@ public function addRating(\Thucke\ThRating\Domain\Model\Rating $rating) {
/**
* Remove a raiting from this object
*
* @param \Thucke\ThRating\Domain\Model\Rating $rating The rating to be removed
* @param Rating $rating The rating to be removed
* @return void
*/
public function removeRating(\Thucke\ThRating\Domain\Model\Rating $rating) {
public function removeRating(Rating $rating) {
$this->ratings->detach($rating);
}

Expand All @@ -211,10 +199,10 @@ public function removeAllRatings() {
/**
* Adds a stepconf to this object
*
* @param \Thucke\ThRating\Domain\Model\Stepconf $stepconf
* @param Stepconf $stepconf
* @return void
*/
public function addStepconf(\Thucke\ThRating\Domain\Model\Stepconf $stepconf) {
public function addStepconf(Stepconf $stepconf) {
If (!$this->stepconfRepository->existStepconf($stepconf)) {
$this->stepconfs->attach( $stepconf );
$this->extensionHelperService->persistRepository('Thucke\ThRating\Domain\Repository\StepconfRepository', $stepconf);
Expand Down Expand Up @@ -260,4 +248,3 @@ public function getRatings() {
return clone $this->ratings;
}
}
?>
Loading

0 comments on commit 8edd33c

Please sign in to comment.