Bookmark.php 1.47 KB
<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "bookmark".
 *
 * @property integer $bookmark_id
 * @property integer $user_id
 * @property string $model
 * @property integer $model_id
 * @property integer $type
 *
 * @property User $user
 */
class Bookmark extends \yii\db\ActiveRecord
{

    const TYPE_PERFORMER = 1;
    const TYPE_CUSTOMER = 2;
    const TYPE_PROJECT = 3;
    const TYPE_VACANCY = 4;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'bookmark';
    }

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

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'bookmark_id' => Yii::t('app', 'Bookmark ID'),
            'user_id' => Yii::t('app', 'User ID'),
            'model' => Yii::t('app', 'Model'),
            'model_id' => Yii::t('app', 'Model ID'),
            'type' => Yii::t('app', 'Type'),
        ];
    }

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