diff --git a/Classes/Domain/Repository/BookmarkRepository.php b/Classes/Domain/Repository/BookmarkRepository.php index 4021c2e..753d105 100644 --- a/Classes/Domain/Repository/BookmarkRepository.php +++ b/Classes/Domain/Repository/BookmarkRepository.php @@ -2,6 +2,9 @@ namespace WapplerSystems\BookmarksLikesRatings\Domain\Repository; +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Database\Query\QueryBuilder; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Persistence\QueryInterface; use WapplerSystems\BookmarksLikesRatings\Domain\Model\Rating; use WapplerSystems\BookmarksLikesRatings\Domain\Model\Vote; @@ -52,6 +55,25 @@ class BookmarkRepository extends Repository } + public function getTop($limit) + { + + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_bookmarkslikesratings_domain_model_bookmark'); + + return $queryBuilder + ->select('tablename') + ->addSelect('object_uid') + ->addSelectLiteral('count(*) as number') + ->from('tx_bookmarkslikesratings_domain_model_bookmark') + ->groupBy('tablename') + ->addGroupBy('object_uid') + ->orderBy('number', 'DESC') + ->setMaxResults($limit) + ->execute()->fetchAll(); + } + + /** * Initialize this repository */ diff --git a/Classes/Widgets/Provider/TopBookmarksDataProvider.php b/Classes/Widgets/Provider/TopBookmarksDataProvider.php new file mode 100644 index 0000000..3e6c69c --- /dev/null +++ b/Classes/Widgets/Provider/TopBookmarksDataProvider.php @@ -0,0 +1,51 @@ +bookmarkRepository = $bookmarkRepository; + } + + + public function __construct() + { + } + + + public function getItems() + { + + $objs = $this->bookmarkRepository->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; + } +} diff --git a/Classes/Widgets/Provider/TopLikesDataProvider.php b/Classes/Widgets/Provider/TopLikesDataProvider.php index a1ac643..94ba36e 100644 --- a/Classes/Widgets/Provider/TopLikesDataProvider.php +++ b/Classes/Widgets/Provider/TopLikesDataProvider.php @@ -6,7 +6,6 @@ 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 @@ -16,7 +15,7 @@ class TopLikesDataProvider protected $likeRepository; /** - * @param \WapplerSystems\BookmarksLikesRatings\Domain\Repository\LikeRepository $bookmarkRepository + * @param \WapplerSystems\BookmarksLikesRatings\Domain\Repository\LikeRepository $likeRepository */ public function injectLikeRepository(LikeRepository $likeRepository) { $this->likeRepository = $likeRepository; diff --git a/Classes/Widgets/TopBookmarksWidget.php b/Classes/Widgets/TopBookmarksWidget.php new file mode 100644 index 0000000..cb10a8e --- /dev/null +++ b/Classes/Widgets/TopBookmarksWidget.php @@ -0,0 +1,65 @@ +configuration = $configuration; + $this->view = $view; + $this->options = $options; + $this->buttonProvider = $buttonProvider; + $this->dataProvider = $dataProvider; + } + + public function renderWidgetContent(): string + { + $this->view->setTemplate('TopBookmarksWidget'); + $this->view->assignMultiple([ + 'items' => $this->dataProvider->getItems(), + 'options' => $this->options, + 'button' => $this->buttonProvider, + 'configuration' => $this->configuration, + ]); + return $this->view->render(); + } + +} diff --git a/Configuration/Backend/DashboardWidgets.yaml b/Configuration/Backend/DashboardWidgets.yaml index c56f2db..b85b58a 100644 --- a/Configuration/Backend/DashboardWidgets.yaml +++ b/Configuration/Backend/DashboardWidgets.yaml @@ -7,10 +7,25 @@ services: $dataProvider: '@WapplerSystems\BookmarksLikesRatings\Widgets\Provider\TopLikesDataProvider' tags: - name: dashboard.widget - identifier: 'bookmarks_likes_ratings' + identifier: 'bookmarks_likes_ratings_likes' groupNames: 'ratings' title: 'LLL:EXT:bookmarks_likes_ratings/Resources/Private/Language/locallang.xlf:widgets.bookmarks_likes_ratings.topLikes.title' description: 'LLL:EXT:bookmarks_likes_ratings/Resources/Private/Language/locallang.xlf:widgets.bookmarks_likes_ratings.topLikes.description' iconIdentifier: 'content-widget-text' height: 'large' width: 'medium' + + dashboard.widget.bookmarkslikesratingsTopBookmarks: + class: 'WapplerSystems\BookmarksLikesRatings\Widgets\TopBookmarksWidget' + arguments: + $view: '@dashboard.views.widget' + $dataProvider: '@WapplerSystems\BookmarksLikesRatings\Widgets\Provider\TopBookmarksDataProvider' + tags: + - name: dashboard.widget + identifier: 'bookmarks_likes_ratings_bookmarks' + groupNames: 'ratings' + title: 'LLL:EXT:bookmarks_likes_ratings/Resources/Private/Language/locallang.xlf:widgets.bookmarks_likes_ratings.topBookmarks.title' + description: 'LLL:EXT:bookmarks_likes_ratings/Resources/Private/Language/locallang.xlf:widgets.bookmarks_likes_ratings.topBookmarks.description' + iconIdentifier: 'content-widget-text' + height: 'large' + width: 'medium' diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 290b5e0..26c6a14 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -6,13 +6,15 @@ - Ratings Top likes + + Top bookmarks + diff --git a/Resources/Private/Templates/Dashboard/Widgets/TopBookmarksWidget.html b/Resources/Private/Templates/Dashboard/Widgets/TopBookmarksWidget.html new file mode 100644 index 0000000..fd66a8d --- /dev/null +++ b/Resources/Private/Templates/Dashboard/Widgets/TopBookmarksWidget.html @@ -0,0 +1,24 @@ + + + + +
+ + + + + + + +
+

{item.title -> f:format.crop(maxCharacters: 180)}

+
+ {item.number} +
+
+ +
+ + + + diff --git a/ext_emconf.php b/ext_emconf.php index 9826230..e9bb890 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -15,7 +15,7 @@ $EM_CONF[$_EXTKEY] = [ 'author_email' => 'typo3@wappler.systems', 'author_company' => 'WapplerSystems', 'version' => '0.0.0', - 'state' => 'stable', + 'state' => 'alpha', 'uploadfolder' => 0, 'createDirs' => '', 'modify_tables' => '',