bookmark-pages/Classes/Widgets/Provider/TopLikesDataProvider.php
2021-08-20 13:33:13 +02:00

57 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace WapplerSystems\BookmarksLikesRatings\Widgets\Provider;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\DebugUtility;
use WapplerSystems\BookmarksLikesRatings\Domain\Repository\LikeRepository;
class TopLikesDataProvider
{
/** @var LikeRepository */
protected $likeRepository;
/**
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Repository\LikeRepository $bookmarkRepository
*/
public function injectLikeRepository(LikeRepository $likeRepository) {
$this->likeRepository = $likeRepository;
}
public function __construct()
{
}
public function getItems()
{
$objs = $this->likeRepository->getTop(10);
$items = [];
foreach ($objs as $obj) {
$title = '';
if ($obj['tablename'] === 'pages') {
$page = BackendUtility::getRecord('pages',$obj['object_uid'],'title');
if ($page) {
$title = $page['title'];
}
}
$items[] = [
'title' => $title,
'number' => $obj['number']
];
}
return $items;
}
}