<?php

namespace common\modules\sessions\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "sessions".
 *
 * @property integer $id
 * @property string $PHPSESSID
 * @property integer $user_id
 * @property string $ip
 * @property string $url
 * @property integer $created_at
 */
class Session extends \common\components\ActiveRecordModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'sessions';
    }

    public function name()
    {
        return 'Сессия';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'created_at',
                'updatedAtAttribute' => null,
                'value' => time(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            // [['PHPSESSID', 'ip', 'url'], 'required'],
            [['user_id', 'created_at'], 'integer'],
            [['url', 'referer'], 'string'],
            [['PHPSESSID'], 'string', 'max' => 32],
            [['ip'], 'string', 'max' => 15],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'PHPSESSID' => 'Сессия',
            'user_id' => 'Пользователь',
            'ip' => 'IP',
            'url' => 'Ссылка',
            'created_at' => 'Дата добавления',
        ];
    }
}
