bookmark-pages/Classes/Widgets/Provider/TopLikesDataProvider.php

56 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2021-08-17 19:45:38 +02:00
<?php
declare(strict_types=1);
namespace WapplerSystems\BookmarksLikesRatings\Widgets\Provider;
2021-08-20 13:33:13 +02:00
use TYPO3\CMS\Backend\Utility\BackendUtility;
use WapplerSystems\BookmarksLikesRatings\Domain\Repository\LikeRepository;
2021-08-17 19:45:38 +02:00
2021-08-20 13:33:13 +02:00
class TopLikesDataProvider
2021-08-17 19:45:38 +02:00
{
2021-08-20 13:33:13 +02:00
/** @var LikeRepository */
protected $likeRepository;
/**
2021-08-20 16:25:22 +02:00
* @param \WapplerSystems\BookmarksLikesRatings\Domain\Repository\LikeRepository $likeRepository
2021-08-20 13:33:13 +02:00
*/
public function injectLikeRepository(LikeRepository $likeRepository) {
$this->likeRepository = $likeRepository;
}
2021-08-17 19:45:38 +02:00
public function __construct()
{
}
2021-08-20 13:33:13 +02:00
public function getItems()
2021-08-17 19:45:38 +02:00
{
2021-08-20 13:33:13 +02:00
$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;
2021-08-17 19:45:38 +02:00
}
}