Diem plugins syndication

dmRattablePlugin

Allow visitors to rate records ...

Installation

  • In a console, from your project root dir, run:
git clone httP://github.com/knplabs/dmRatablePlugin.git.git plugins/dmRattablePlugin  
  • In config/ProjectConfiguration.class.php, add dmRattablePlugin to the list of enabled plugins:
class ProjectConfiguration extends dmProjectConfiguration
{  
  public function setup()  
  {  
    parent::setup();  
 
    $this->enablePlugins(array(  
      // your enabled plugins  
      'dmRattablePlugin'  
    ));  
  • In a console, from your project root dir, run:
php symfony doctrine:generate-migrations-diff  

php symfony doctrine:migrate  

php symfony dm:setup  

dmRatablePlugin provides a Doctrine behavior, controllers, templates and assets to set up a rating system quickly.

Doctrine behavior

To declare that a model is ratable, add the behavior in your config/doctrine/schema.yml file:

Article:  
  actAs:  
    DmRatable:  

Run migrations and update the model:

php symfony doctrine:generate-migrations-diff  
php symfony doctrine:migrate  
php symfony dm:setup  

A new table, article_rate, is created to store the article rates.

Display rating stars

Include the plugin assets in your apps/front/config/view.yml file:

stylesheets:  
  - dmRatablePlugin.stars  
  - ...  

javascripts:  
  - lib.ui-core  
  - lib.ui-widget  
  - dmRatablePlugin.stars  
  - ...  

Include the dmRatable/rating component from your record template.

include_component('dmRatable', 'rating', array('record' => $article));  

JavaScript

To enable the jquery.stars plugin, paste the following code to your web/js/front.js file:

$('.dm_ratable_rating').each(function() {  
  var $this = $(this).stars({  
    inputType: "select",  
    callback: function(ui, type, value){  
      $this.find('.message').html(value==ui.options.cancelValue ? "Rating removed" : "Rating saved! ("+value+")").stop().css("opacity", 1).fadeIn(30);  
      setTimeout(function(){ $this.find('.message').fadeOut(1000) }, 2000);  
      $.ajax({  
        type:     'POST',  
        url:      $this.find('form').attr('action'),  
        data:     { hash: $this.attr('data-hash'), value: value, type: type },  
        success:  function(data) {  
          if(data.new_value) {  
              $this.stars('select', newValue);  
          }  
        }  
      });  
    }  
  });  
});  

Then customize it to fit your needs.

Admin

To show the rating of each record in its admin module, add a _rating partial:

# apps/admin/modules/article/config/generator.yml  

  list:  
    display:  
      - _rating  

# apps/admin/modules/article/templates/_rating.php  

<?php  
echo sprintf('%d/%d',  
  $article->getRating(),  
  $article->getTable()->getTemplate('DmRatable')->getOption('max_rate')  
);  

    Add a comment

    Impossible to fetch issues for this plugin.
    Impossible to get this plugin changelog.

    dmRattablePlugin, created on September 14, 2010 by altrano, used by 0 projects

    Fork Diem on GitHub