Zwischenstand
This commit is contained in:
130
Classes/Domain/Repository/BookmarkRepository.php
Normal file
130
Classes/Domain/Repository/BookmarkRepository.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Repository;
|
||||
|
||||
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote;
|
||||
use WapplerSystems\BookmarksLikesRatings\Domain\Model\Voter;
|
||||
use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||
|
||||
/**
|
||||
*/
|
||||
class BookmarkRepository extends Repository
|
||||
{
|
||||
|
||||
|
||||
public function countByUserTablenameObjectUid($userUid, $tablename, $objectUid)
|
||||
{
|
||||
$query = $this->createQuery();
|
||||
|
||||
return $query->matching(
|
||||
$query->logicalAnd(
|
||||
[
|
||||
$query->equals('user', $userUid),
|
||||
$query->equals('tablename', $tablename),
|
||||
$query->equals('objectUid', $objectUid)
|
||||
]
|
||||
)
|
||||
)->execute()->count();
|
||||
}
|
||||
|
||||
|
||||
public function removeByUserTablenameObjectUid($userUid, $tablename, $objectUid)
|
||||
{
|
||||
$query = $this->createQuery();
|
||||
|
||||
$objs = $query->matching(
|
||||
$query->logicalAnd(
|
||||
[
|
||||
$query->equals('user', $userUid),
|
||||
$query->equals('tablename', $tablename),
|
||||
$query->equals('objectUid', $objectUid)
|
||||
]
|
||||
)
|
||||
)->execute()->toArray();
|
||||
|
||||
foreach ($objs as $obj) {
|
||||
$this->remove($obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize this repository
|
||||
*/
|
||||
public function initializeObject(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the voting by giving the rating and voter objects
|
||||
*
|
||||
* @param Rating|null $rating The concerned ratingobject
|
||||
* @param Voter|null $voter The Uid of the rated row
|
||||
* @return Vote|object The voting
|
||||
*/
|
||||
public function findMatchingRatingAndVoter($rating = null, $voter = null)
|
||||
{
|
||||
/** @var QueryInterface $query */
|
||||
$query = $this->createQuery();
|
||||
|
||||
return $query->matching(
|
||||
$query->logicalAnd(
|
||||
[
|
||||
$query->equals('rating', $rating),
|
||||
$query->equals('voter', $voter)
|
||||
]
|
||||
)
|
||||
)->execute()->getFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts all votings by giving the rating and ratingstep
|
||||
*
|
||||
* @param Rating $rating The concerned ratingobject
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf $stepconf The stepconf object
|
||||
* @return int
|
||||
*/
|
||||
public function countByMatchingRatingAndVote($rating = null, $stepconf = null): int
|
||||
{
|
||||
$query = $this->createQuery();
|
||||
$query->matching($query->logicalAnd(
|
||||
[
|
||||
$query->equals('rating', $rating->getUid()),
|
||||
$query->equals('vote', $stepconf->getUid())
|
||||
]
|
||||
));
|
||||
|
||||
return count($query->execute());
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts all anonymous votings by giving the rating and ratingstep
|
||||
*
|
||||
* @param Rating $rating The concerned ratingobject
|
||||
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Model\Stepconf $stepconf The stepconf object
|
||||
* @param int $anonymousVoter UID of the anonymous account
|
||||
* @return int
|
||||
*/
|
||||
public function countAnonymousByMatchingRatingAndVote($rating = null, $stepconf = null, $anonymousVoter = null): int
|
||||
{
|
||||
/** @var int $count */
|
||||
$count = 0;
|
||||
|
||||
if ($anonymousVoter !== null) {
|
||||
$query = $this->createQuery();
|
||||
$query->matching(
|
||||
$query->logicalAnd([
|
||||
$query->equals('rating', $rating->getUid()),
|
||||
$query->equals('vote', $stepconf->getUid()),
|
||||
$query->equals('voter', $anonymousVoter),
|
||||
])
|
||||
);
|
||||
$count = count($query->execute());
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user