Zwischenstand
This commit is contained in:
75
Classes/Domain/Repository/LikeRepository.php
Normal file
75
Classes/Domain/Repository/LikeRepository.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Repository;
|
||||
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
||||
use TYPO3\CMS\Core\Utility\DebugUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
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 LikeRepository 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getTop($limit)
|
||||
{
|
||||
|
||||
/** @var QueryBuilder $queryBuilder */
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_bookmarkslikesratings_domain_model_like');
|
||||
|
||||
return $queryBuilder
|
||||
->select('tablename')
|
||||
->addSelect('object_uid')
|
||||
->addSelectLiteral('count(*) as number')
|
||||
->from('tx_bookmarkslikesratings_domain_model_like')
|
||||
->groupBy('tablename')
|
||||
->addGroupBy('object_uid')
|
||||
->orderBy('number', 'DESC')
|
||||
->setMaxResults($limit)
|
||||
->execute()->fetchAll();
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user