76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
|
<?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();
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|