PHP code example of sizeg / yii2-newton-cool-ranking-behavior

1. Go to this page and download the library: Download sizeg/yii2-newton-cool-ranking-behavior library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sizeg / yii2-newton-cool-ranking-behavior example snippets


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


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

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

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