diff --git a/Extensions/StarRatingExtension.php b/Extensions/StarRatingExtension.php index 476ed68..ab20474 100644 --- a/Extensions/StarRatingExtension.php +++ b/Extensions/StarRatingExtension.php @@ -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 ) diff --git a/README.md b/README.md index 967658d..ea11410 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,9 @@ if you want to use the [font awesome icon sizes](http://fortawesome.github.io/Fo If you want the smallest size use "fa-norm" (in font awesome, this would be the same as not providing an size class); providing no size argument sets the font size to 25px which is somewhere in between "fa-lg" and "fa-2x". To customize the size, feel free to override the css. +When ratings are displayed, they are rounded to the closest half star, ie 2.3 and 2.6 equals 2 and a half star. + + License ======= This bundle is under the MIT license. See the complete license in the bundle: diff --git a/Resources/public/css/rating.css b/Resources/public/css/rating.css index c841efb..39870fb 100644 --- a/Resources/public/css/rating.css +++ b/Resources/public/css/rating.css @@ -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; diff --git a/Resources/views/Display/ratingDisplay.html.twig b/Resources/views/Display/ratingDisplay.html.twig index c40813d..e9b28ab 100644 --- a/Resources/views/Display/ratingDisplay.html.twig +++ b/Resources/views/Display/ratingDisplay.html.twig @@ -1,5 +1,6 @@
\ No newline at end of file diff --git a/Resources/views/rating.html.twig b/Resources/views/rating.html.twig index 021b89d..7045516 100644 --- a/Resources/views/rating.html.twig +++ b/Resources/views/rating.html.twig @@ -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 -%}