<?php

namespace common\modules\support\models\redmine;

use Yii;

/**
 * This is the model class for table "users".
 *
 * @property integer $id
 * @property string $login
 * @property string $hashed_password
 * @property string $firstname
 * @property string $lastname
 * @property integer $admin
 * @property integer $status
 * @property string $last_login_on
 * @property string $language
 * @property integer $auth_source_id
 * @property string $created_on
 * @property string $updated_on
 * @property string $type
 * @property string $identity_url
 * @property string $mail_notification
 * @property string $salt
 * @property integer $must_change_passwd
 * @property string $passwd_changed_on
 * @property integer $show_report
 * @property string $requisite
 */
class User extends \common\components\ActiveRecordModel
{
    const TYPE_USER = 'User';
    const TYPE_GROUP = 'Group';
    const TYPE_GROUP_NON_MEMBER = 'GroupNonMember';
    const TYPE_GROUP_ANONYMOUS = 'GroupAnonymous';
    const TYPE_ANONYMOUS_USER = 'AnonymousUser';

    public $specialName;

    /**
     * @inheritdoc
     */
    public function name() 
    {
        return 'Пользователи Redmine';
    }

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

    /**
     * @return \yii\db\Connection the database connection used by this AR class.
     */
    public static function getDb()
    {
        return Yii::$app->get('dbSupport');
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['admin', 'status', 'auth_source_id', 'must_change_passwd', 'show_report'], 'integer'],
            [['last_login_on', 'created_on', 'updated_on', 'passwd_changed_on', 'specialName'], 'safe'],
            [['requisite'], 'string'],
            [['login', 'lastname', 'type', 'identity_url', 'mail_notification'], 'string', 'max' => 255],
            [['hashed_password'], 'string', 'max' => 40],
            [['firstname'], 'string', 'max' => 30],
            [['language'], 'string', 'max' => 5],
            [['salt'], 'string', 'max' => 64],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'login' => 'Логин',
            'hashed_password' => 'Пароль',
            'firstname' => 'Имя',
            'lastname' => 'Фамилия',
            'admin' => 'Admin',
            'status' => 'Статус',
            'last_login_on' => 'Последняя авторизация',
            'language' => 'Язык',
            'auth_source_id' => 'Auth Source ID',
            'created_on' => 'Created On',
            'updated_on' => 'Updated On',
            'type' => 'Тип',
            'identity_url' => 'Identity Url',
            'mail_notification' => 'Mail Notification',
            'salt' => 'Salt',
            'must_change_passwd' => 'Must Change Passwd',
            'passwd_changed_on' => 'Passwd Changed On',
            'show_report' => 'Show Report',
            'requisite' => 'Requisite',
        ];
    }
}
