Giter Club home page Giter Club logo

starratingbundle's Introduction

StarRatingBundle

Star Rating Bundle for Symfony 3. Requires Jquery and Font Awesome.

If Using Symfony 2. Use version 1.*

Sample Output

alt tag

Installation

Step 1: Download the StarRatingBundle

Using Composer

Add the following to the "require" section of your composer.json file:

    "blackknight467/star-rating-bundle": "2.*"

Step 2: Enable the bundle

Enable the bundle in the kernel:

<?php
// app/appKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new blackknight467\StarRatingBundle\StarRatingBundle(),
    );
}

Step 3: Add the css

Add the css in your page head

  <link rel="stylesheet" type="text/css" href="{{ asset('bundles/starrating/css/rating.css') }}" />

or

	{% stylesheets
      'bundles/starrating/css/rating.css'
      filter="cssrewrite" %}
      <link href="{{ asset_url }}" rel="stylesheet" type="text/css" />
    {% endstylesheets %}

Step 4: Add the js

Add the javascript to your page head

    <!-- make sure that jquery is included --!>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script src="{{ asset('bundles/starrating/js/rating.js') }}"></script>

or

    <!-- make sure that jquery is included --!>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
	{% javascripts
      '@StarRatingBundle/Resources/public/js/rating.js' %}
      <script src="{{ asset_url }}"></script>
    {% endjavascripts %}

Usage

In a Form

<?php
    // ...
    $builder->add('rating', RatingType::class, [
    	'label' => 'Rating'
    ]);
    // ...

or for a custom rating scale:

<?php
    // ...
    $builder->add('rating', RatingType::class, [
    	//...
    	'stars' => 4,
    	//...
    ]);
    // ...

Display in a twig template using the rating filter

    // ...
    {{ someInteger|rating }}
    // ...

or if you are not using a 5 star scale

{{ someInteger|rating(4) }}

if you want to use the font awesome icon sizes

{{ someInteger|rating(5, "fa-3x") }}

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.

License

This bundle is under the MIT license. See the complete license in the bundle: LICENSE

starratingbundle's People

Contributors

blackknight467 avatar glynnforrest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

starratingbundle's Issues

Pass rate value into entity

Hi,
I have successfully use your bundle and I want to use rate value from your bundle and save it in a field of my table in the db through my entity as an integer.
So how can I save the rating in that field?
Thanks in advanced.

Stars Not showing

screen shot 2016-12-04 at 00 25 29

Hello,
Thank you this bundle. its working in a form but the stars are not showing.

and please how can i show the rated stars from the form on html.twig. i mean how to display the already selected rated stars on html.twig.

Symfony 4 template not found exception

This bundle will trigger an exception Symfony 4.

$resources = array_merge(array('StarRatingBundle::rating.html.twig'), $resources);

To solve this, change the line with:

$resources = array_merge(array('@StarRatingBundle/rating.html.twig'), $resources);

Then add and alias to /config/packages/twig.yaml:

twig:
  paths:
    '%kernel.project_dir%/templates': templates
    '%kernel.project_dir%/vendor/blackknight467/star-rating-bundle/blackknight467/StarRatingBundle/Resources/views': StarRatingBundle

Rectangles instead of stars

I work with Symfony 3.2.
My code is the following:
<p class="rating-stars">{{ product.rate|rating(5, "fa-3x") }}</p>
as an output, I had the 5 rectangles instead of stars. How can I solve this issue?
rectangles

Is it possible to use it in a Handlebars file ?

Hi !

I'm using your bundle, and it is exactly what I need !
Working perfectly with Twig

My problem is that I now use handlebarsjs template file for a specific functionality in my symfony app.
Is there a equivalent of {{ someInteger|rating }} for handlebars ??

Thanks

Usage in forms

Hi!

I am trying to use your bundle and I found that I cannot make it work in the form.

I added in my form builder this line

->add('rating', 'rating', array('label' => 'Rating'));

and now I can see this field:

image

But it is not working as expected when clicking at some star. When I do mouseout the whole stars get deactivated again and the input field

still shows 0 as value.

May I be doing something wrong?

Another topic is if you made or thought on some way to make this work in ajax, anyway once I can make work the normal functionality I can implement on myself the ajax sendinf of the rating.

Thanks and best regars!

This bundle will be updated to symfony 3?

Hi, i'm trying to use the bundle with symfony 3 but forms have changed.

<?php
    // ...
    $builder->add('rating', 'rating', array(
        'label' => 'Rating'
    ));
    // ...

Thanks.

Render half star

Hi.

It is possible to display in a Twig template a half star score?

problem

An exception has been thrown during the rendering of a template ("Notice: Object of class Symfony\Component\Form\FormView could not be converted to int")

Label appearing twice

Hello. I like this bundle, was easy to use(instructions on getting font awesome too would have helped but fine)

I have deployed my form with the stars, but the form label is appearing twice for some reason. I am using a loop to render my form that looks kind of like
{{form.label}}{{form.form}}

Not sure why the label is being duplicated. The rest of the form appears normally

Thank you

Issue in installation

Hi,
When I install the bundle with composer, it is installed under vendor directory but the directory web/bundles/starrating/ doesn't exist, when I add it manually and I try to execute I get the error

ClassNotFoundExceptionAttempted to load class "StarRatingBundle" from namespace "blackknight467\StarRatingBundle".Did you forget a "use" statement for "blackknight467\StarRatingBundle\StarRatingBundle"?

in AppKernel.php

and it is caused by this declaration: new blackknight467\StarRatingBundle\StarRatingBundle()
can You tell me how to fix this ?
Also I would like to uninstall the bundle and reinstall it, as I tried many manipulations, should I remove it from the vendor directory?
Thanks

Read only field

Greetings,

I am actually using your bundle, and it is quite handy !
One problem thou : stars cannot be on readonly.

In fact, I have tried :

$builder->add("rating", "rating", array(
                    "label" => 'Rating',
                    "read_only" => true
))

Field is on readonly attribute :

readonly="readonly"

but I can still modify stars rating.

Is it a solution ?

Kind Regards,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.