Giter Club home page Giter Club logo

rate's Introduction

Rate System

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);

rate's People

Contributors

mhndev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.