2017 © Pedro Peláez
 

library jraty

Package for item ratings + optional microdata format.

image

escapeboy/jraty

Package for item ratings + optional microdata format.

  • Monday, June 16, 2014
  • by escapeboy
  • Repository
  • 2 Watchers
  • 12 Stars
  • 372 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 1 Versions
  • 3 % Grown

The README.md

Laravel 4 Rating Package

Rating Package using jQuery Raty plugin for item ratings + optional microdata format., (*1)

alt text alt text alt text alt text alt text, (*2)

The package is doing everything for you - from displaying rating to receiving rating and stores it into database., (*3)


Installation

{
    ...
    "require": {
        "escapeboy/jraty": "dev-master"
    }
}

Register in app/config/app.php, (*4)

'providers' => array(
    'Escapeboy\Jraty\JratyServiceProvider',
)

Creating table for ratings, (*5)

php artisan migrate --package="escapeboy/jraty"

Publish jQuery Raty assets, (*6)

php artisan asset:publish escapeboy/jraty

Prepare for usage

First you need to load jQuery, (*7)

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

then need to load Raty plugin. You can use it like this:, (*8)

echo Jraty::js()

or, (*9)

<script src="packages/escapeboy/jraty/raty/lib/jquery.raty.min.js"></script>

After we need to initialize Raty plugin., (*10)

Using library:, (*11)

echo Jraty::js_init($params=array());

Jraty::js_init accepts array with options for Raty. More info can be found on Raty website, (*12)

For example this and it is default:, (*13)

Jraty::js_init(array(
    'score' => 'function() { return $(this).attr(\'data-score\'); }',
    'number' => 5,
    'click' => 'function(score, evt) {
                $.post(\'save/item_rating\',{
                    item_id: $(\'[data-item]\').attr(\'data-item\'),
                    score: score
                });
              }',
    'path' => '\'packages/escapeboy/jraty/raty/lib/img\''
));

returns, (*14)

$(document).ready(function () {
    $('#item-rating').raty({
        'score': function () {
            return $(this).attr('data-score');
        },
        'number': 5,
        'click': function (score, evt) {
            $.post('save/item_rating', {
                item_id: $('[data-item]').attr('data-item'),
                score: score
            });
        },
        'path': 'packages/escapeboy/jraty/raty/lib/img'
    });
});

Important: If you noticed in php call single quotes are escaped., (*15)

Usage

echo Jraty::html($item_id, $item_name='', $item_photo='', $seo=true);

If you are using seo option (true by default) its good to set a item_name, (*16)

And result will be alt text alt text alt text alt text alt text, (*17)

Library is accepting only one rating per item from single IP., (*18)

Additional

Deleting record, (*19)

Jraty::delete($id)

Adding manual rating, (*20)

$data = array(
            'item_id'    => Input::get('item_id'),
            'score'      => Input::get('score'),
            'added_on'   => DB::raw('NOW()'),
            'ip_address' => Request::getClientIp()
        );
Jraty::add($data);

Getting rating data for item, (*21)

$rating = Jraty::get($item_id);
echo $rating->avg; // avarage score
echo $rating->votes; // total votes

The Versions

16/06 2014

dev-master

9999999-dev http://github.com/escapeboy/jraty

Package for item ratings + optional microdata format.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

laravel seo rating microdata jraty