- PHP 7.1+
- MySQL 5.7.20+
- Symfony 3.4+
Install bundle with Composer
dependency manager first by running the command:
$ composer require oachoor/rating-bundle
Enable the bundle in app\AppKernel.php
file.
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new RatingBundle\RatingBundle(),
);
}
rating:
resource: '@RatingBundle/Controller'
type: annotation
Entities doens't fully meet your requirements?, then you can create yours based on Rating and Vote.
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: FOS\UserBundle\Model\User # Voter (Optional)
Make sure you have registred the Bundle that holds the Entities as following:
doctrine:
orm:
entity_managers:
default:
mappings:
RatingBundle: ~ or AcmeRatingBundle: ~
$ bin/console doctrine:schema:update --force
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'
To see rating result for a Content (read-only mode), use the following twig code:
{{ render( controller( 'RatingBundle:Rating:result', {'contentId' : YOUR_CONTENT_ID} ) ) }}
Rating is based on Content, to enable voting for a Content use the following twig code:
{{ render( controller( 'RatingBundle:Rating:vote', {'contentId' : YOUR_CONTENT_ID} ) ) }}
Voting is based on IP address, meaning that each computer or device can only vote once.
A minimal Template that contains rating-call, javascripts and stylesheets.