2017 © Pedro Peláez
 

library yii2-rate

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

image

mhndev/yii2-rate

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

  • Sunday, October 9, 2016
  • by majidphpdeveloper
  • Repository
  • 3 Watchers
  • 3 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 3 % Grown

The README.md

Yii2 Rate functionality implementation

Table of Contents

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

Installation

Composer

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

composer require --prefer-dist mhndev/yii2-rate "0.0.*"

or add, (*5)

"mhndev/yii2-rate": "0.0.*"

Configuration

create config file

then of all you need to create a configuration file in your yii2 project config directory called rate.php and fill it like following :, (*6)


return [ 'userClass' => \app\models\User::class, 'RateClass' => \mhndev\yii2Rate\Models\Rate::class, 'items'=>[ 'post' => [ 'class'=> \app\models\Post::class, 'rate_types' => ['rate','like'], 'rate_values' => [ 'class' => \mhndev\rate\DiscreteNumberValue::class, 'values' => ['1','2','3','4','5'] ] ] ] ];

look at config array and check items field are entities which you want to rate them or like them. for example above config array has an item called post. and its fields are :, (*7)

class

which specify entity class which you want to rate, (*8)

rate_types

you can have multiple kind of rates for an entity for example a user can like a post entity and also rate it, (*9)

rate_values

you can specify possible rate values for an entity, (*10)

and after that your user class you should implement following interface, (*11)

mhndev\rate\Interfaces\iUser

and add the following method for rate functionality persistence. you can change it as your project needs., (*12)

    /**
     * @param $value
     * @param iRateableEntity $entity
     * @param $type
     * @return Rate
     */
    public function doRate($value, iRateableEntity $entity, $type)
    {
        $rate = new Rate;

        $rate->type = $type;
        $rate->entity = get_class($entity);
        $rate->entity_id  = $entity->_id->__toString();
        $rate->owner = static::class;
        $rate->owner_id = Yii::$app->user->identity->id;
        $rate->value = $value;

        $rate->save();

        return $rate;
    }

Usage

Like

This is a sample code which uses this package :, (*13)

    $post = Post::findOne(1);
    $user = Yii::$app->user->identity;
    $user->like($post);

Rate

    $post = Post::findOne(1);
    $user = Yii::$app->user->identity;
    $user->rate(+2, $post, 'rate');

The Versions

09/10 2016

dev-master

9999999-dev

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

  Sources   Download

MIT

The Requires

 

yii2 yii rate rank like dislike unlike

09/10 2016

dev-develop

dev-develop

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

  Sources   Download

MIT

The Requires

 

yii2 yii rate rank like dislike unlike

09/10 2016

0.0.5

0.0.5.0

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

  Sources   Download

MIT

The Requires

 

yii2 yii rate rank like dislike unlike

02/10 2016

0.0.04

0.0.04.0

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

  Sources   Download

MIT

The Requires

 

yii2 yii rate rank like dislike unlike

25/09 2016

0.0.3

0.0.3.0

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

  Sources   Download

MIT

The Requires

 

yii2 yii rate rank like dislike unlike

25/09 2016

0.0.2

0.0.2.0

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

  Sources   Download

MIT

The Requires

 

yii2 yii rate rank like dislike unlike

25/09 2016

0.0.1

0.0.1.0

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

  Sources   Download

MIT

The Requires

 

yii2 yii rate rank like dislike unlike