UserInfo.php 6.81 KB
<?php

    namespace common\models;

    use Yii;

    /**
     * This is the model class for table "user_info".
     * @property integer $user_id
     * @property integer $view_count
     * @property string  $busy
     * @property string  $date_visit
     * @property string  $experience
     * @property string  $rank
     * @property string  $salary
     * @property string  $job
     * @property string  $location
     * @property string  $soft
     * @property integer $user_info_id
     * @property string  $guarantee
     * @property integer $contract
     * @property integer $estimate
     * @property integer $purchase
     * @property integer $delivery
     * @property double  $prepayment
     * @property string  $about
     * @property integer $type
     */
    class UserInfo extends \yii\db\ActiveRecord
    {

        // Константа обознащающая физическое лицо
        const USER_TYPE_FIZ = 1;

        // Константа обозначающая компанию
        const USER_TYPE_COMPANY = 2;

        // Константа обозначающая, что компания/физ.лицо свободно
        const USER_STATUS_FREE = 1;

        // Константа обозначающая, что компания/физ.лицо занято
        const USER_STATUS_BUSY = 2;

        // Константа обозначающая, что компания/физ.лицо хочет стать членом МФП
        const USER_MEMBER_FALSE = 1;

        // Константа обозначающая, что компания/физ.лицо не хочет стать членом МФП
        const USER_MEMBER_TRUE = 2;

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

        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [
                    [
                        'is_customer',
                        'is_freelancer',
                    ],
                    'integer',
                ],
                [
                    [ 'date_visit' ],
                    'safe',
                ],
                [
                    [
                        'soft',
                        'about',
                        'city',
                        'country',
                        'image',
                        'poster',
                        'social_vk',
                        'social_fb',
                        'social_in',
                        'social_t',
                    ],
                    'string',
                ],
                [
                    [ 'prepayment' ],
                    'number',
                    'min' => 1,
                ],
                [
                    [ 'experience' ],
                    'integer',
                    'max' => date('Y'),
                    'min' => 1950,
                ],
                [
                    [ 'experience' ],
                    'default',
                    'value' => date('Y'),
                ],
                [
                    [
                        'rank',
                        'location',
                    ],
                    'string',
                    'max' => 50,
                ],
                [
                    [
                        'job',
                    ],
                    'string',
                    'max' => 255,
                ],
                [
                    [
                        'busy',
                        'member',
                        'contract',
                        'estimate',
                        'purchase',
                        'delivery',
                    ],
                    'boolean',
                ],
                [
                    [ 'view_count', 'busy', 'member', 'salary', 'guarantee', 'prepayment' ],
                    'default',
                    'value' => 0,
                ],
                [
                    ['salary', 'guarantee'],
                    'integer',
                    'min' => 0,
                ],
            ];
        }

        public function getBusyText()
        {
            return $this->busy ? 'Занят' : 'Свободный';
        }

        public function getLastVisit()
        {
            return \Yii::$app->formatter->asRelativeTime(new \DateTime($this->date_visit));
        }

        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'user_id'       => Yii::t('app', 'User ID'),
                'view_count'    => Yii::t('app', 'Количество просмотров'),
                'busy'          => Yii::t('app', 'Статус'),
                'date_visit'    => Yii::t('app', 'Дата визита'),
                'experience'    => Yii::t('app', 'Опыт работы'),
                'rank'          => Yii::t('app', 'Rank'),
                'salary'        => Yii::t('app', 'Зарплата'),
                'job'           => Yii::t('app', 'Место работы'),
                'location'      => Yii::t('app', 'Место расположения'),
                'soft'          => Yii::t('app', 'Работа с программами'),
                'user_info_id'  => Yii::t('app', 'User Info ID'),
                'guarantee'     => Yii::t('app', 'Гарантия качества работ'),
                'contract'      => Yii::t('app', 'Работа по договору'),
                'estimate'      => Yii::t('app', 'Предоставляете смету'),
                'purchase'      => Yii::t('app', 'Делаете сами закупку материалов'),
                'delivery'      => Yii::t('app', 'Занимаетесь сами доставкой материалов'),
                'prepayment'    => Yii::t('app', 'Минимальная предоплата за работы'),
                'about'         => Yii::t('app', 'О себе'),
                'type'          => Yii::t('app', 'Is Default'),
                'member' => Yii::t('app', 'Членство в МФП'),
                'alt_location'  => 'Город не в списке',
                'country' => Yii::t('app', 'Страна'),
                'city' => Yii::t('app', 'Город'),
                'image' => Yii::t('app', 'Аватар'),
                'poster' => Yii::t('app', 'Подложка'),
                'social_vk' => Yii::t('app', 'Vk.com'),
                'social_fb' => Yii::t('app', 'FaceBook.com'),
                'social_in' => Yii::t('app', 'LinkedIn.com'),
                'social_t' => Yii::t('app', 'Twitter.com'),
                'is_customer'   => '',
                'is_freelancer' => '',

            ];
        }
    }