<?php

namespace app\models;

use Yii;
use common\modules\users\models\User;

/**
 * This is the model class for table "trigger_logs".
 *
 * @property integer $id
 * @property integer $user_id
 * @property string $action
 * @property string $datetime
 * @property integer $presence_time
 *
 * @property User $user
 */
class TriggerLogs extends \yii\db\ActiveRecord
{
    const USER_REGISTRATION = 'registration';
    const USER_VISITED = 'visited';

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'trigger_logs';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'action', 'datetime', 'url'], 'required'],
            [['user_id', 'presence_time'], 'integer'],
            [['datetime'], 'safe'],
            [['action', 'url'], 'string', 'max' => 255],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'action' => 'Action',
            'datetime' => 'Datetime',
            'presence_time' => 'Presence Time',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }
}
