oachoor / rating-bundle
Provides star rating functionality for Symfony
Installs: 210
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 5
Open Issues: 2
Type:symfony-bundle
Requires
- php: >=7.2
- doctrine/common: ^2.11
- doctrine/doctrine-bundle: ^1.0 || ^2.0
- doctrine/orm: ^2.6 || ^2.7
- symfony/form: ^4.3 || ^5.0
- symfony/framework-bundle: ^4.3 || ^5.0
- symfony/security-bundle: ^4.3 || ^5.0
- symfony/twig-bundle: ^4.3 || ^5.0
- symfony/validator: ^4.3 || ^5.0
Requires (Dev)
- phpunit/phpunit: ^8.4
- symfony/browser-kit: ^4.3 || ^5.0
- symfony/phpunit-bridge: ^4.3 || ^5.0
Suggests
- symfony/translation: If you want feedback messages to be translated.
This package is auto-updated.
Last update: 2024-04-19 21:39:35 UTC
README
This Symfony bundle provides integration of a star rating system.
Requirements
- PHP 7.2+
- MySQL 5.7.20+
- Symfony 4.3+
📦 Installation
Install bundle with Composer
dependency manager first by running the command:
$ composer req oachoor/rating-bundle
Add routes
oa_rating: resource: '@RatingBundle/Controller' type: annotation
(Optional) Create your own Entities
Entities doesn't fully meet your requirements?, then you can create yours based on Rating and Vote.
Resolve abstract Entities with RatingBundle or your custom ones
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
Define mapping Bundle
Make sure you have registered the Bundle that holds the Entities as following:
doctrine: orm: entity_managers: default: mappings: RatingBundle: ~ or AcmeRatingBundle: ~
Update database schema
$ bin/console doctrine:schema:update --force --no-debug
Using voting strategy
There are two strategies for rating, based on IP addresses or cookies. (both? feel free to contribute)
oa_rating: strategy: cookie (default "ip") cookie_name: your_custom_name cookie_lifetime: '+1 year'
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:
{{ render( controller( 'RatingBundle:Rating:result', {'contentId': yourContentId} ) ) }}
Rating is based on Content, to enable voting for a Content use the following twig code:
{{ render( controller( 'RatingBundle:Rating:vote', {'contentId': yourContentId} ) ) }}
Example
A minimal Template that contains rating-call, javascripts and stylesheets.
Todos
- Make User dependencies optional.
- Write some Unit Tests.
- Add Fixtures.