Commit 3fdfce69 authored by Tino Goratsch's avatar Tino Goratsch

display the ratings of a content item

parent 45e3939e
......@@ -63,7 +63,7 @@ class Index extends AbstractWidgetAction
'shariff' => [
'lang' => $this->translator->getShortIsoCode(),
'path' => $path,
'services' => \json_encode($this->getServices($sharingInfo)),
'services' => $this->getServices($sharingInfo),
],
];
}
......
......@@ -11,6 +11,7 @@ use ACP3\Core\Controller\AreaEnum;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\View;
use ACP3\Modules\ACP3\Share\Helpers\SocialServices;
use ACP3\Modules\ACP3\Share\Model\Repository\ShareRatingsRepository;
use ACP3\Modules\ACP3\Share\Model\Repository\ShareRepository;
class AddSocialSharingListener
......@@ -31,25 +32,32 @@ class AddSocialSharingListener
* @var \ACP3\Modules\ACP3\Share\Model\Repository\ShareRepository
*/
private $shareRepository;
/**
* @var \ACP3\Modules\ACP3\Share\Model\Repository\ShareRatingsRepository
*/
private $shareRatingsRepository;
/**
* AddSocialSharingListener constructor.
*
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\View $view
* @param \ACP3\Modules\ACP3\Share\Helpers\SocialServices $socialServices
* @param \ACP3\Modules\ACP3\Share\Model\Repository\ShareRepository $shareRepository
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\View $view
* @param \ACP3\Modules\ACP3\Share\Helpers\SocialServices $socialServices
* @param \ACP3\Modules\ACP3\Share\Model\Repository\ShareRepository $shareRepository
* @param \ACP3\Modules\ACP3\Share\Model\Repository\ShareRatingsRepository $shareRatingsRepository
*/
public function __construct(
RequestInterface $request,
View $view,
SocialServices $socialServices,
ShareRepository $shareRepository)
ShareRepository $shareRepository,
ShareRatingsRepository $shareRatingsRepository)
{
$this->request = $request;
$this->view = $view;
$this->socialServices = $socialServices;
$this->shareRepository = $shareRepository;
$this->shareRatingsRepository = $shareRatingsRepository;
}
/**
......@@ -58,12 +66,14 @@ class AddSocialSharingListener
public function execute(): void
{
if ($this->request->getArea() === AreaEnum::AREA_FRONTEND) {
$item = $this->shareRepository->getOneByUri($this->request->getUriWithoutPages());
$sharingInfo = $this->shareRepository->getOneByUri($this->request->getUriWithoutPages());
if (!empty($item) && (int) $item['active'] == 1) {
$this->view->assign('shariff', [
if (!empty($sharingInfo) && (int) $sharingInfo['active'] == 1) {
$this->view->assign('sharing', [
'path' => $this->request->getUriWithoutPages(),
'services' => \json_encode($this->socialServices->getActiveServices()),
'services' => $this->socialServices->getActiveServices(),
'ratings_active' => ((int)$sharingInfo['ratings_active']) === 1,
'rating_stats' => $this->shareRatingsRepository->getRatingsStats($sharingInfo['id'])
]);
$this->view->displayTemplate('Share/Partials/add_social_sharing.tpl');
......
......@@ -12,4 +12,12 @@ use ACP3\Core\Model\Repository\AbstractRepository;
class ShareRatingsRepository extends AbstractRepository
{
const TABLE_NAME = 'share_ratings';
public function getRatingsStats(int $shareId): array
{
return $this->db->fetchAssoc(
"SELECT COUNT(*) AS total_ratings, AVG(`stars`) AS average_rating FROM {$this->getTableName()} WHERE `share_id` = :shareId GROUP BY `share_id`;",
['shareId' => $shareId]
) ?: [];
}
}
/*
* Copyright (c) by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
.rating {
unicode-bidi: bidi-override;
direction: rtl;
font-size: 30px;
display: flex;
justify-content: flex-end;
}
.rating__star {
font-family: FontAwesome, sans-serif;
font-weight: normal;
font-style: normal;
}
.rating__star::before {
content: "\f006";
padding-right: 5px;
color: #777;
}
.rating__star:hover,
.rating__star:focus,
.rating__star:active,
.rating__star.rating__star_active {
text-decoration: none;
}
.rating__star:hover::before,
.rating__star:focus::before,
.rating__star:active::before,
.rating__star.rating__star_active::before,
.rating__star:hover ~ .rating__star::before,
.rating__star:focus ~ .rating__star::before,
.rating__star:active ~ .rating__star::before,
.rating__star.rating__star_active ~ .rating__star::before {
content: "\f005";
color: #e3cf7a;
}
/*
* Copyright (c) by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
.rating {
unicode-bidi: bidi-override;
direction: rtl;
font-size: 30px;
display: flex;
justify-content: flex-end;
}
.rating__star {
font-family: FontAwesome, sans-serif;
font-weight: normal;
font-style: normal;
&::before {
content: "\f006";
padding-right: 5px;
color: #777;
}
&:hover,
&:focus,
&:active,
&.rating__star_active {
text-decoration: none;
&::before,
& ~ .rating__star::before {
content: "\f005";
color: #e3cf7a;
}
}
}
{load_module module="widget/share/index/index" path=$shariff.path}
{js_libraries enable='shariff'}
{if !empty($sharing.services)}
{load_module module="widget/share/index/index" path=$sharing.path}
{js_libraries enable='shariff'}
{/if}
{if $sharing.ratings_active === true && !empty($sharing.rating_stats)}
{if !empty($sharing.services)}
<hr>
{/if}
{include file="asset:Share/Partials/ratings.tpl" sharing=$sharing}
{/if}
<span class="rating">
{$rating_rounded=$sharing.rating_stats.average_rating|round:0}
{for $i=5 to 1 step -1}
<a href="#"
title="{lang t="share|rate_with_x_stars" args=['%stars%' => $i]}"
class="rating__star{if $i == $rating_rounded} rating__star_active{/if}"></a>
{/for}
</span>
{if $sharing.rating_stats.total_ratings > 0}
<div class="rating-summary">
{$sharing.rating_stats.average_rating|round:2} / 5 ({lang t="share|total_x_ratings" args=['%ratings%' => $sharing.rating_stats.total_ratings]})
</div>
{/if}
<div class="shariff"
data-lang="{$shariff.lang}"
data-url="{uri args=$shariff.path absolute=true}"
data-services="{$shariff.services|escape:'html'}"
data-services="{$shariff.services|json_encode|escape:'html'}"
data-backend-url="{uri args="share"}"></div>
......@@ -11,6 +11,7 @@ services:
- '@core.view'
- '@share.helpers.social_services'
- '@share.model.share_repository'
- '@share.model.share_ratings_repository'
tags:
- { name: core.eventListener, event: share.layout.add_social_sharing, method: execute }
......
......@@ -17,6 +17,7 @@
<item key="fb_app_id">Facebook App-ID</item>
<item key="fb_secret">Facebook Secret</item>
<item key="mod_description">Ermöglicht die Einbindung diverser sozialer Netzwerke zum Teilen von Inhalten, etc.</item>
<item key="rate_with_x_stars">Mit %stars% Sternen bewerten</item>
<item key="select_active">Bitte wählen aus, ob dieser Datensatz bei sozialen Netzwerken geteilt werden können soll oder nicht.</item>
<item key="select_customize_services">Bitte wählen aus ob Sie die verfügbaren sozialen Netzwerke für diesen Datensatz anpassen möchten oder nicht.</item>
<item key="select_ratings_active">Bitte wählen aus, ob dieser Datensatz von Benutzern bewertet werden können soll oder nicht.</item>
......@@ -45,6 +46,7 @@
<item key="service_xing">Xing</item>
<item key="services">Dienste</item>
<item key="share">Social sharing</item>
<item key="total_x_ratings">Insgesamt %ratings% Bewertungen</item>
<item key="type_in_valid_resource">Bitte geben Sie einen validen Pfad zu einer ACP3 internen Ressource an.</item>
<item key="uri">Pfad</item>
</keys>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment