Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Extensions/StarRatingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ public function getFilters()

public function rating($number, $max = 5, $starSize = "")
{

$roundDown=floor($number);
$roundUp=ceil($number);
$fraction=(round($number*2,0,PHP_ROUND_HALF_UP)/2)-floor($number);

return $this->container->get('templating')->render(
'StarRatingBundle:Display:ratingDisplay.html.twig',
array(
'stars' => $number,
'roundDown' => $roundDown,
'roundUp'=>$roundUp,
'fraction'=>$fraction,
'max' => $max,
'starSize' => $starSize
)
Expand Down
17 changes: 17 additions & 0 deletions Resources/public/css/rating.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@
color:#e3cf7a;
}

.rating div.star-half {
font-family:FontAwesome;
font-weight:normal;
font-style:normal;
font-size: 25px;
display:inline-block;
position: relative;
}

.rating div.star-half:before {
content:"\f123";
padding-right:5px;
color:#e3cf7a;
}



.rating div.star-empty {
font-family:FontAwesome;
font-weight:normal;
Expand Down
3 changes: 2 additions & 1 deletion Resources/views/Display/ratingDisplay.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="rating">
{% for i in 1..max %}
<div class="{% if i <= stars %}star-full{% else %}star-empty{% endif %} {{ starSize }}"></div>

<div class="{% if i <=roundDown %}star-full{% elseif i == roundUp and roundDown!=roundUp %} {%if fraction==1%}star-full{%elseif fraction==0.5%}star-half{%else%}star-empty{%endif%}{%else%}star-empty{% endif %} {{ starSize }}"></div>
{% endfor %}
</div>
4 changes: 2 additions & 2 deletions Resources/views/rating.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
{{- " " -}}
{%- if attrname in ['placeholder', 'title'] -%}
{{- attrname }}="{{ attrvalue|trans({}, translation_domain) }}"
{%- elseif attrvalue is sameas(true) -%}
{%- elseif attrvalue is same as(true) -%}
{{- attrname }}="{{ attrname }}"
{%- elseif attrvalue is not sameas(false) -%}
{%- elseif attrvalue is not same as(false) -%}
{{- attrname }}="{{ attrvalue }}"
{%- endif -%}
{%- endfor -%}
Expand Down