dev-master
9999999-dev https://github.com/oachoor/RatingBundleProvides star rating functionality for Symfony3
MIT
The Requires
- php >=7.1
- symfony/symfony 3.4.*
by Omar Achoor
bundle rating voting star
Provides star rating functionality for Symfony3
This Symfony bundle provides integration of a star rating system., (*1)
Install bundle with Composer
dependency manager first by running the command:, (*2)
$ composer req oachoor/rating-bundle
, (*3)
``` yaml oa_rating: resource: '@RatingBundle/Controller' type: annotation, (*4)
### (Optional) Create your own Entities Entities doesn't fully meet your requirements?, then you can create yours based on [Rating](Entity/Rating.php) and [Vote](Entity/Vote.php). ### Resolve abstract Entities with RatingBundle or your custom ones ``` yaml doctrine: orm: resolve_target_entities: RatingBundle\Model\AbstractVote: RatingBundle\Entity\Vote or AcmeRatingBundle\Entity\Vote RatingBundle\Model\AbstractRating: RatingBundle\Entity\Rating or AcmeRatingBundle\Entity\Rating Symfony\Component\Security\Core\User\UserInterface: RatingBundle\Entity\User or AcmeRatingBundle\Entity\User
Make sure you have registered the Bundle that holds the Entities as following:, (*5)
``` yaml doctrine: orm: entity_managers: default: mappings: RatingBundle: ~ or AcmeRatingBundle: ~, (*6)
### Update database schema ``` bash $ bin/console doctrine:schema:update --force --no-debug
There are two strategies for rating, based on IP addresses or cookies. (both? feel free to contribute), (*7)
``` yaml oa_rating: strategy: cookie (default "ip") cookie_name: your_custom_name cookie_lifetime: '+1 year', (*8)
### Templates customization Templates can be overridden in the `<your-project>/templates/bundles/RatingBundle/` directory, the new templates must use the same name and path (relative to `RatingBundle/Resources/views/`) as the original templates. To override the `Resources/views/rating/view.html.twig` template, create this template: `<your-project>/templates/bundles/RatingBundle/rating/view.html.twig` ### Usage To see rating result for a Content (read-only mode), use the following twig code: ``` twig {{ render( controller( 'RatingBundle:Rating:result', {'contentId': yourContentId} ) ) }}
Rating is based on Content, to enable voting for a Content use the following twig code:, (*9)
twig
{{ render( controller( 'RatingBundle:Rating:vote', {'contentId': yourContentId} ) ) }}
, (*10)
A minimal Template that contains rating-call, javascripts and stylesheets., (*11)
Provides star rating functionality for Symfony3
MIT
bundle rating voting star