Commit 915fa55f authored by Tino Goratsch's avatar Tino Goratsch

let's give the some more feedback when rating a page

parent a1103234
......@@ -62,6 +62,7 @@ class ControllerActionDispatcher
*
* @throws ControllerActionNotFoundException
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
* @throws \ReflectionException
*/
public function dispatch($serviceId = '', array $arguments = [])
{
......@@ -112,6 +113,7 @@ class ControllerActionDispatcher
* @return mixed
*
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
* @throws \ReflectionException
*/
private function executeControllerAction(ActionInterface $controller, array $arguments)
{
......@@ -128,6 +130,8 @@ class ControllerActionDispatcher
* @param ActionInterface $controller
*
* @return array
*
* @throws \ReflectionException
*/
private function getCallable(ActionInterface $controller)
{
......
......@@ -65,7 +65,7 @@ class Modules
*
* @return bool
*/
public function controllerActionExists($path)
public function controllerActionExists(string $path)
{
return $this->controllerActionExists->controllerActionExists($path);
}
......@@ -73,13 +73,13 @@ class Modules
/**
* Returns, whether a module is active or not.
*
* @param string $module
* @param string $moduleName
*
* @return bool
*/
public function isActive($module)
public function isActive(string $moduleName)
{
$info = $this->getModuleInfo($module);
$info = $this->getModuleInfo($moduleName);
return !empty($info) && $info['active'] === true;
}
......@@ -87,28 +87,28 @@ class Modules
/**
* Returns the available information about the given module.
*
* @param string $module
* @param string $moduleName
*
* @return array
*/
public function getModuleInfo($module)
public function getModuleInfo(string $moduleName)
{
$module = \strtolower($module);
$moduleName = \strtolower($moduleName);
if (empty($this->modulesInfo)) {
$this->modulesInfo = $this->moduleInfoCache->getModulesInfoCache();
}
return !empty($this->modulesInfo[$module]) ? $this->modulesInfo[$module] : [];
return !empty($this->modulesInfo[$moduleName]) ? $this->modulesInfo[$moduleName] : [];
}
/**
* @param string $module
* @param string $moduleName
*
* @return int
*/
public function getModuleId($module)
public function getModuleId(string $moduleName)
{
$info = $this->getModuleInfo($module);
$info = $this->getModuleInfo($moduleName);
return !empty($info) ? $info['id'] : 0;
}
......@@ -120,7 +120,7 @@ class Modules
*
* @return bool
*/
public function isInstalled($moduleName)
public function isInstalled(string $moduleName)
{
$info = $this->getModuleInfo($moduleName);
......
......@@ -31,7 +31,7 @@ class ControllerActionExists
*
* @return bool
*/
public function controllerActionExists($path)
public function controllerActionExists(string $path)
{
$pathArray = \explode('/', \strtolower($path));
......
......@@ -51,14 +51,14 @@ class Rate extends AbstractFrontendAction
/**
* @param int $id
* @param int $stars
*
* @return array
*
* @throws \Doctrine\DBAL\DBALException
*/
public function execute(int $id, int $stars): array
public function execute(int $id): array
{
$stars = $this->request->getPost()->get('stars');
$ipAddress = $this->request->getSymfonyRequest()->getClientIp();
if ($this->canSaveRating($id, $stars, $ipAddress) === true) {
......@@ -70,7 +70,10 @@ class Rate extends AbstractFrontendAction
}
return [
'rating' => $this->shareRatingsRepository->getRatingStatistics($id),
'rating' => \array_merge(
$this->shareRatingsRepository->getRatingStatistics($id),
['already_rated' => $this->hasAlreadyRated($ipAddress, $id)]
),
];
}
......@@ -91,10 +94,23 @@ class Rate extends AbstractFrontendAction
if ($this->shareRepository->resultExistsById($shareId) === false) {
return false;
}
if ($this->shareRatingsRepository->hasAlreadyRated($ipAddress, $shareId) === true) {
if ($this->hasAlreadyRated($ipAddress, $shareId) === true) {
return false;
}
return true;
}
/**
* @param string $ipAddress
* @param int $shareId
*
* @return bool
*
* @throws \Doctrine\DBAL\DBALException
*/
private function hasAlreadyRated(string $ipAddress, int $shareId): bool
{
return $this->shareRatingsRepository->hasAlreadyRated($ipAddress, $shareId) === true;
}
}
......@@ -3,21 +3,23 @@
* See the LICENCE file at the top-level module directory for licencing details.
*/
.rating {
unicode-bidi: bidi-override;
align-items: center;
direction: rtl;
font-size: 24px;
display: flex;
justify-content: flex-end;
unicode-bidi: bidi-override;
}
.rating__star {
font-family: 'Glyphicons Halflings', sans-serif;
font-weight: normal;
font-size: 24px;
font-style: normal;
font-weight: normal;
margin-bottom: 0;
}
.rating__star::before {
color: #777;
content: "\e007";
padding-right: 5px;
color: #777;
}
.rating__star:hover,
.rating__star:focus,
......@@ -41,3 +43,6 @@
content: "\e006";
color: #e3cf7a;
}
.rating__already-rated {
direction: initial;
}
/*
* Copyright (c) by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
jQuery(document).ready(function($) {
$('#rating-wrapper').on('change', ':radio', function() {
$(this).closest('form').submit();
});
});
......@@ -4,22 +4,24 @@
*/
.rating {
unicode-bidi: bidi-override;
align-items: center;
direction: rtl;
font-size: 24px;
display: flex;
justify-content: flex-end;
unicode-bidi: bidi-override;
}
.rating__star {
font-family: 'Glyphicons Halflings', sans-serif;
font-weight: normal;
font-size: 24px;
font-style: normal;
font-weight: normal;
margin-bottom: 0;
&::before {
color: #777;
content: "\e007";
padding-right: 5px;
color: #777;
}
&:hover,
......@@ -44,3 +46,7 @@
}
}
}
.rating__already-rated {
direction: initial;
}
......@@ -3,6 +3,9 @@
<div id="rating-wrapper">
{include file="asset:Share/Partials/rating.tpl" rating=$sharing.rating}
</div>
{javascripts}
{include_js module="share" file="partials/rating"}
{/javascripts}
{if !empty($sharing.services)}
<hr>
{/if}
......
<span class="rating">
{$rating_rounded=$rating.average_rating|round:0}
{for $i=5 to 1 step -1}
<a href="{uri args="share/index/rate/stars_`$i`/id_`$rating.share_id`"}"
rel="nofollow"
data-ajax-form="true"
data-ajax-form-target-element="#rating-wrapper"
data-ajax-form-loading-overlay="false"
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>
<form action="{uri args="share/index/rate/id_`$rating.share_id`"}"
method="post"
accept-charset="UTF-8"
data-ajax-form="true"
data-ajax-form-target-element="#rating-wrapper"
data-ajax-form-loading-overlay="false">
<div class="rating">
{if isset($rating.already_rated) && $rating.already_rated}
<small class="rating__already-rated">{lang t="share|already_rated"}</small>
{/if}
{$rating_rounded=$rating.average_rating|round:0}
{for $i=5 to 1 step -1}
<label for="rating-star-{$i}"
title="{lang t="share|rate_with_x_stars" args=['%stars%' => $i]}"
class="rating__star{if $i == $rating_rounded} rating__star_active{/if}">
<input type="radio" id="rating-star-{$i}" name="stars" value="{$i}" class="hidden" required>
</label>
{/for}
</div>
</form>
{if $rating.total_ratings > 0}
<div class="rating-summary"
itemprop="aggregateRating"
......
......@@ -13,6 +13,7 @@
<item key="admin_index_delete">Datensatz löschen</item>
<item key="admin_index_edit">Datensatz bearbeiten</item>
<item key="admin_index_settings">Einstellungen</item>
<item key="already_rated">Sie haben diese Seite bereits bewertet.</item>
<item key="customize_services">Verfügbare Dienste anpassen</item>
<item key="fb_app_id">Facebook App-ID</item>
<item key="fb_secret">Facebook Secret</item>
......
......@@ -13,6 +13,7 @@
<item key="admin_index_delete">Delete resultset</item>
<item key="admin_index_edit">Edit resultset</item>
<item key="admin_index_settings">Settings</item>
<item key="already_rated">You've already rated this page.</item>
<item key="customize_services">Customize available services</item>
<item key="fb_app_id">Facebook App-ID</item>
<item key="fb_secret">Facebook Secret</item>
......
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