Developed with love by KnpLabs Hire us for your project!
5

StarRatingBundle

by nurikabe

CCCStarRatingBundle

Form type and Twig filter for FyneWorks' super fine jQuery Star Rating Plugin.

Installation

Add the package to your dependencies

{
    "require": {
        "ccc/star-rating-bundle": "dev-master"
        ...
    }
}

Register the bundle in your kernel

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

Install the Star Rating Plugin

There are many ways to skin this cat, though if you'd like to manage the Star Rating Plugin via Composer this can be
done by adding a new external repository to composer.json:

"repositories": [
    {
        "type": "package",
        "package": {
            "name": "fyneworks/star-rating",
            "version": "dev-master",
            "source": {
                "type": "git",
                "url": "https://github.com/Fyneworks-jQuery/star-rating.git",
                "reference": "master"
            }
        }
    },
    ...
}

Update your packages

$ php composer.phar update ccc/star-rating-bundle

Usage

Load the Star Rating plugin in your layout. For example, if you are using Assetic and you have installed Star Rating
via Composer as per above:

{% stylesheets '@CCCStarRatingBundle/Resources/rating.css' %}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% javascripts '%kernel.root_dir%/../vendor/fyneworks/star-rating/jquery.rating.js' %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

Of course, remember to dump your assets if use_controller is off:

$ app/console assetic:dump

This bundle contains a new FormType star_rating field type:

$builder->add('rating', 'star_rating', array(
    'choices' => array(1 => 'ichi', 2  => 'ni', 3 => 'san', 4=> 'shi', 5 => 'go'),
    'expanded' => true,  // radio or checkbox...
    'multiple' => false  // ...but not checkbox
));

star_rating extends choice and will render expanded choice fields as a Star Rating field.

Original choice field:

before

As a star_rating field:

after

A Twig filter is also available that will render a static Star Rating widget given a numeric input:

{{ entity.rating|star_rating }}
  • Add "required" class to each input when Symfony field is required => true: This will cause the jQuery Star Rating Plugin to hide the cancel widget.
    By nurikabe, 2 years ago
  • Update class and title while preserving other attributes
    By nurikabe, 2 years ago
  • Update namespace to reflect new maintainer
    By nurikabe, 2 years ago
  • Update composer.json
    By nurikabe, 2 years ago
  • Update composer.json
    By nurikabe, 2 years ago
  • Update composer.json
    By nurikabe, 2 years ago
  • Update composer.json
    By nurikabe, 2 years ago
  • Update composer.json
    By nurikabe, 2 years ago
  • Add SLInsight badge
    By nurikabe, 2 years ago
  • Fix namespace
    By nurikabe, 2 years ago
  • Update README
    By nurikabe, 2 years ago
  • Fix composer
    By nurikabe, 2 years ago
  • Remove dead code. Move form type into Type directory.
    By nurikabe, 2 years ago
  • CS fix
    By nurikabe, 2 years ago
  • Transfer ownership
    By nurikabe, 2 years ago
  • Merge pull request #2 from mseshachalam/patch-1
    By nurikabe, 3 years ago
  • Bundle name corrected in the AppKernel
    By mseshachalam, 3 years ago
  • Require symfony/form at least 2.2 and open up for 2.4 and beyond.
    By nurikabe, 3 years ago
  • Merge pull request #1 from CedCannes/patch-1
    By nurikabe, 3 years ago
  • Added title attribute to have mouseover label
    By CedCannes, 3 years ago
  • Seems like we can't defined repositories here afterall.
    By nurikabe, 3 years ago
  • Require fyneworks/star-rating as a dependency. Not sure if this is possible in a bundle like this.
    By nurikabe, 3 years ago
  • Override style with our own.
    By nurikabe, 3 years ago
  • Add basic test
    By nurikabe, 4 years ago
  • Move images into doc directory.
    By nurikabe, 4 years ago
  • Add images
    By nurikabe, 4 years ago
  • Update README
    By nurikabe, 4 years ago
  • Can't use dashes in service keys.
    By nurikabe, 4 years ago
  • First commit
    By nurikabe, 4 years ago