sizeg/yii2-newton-cool-ranking-behavior 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sizeg/yii2-newton-cool-ranking-behavior

最新稳定版本:v1.0.0

Composer 安装命令:

composer require sizeg/yii2-newton-cool-ranking-behavior

包简介

Yii2 Newton cool ranking behavior

README 文档

README

This behavior provides the algorithm of rank hotness with Newton's law of cooling explained by Evan Miller.

You can use it to rate comments or blog posts. Listing active discussion threads in an online forum.

Read this article Rank Hotness With Newton's Law of Cooling for more details.

Installation

Package is available on Packagist, you can install it using Composer.

composer require sizeg/yii2-newton-cool-ranking-behavior

Dependencies

  • Yii2 (testing with 2.8, but should work with lower versions)

Basic usage

Create migration,

public function up()
{
    // [[NewtonCoolRankingBehavior::$rankAttribute]]
    $this->addColumn('{{%tableName}}', 'rank', $this->float());

    // [[NewtonCoolRankingBehavior::$rankTimeAttribute]]
    // By default time update with result of php time() function
    // For example we will use DateTime instead of UnixTimestamp
    $this->addColumn('{{%tableName}}', 'rankTime', $this->datetime());

    // [[NewtonCoolRankingBehavior::$rankBoostAttribute]]
    // This field is optional
    $this->addField('{{%tableName}}', 'rankBoost', $this->float());
}

Add behavior to your ActiveRecord model,

class Item extends \yii\base\ActiveRecord
{
    public function behaviors()
    {
        return \yii\helpers\ArrayHelper::merge(parent::behaviors(), [
            [
                'class' => 'sizeg\newtoncoolranking\NewtonCoolRankingBehavior',
                // optional params
                'initial' => 1000, 
                'coolingRate' => 150,
                'timeValue' => date('Y-m-d H:i:s'), // can be a callback function
            ]
        ]);
    }
}

By default the new model would have [[NewtonCoolRankingBehavior::$initial]] value and will cooling with [[NewtonCoolRankingBehavior::$coolingRate]].

When there is new activity on an model, you need update rank,

/** @var ActiveRecord $model */
$model->heat(20);

Sometimes you need one or more models to show in top for a few days, then you need to boost it.

Boost value will be received from model [[NewtonCoolRankingBehavior::$rankBoostAttribute]] field. If field doesn't exist, the value will be received from optional [[NewtonCoolRankingBehavior::$boost]] attribute.

/** @var ActiveRecord $model */
$model->boost();

统计信息

  • 总下载量: 8.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固