From 2de5930c85767de7f964c5dc0d5ed8a3a87a7aa2 Mon Sep 17 00:00:00 2001 From: "M. Vondano" Date: Sat, 20 Jul 2019 14:19:13 +0200 Subject: [PATCH] add aggregated ratings to json linked data --- src/ContentElement/EventBookingElement.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ContentElement/EventBookingElement.php b/src/ContentElement/EventBookingElement.php index 4f819eb..c918c09 100644 --- a/src/ContentElement/EventBookingElement.php +++ b/src/ContentElement/EventBookingElement.php @@ -3,8 +3,9 @@ /* * Regiondo Bundle for Contao Open Source CMS. * - * @copyright Copyright (c) 2018, derhaeuptling + * @copyright Copyright (c) 2019, derhaeuptling * @author Codefog + * @author Moritz V. * @license MIT */ @@ -148,6 +149,15 @@ protected function generateJsonLinkedData(CalendarEventsModel $model): array ], ]; + // Add aggregate ratings if present + if ($originalData['reviews_count'] && $originalData['rating_summary']) { + $data['aggregateRating'] = [ + '@type' => 'AggregateRating', + 'ratingCount' => $originalData['reviews_count'], + 'ratingValue' => $originalData['rating_summary'], + ]; + } + // Add the image if ($model->addImage && null !== ($image = FilesModel::findByPk($model->singleSRC)) && \is_file(TL_ROOT.'/'.$image->path)) { $data['image'] = Environment::get('url').'/'.$image->path;