sfPropelActAsRatableBehaviorPlugin - 0.5.0

Propel ratable behavior

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
This plugin is deprecated and is not maintained anymore. I don't use Propel anymore. Feel free to request if you want to take over the plugin development.
Show source | Show as Markdown


This plugin aims at providing rating capabilities to any Propel object with the help of a dedicated Propel behavior.


To install the plugin, run this command within your symfony project :

symfony plugin-install http://plugins.symfony-project.com/sfPropelActAsRatableBehaviorPlugin

To activate this Propel behavior in Symfony, you must first activate behaviors in your propel.ini file :

propel.builder.addBehaviors = true

Add the behavior to one or more of your existing model object classes, eg. an Article object :

class Article extends BaseArticle

sfPropelBehavior::add('Article', array('sfPropelActAsRatableBehavior'));

Then, rebuild your model :

symfony propel-build-all

And clear the cache :

symfony cc


You can rate your previously configured Article objects through the plugin API. Note that you can provide a user PK to determine if one of your user has already rated the object.

Here we imagine a User object instance $user which represent a member, an author, a person or anything like this.

To set a rating for a given user :

$article->setRating(10, $user->getId());

To retrieve user rating for this object :


To get the average rating of the object :


To clear user rating :


To clear all ratings for the object :


You can test if the object has already been rated :


You can also test if the object has already been rated by a particular user:


Unit testing

The plugin is provided with a unit tests suite located here. To run the tests, type this line from the root of your project :

$ php plugins/sfPropelActAsRatableBehaviorPlugin/test/sfPropelActAsRatableBehaviorTest.php

Note that you have to provide a test object to run the test. By default its an Article object with a title field which the behavior is supposed to be applied, but feel free to edit the tests file to adapt it to your need and your existing schema.