The recommendations are always ordered with the best recommendation first. Recommendations never contain objects which the user has already rated so if the user has rated all objects then getRecommendations() will return an empty array.

Item recommendations

To retrieve recommendations of other items with similar ratings to a specific item the item class must have the sfPropelActAsSlopeOneRateableBehavior.

Note that your item class must implement a getId() method which returns a unique id.

When the behavior has been added you can now call getRecommendations($numRecommendations):

//get 10 recommended Item objects based on the rating of the current item$recommendations = $item->getRecommentations(10);

The recommendations are always ordered with the best recommendation first.

Recommendation objects

The objects returned by the two getRecommendations() will actually be of type sfPropelSlopeOneRecommendation. This class implements two methods:

getRecommendationRating() which returns the expected rating of the returned object

getRecommendationObject() which returns the actual recommended object

In all other concerns sfPropelSlopeOneRecommendation acts as a transparent wrapper class for the recommended object by passing calls to all other methods to this object.

An array of sfPropelSlopeOneRecommendation objects returned by getRecommendations() will be sorted by descending value returned by getRecommendationRating().

Maintenance

The Slope One implementation used in this plugin uses a database table containing precalculated rating relations between items. Data in this table needs to be updated on a regular basis to for recommendations to reflect the latest ratings.

Task-based maintenance

To maintain this you can invoke either of the provided tasks:

The MySQL task creates a slope_one stored procedure for maintaining the table and executes this. This will usually be faster than running the PHP task. This is recommended for production use if you use MySQL 5.1 verson which supports stored procedures.

> php symfony slopeone:build-mysql

The PHP task uses a combination of PHP and standard SQL queries for maintaining the data.

> php symfony slopeone:build-php

Depending on the number of items and ratings in your application maintenance can be time consuming and it suitable for a nightly cron job.