2017 © Pedro Peláez
 

library rating-bundle

Forked from damianociarla/rating-bundle ! This Bundle provides functionality for a rating system for Symfony4 applications

image

discutea/rating-bundle

Forked from damianociarla/rating-bundle ! This Bundle provides functionality for a rating system for Symfony4 applications

  • Tuesday, March 20, 2018
  • by Strategy
  • Repository
  • 1 Watchers
  • 0 Stars
  • 42 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 21 Forks
  • 0 Open issues
  • 6 Versions
  • 17 % Grown

The README.md

DiscuteaRatingBundle

The DiscuteaRatingBundle adds support for a rating system in Symfony2. Features include:, (*1)

  • You can add your vote to any page with a single line of code.
  • You can integrate it with any user management system (eg FOSUserBundle)
  • You can set different roles for access to the vote
  • The bundle using one stylesheet file without javascript file

1) Installation

A) Download and install DiscuteaRatingBundle

To install DiscuteaRatingBundle run the following command, (*2)

bash $ php composer.phar require damianociarla/rating-bundle

B) Enable the bundle

Enable the required bundles in the kernel:, (*3)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Discutea\RatingBundle\DiscuteaRatingBundle(),
    );
}

2) Create your Vote and Rating classes

In this first release DiscuteaRatingBundle supports only Doctrine ORM. However, you must provide a concrete Vote and Rating class. You must extend the abstract entities provided by the bundle and creating the appropriate mappings., (*4)

Rating

<?php
// src/MyProject/MyBundle/Entity/Rating.php

namespace MyProject\MyBundle\Entity;

use Discutea\RatingBundle\Entity\Rating as BaseRating;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
 */
class Rating extends BaseRating
{
    /**
     * @ORM\Id
     * @ORM\Column(type="string")
     */
    protected $id;

    /**
     * @ORM\OneToMany(targetEntity="MyProject\MyBundle\Entity\Vote", mappedBy="rating")
     */
    protected $votes;
}

Vote

<?php
// src/MyProject/MyBundle/Entity/Vote.php

namespace MyProject\MyBundle\Entity;

use Discutea\RatingBundle\Entity\Vote as BaseVote;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
 */
class Vote extends BaseVote
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="MyProject\MyBundle\Entity\Rating", inversedBy="votes")
     * @ORM\JoinColumn(name="rating_id", referencedColumnName="id")
     */
    protected $rating;

    /**
     * @ORM\ManyToOne(targetEntity="MyProject\UserBundle\Entity\User")
     */
    protected $voter;
}

3) Configure your application

# app/config/config.yml

discutea_rating:
    db_driver: orm
    base_path_to_redirect: / # when the permalink is not configured
    max_value: 5 # maximum value for the vote (stars displayed)
    model:
        rating: MyProject\MyBundle\Entity\Rating
        vote: MyProject\MyBundle\Entity\Vote

4) Import DiscuteaRatingBundle routing

Import the bundle routing:, (*5)

discutea_rating:
    resource: "@DiscuteaRatingBundle/Resources/config/routing.xml"
    prefix:   /

5) Import stylesheet in your template

To import the stylesheet run the following command:, (*6)

bash $ php app/console assets:install

and include the stylesheet in your template:, (*7)

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

5.1) Enable vote via ajax

To vote via ajax you have to include the script below after loading the jQuery library:, (*8)

<script src="{{ asset('bundles/discutearating/js/rating.js') }}"></script>

6) Showing rating and enabling vote

You can only vote the page you are in. You can not vote a page while you are on a different one. But you can show the rating of a page (read-only mode) in any page, (*9)

Showing rating

You can show rating using stars without enabling voting:, (*10)

{% include 'DiscuteaRatingBundle:Rating:rating.html.twig' with {'id' : 'YOUR_UNIQUE_ID'} %}

This is useful if you have a list of items and want to show the rating of each item., (*11)

Enabling vote

To enable voting on a page use the following twig code:, (*12)

{% include 'DiscuteaRatingBundle:Rating:control.html.twig' with {'id' : 'YOUR_UNIQUE_ID'} %}

If you need to change the default user role for a specific page, add the role parameter:, (*13)

{% include 'DiscuteaRatingBundle:Rating:control.html.twig' with {'id' : 'YOUR_UNIQUE_ID', 'role' : 'ROLE_USER'} %}

If you need to change the permalink, add the permalink parameter, otherwise it will be stored the current route:, (*14)

{% include 'DiscuteaRatingBundle:Rating:control.html.twig' with {'id' : 'YOUR_UNIQUE_ID', 'permalink' : url('YOUR_ROUTE_ID')} %}

The Versions

20/03 2018

dev-master

9999999-dev https://github.com/Discutea/DiscuteaRatingBundle.git

Forked from damianociarla/rating-bundle ! This Bundle provides functionality for a rating system for Symfony4 applications

  Sources   Download

MIT

The Requires

 

twig symfony2 rating fos fosuserbundle star

19/02 2015

v1.2

1.2.0.0 https://github.com/damianociarla/DCSRatingBundle

This Bundle provides functionality for a rating system for Symfony2 applications

  Sources   Download

MIT

The Requires

 

twig symfony2 rating fos fosuserbundle star

10/12 2014

v1.1.1

1.1.1.0 https://github.com/damianociarla/DCSRatingBundle

This Bundle provides functionality for a rating system for Symfony2 applications

  Sources   Download

MIT

The Requires

 

twig symfony2 rating fos fosuserbundle star

18/10 2014

v1.1

1.1.0.0 https://github.com/damianociarla/DCSRatingBundle

This Bundle provides functionality for a rating system for Symfony2 applications

  Sources   Download

MIT

The Requires

 

twig symfony2 rating fos fosuserbundle star

28/07 2014

v1.0.1

1.0.1.0 https://github.com/damianociarla/DCSRatingBundle

This Bundle provides functionality for a rating system for Symfony2 applications

  Sources   Download

MIT

The Requires

 

twig symfony2 rating fos fosuserbundle star

15/01 2014

v1.0

1.0.0.0 https://github.com/damianociarla/DCSRatingBundle

This Bundle provides functionality for a rating system for Symfony2 applications

  Sources   Download

MIT

The Requires

 

twig symfony2 rating fos fosuserbundle star