<?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
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'trigger_logs';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'action', 'datetime'], 'required'],
            [['user_id', 'presence_time'], 'integer'],
            [['datetime'], 'safe'],
            [['action'], 'string', 'max' => 255],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => Users::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']);
    }
}
