Zwischenstand
This commit is contained in:
@@ -10,13 +10,26 @@
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Model;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Bookmark
|
||||
class Bookmark extends AbstractEntity
|
||||
{
|
||||
|
||||
|
||||
/** @var int */
|
||||
protected $user;
|
||||
|
||||
/** @var string */
|
||||
protected $tablename;
|
||||
|
||||
/** @var int */
|
||||
protected $objectUid;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -29,15 +42,64 @@ class Bookmark
|
||||
* @var string
|
||||
*/
|
||||
protected $url;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $pid;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $parameter;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getUser(): int
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user
|
||||
*/
|
||||
public function setUser(int $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTablename(): string
|
||||
{
|
||||
return $this->tablename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tablename
|
||||
*/
|
||||
public function setTablename(string $tablename): void
|
||||
{
|
||||
$this->tablename = $tablename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getObjectUid(): int
|
||||
{
|
||||
return $this->objectUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $objectUid
|
||||
*/
|
||||
public function setObjectUid(int $objectUid): void
|
||||
{
|
||||
$this->objectUid = $objectUid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Bookmark constructor.
|
||||
* Initialize the bookmark with data
|
||||
@@ -47,7 +109,7 @@ class Bookmark
|
||||
* @param null $pid page id
|
||||
* @param null $parameter
|
||||
*/
|
||||
public function __construct($url, $title = null, $pid = null, $parameter = null)
|
||||
public function construct2($url, $title = null, $pid = null, $parameter = null)
|
||||
{
|
||||
if (is_array($url)) {
|
||||
$this->id = $url['id'];
|
||||
@@ -169,22 +231,6 @@ class Bookmark
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPid()
|
||||
{
|
||||
return $this->pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pid
|
||||
*/
|
||||
public function setPid($pid)
|
||||
{
|
||||
$this->pid = $pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
73
Classes/Domain/Model/Like.php
Normal file
73
Classes/Domain/Model/Like.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace WapplerSystems\BookmarksLikesRatings\Domain\Model;
|
||||
|
||||
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Like extends AbstractEntity
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
protected $user;
|
||||
|
||||
/** @var string */
|
||||
protected $tablename;
|
||||
|
||||
/** @var int */
|
||||
protected $objectUid;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getUser(): int
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user
|
||||
*/
|
||||
public function setUser(int $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTablename(): string
|
||||
{
|
||||
return $this->tablename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tablename
|
||||
*/
|
||||
public function setTablename(string $tablename): void
|
||||
{
|
||||
$this->tablename = $tablename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getObjectUid(): int
|
||||
{
|
||||
return $this->objectUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $objectUid
|
||||
*/
|
||||
public function setObjectUid(int $objectUid): void
|
||||
{
|
||||
$this->objectUid = $objectUid;
|
||||
}
|
||||
|
||||
|
||||
}
|
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;
|
||||
}
|
||||
}
|
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