mhndev / rate
Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)
1.0.10
2017-10-09 10:29 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- mikey179/vfsstream: 1.6.*
- phpunit/phpunit: 6.*
README
Supports
1) Like
2) Like (+1), Dislike(-1)
3) Rate with other number(e.x. 0 < rate <= 5 )
4) Rate with string ('good' , 'very good' , ...)
Sample Usage
use mhndev\rate\Abstracts\Entity; use mhndev\rate\DiscreteNumberValue; use mhndev\rate\Interfaces\iRateableEntity; class User { use \mhndev\rate\Traits\UserTrait; /** * @param $value * @param iRateableEntity $entity * @param $type */ function doRate($value, iRateableEntity $entity, $type) { echo 'rate is done in our storage system.'; } } //you can either extend your entity from AbstractEntity class class Post extends Entity { } //or use EntityTrait in your Entity class Post implements iRateableEntity { use \mhndev\rate\Traits\EntityTrait; } class Comment extends Entity { } //or use EntityTrait in your Entity class Comment implements iRateableEntity { use \mhndev\rate\Traits\EntityTrait; } $rateValue = (new DiscreteNumberValue())->setPossibleValues([1,2,3]); $post = (new Post())->setRateValue($rateValue); //or Post::setRateValue($rateValue); $post->setPossibleRateTypes(['like', 'rate']); $rateValue = (new DiscreteNumberValue())->setPossibleValues([-1,1]); $comment = (new Comment())->setRateValue($rateValue); //or Comment::setRateValue($rateValue); // by default possible rate types are "rate" and "like" so if you want your rate types to be just like default you don't need to call setPossibleRateTypes method on entity pbject $post->setPossibleRateTypes(['like', 'rate', 'test']); //or Post::setPossibleRateTypes(['like', 'rate', 'test']); $user = new User; $user->rate(3, $post); $user->like($post); $user->rate(1,$comment); $user->dislike($comment);