Your IP : 216.73.216.79


Current Path : /var/www/html/ebookingdbkl/backend/modules/serviceApplication/models/
Upload File :
Current File : /var/www/html/ebookingdbkl/backend/modules/serviceApplication/models/ServicePic.php

<?php

namespace backend\modules\serviceApplication\models;

use Yii;
use backend\modules\serviceApplication\Module as M;
use common\models\FrontendUser;

/**
 * This is the model class for table "service_pic".
 *
 * @property int $service_id * 
 * @property int|null $pic_photo
 * @property int|null $pic_video
 * @property string|null $pic_status
 * @property string|null $pic_sorting
 * @property string|null $pic_detail
 * @property string|null $created_at
 * @property int|null $created_by
 * @property string|null $updated_at
 * @property int|null $updated_by
 */
class ServicePic extends \yii\db\ActiveRecord {

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

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['staff_id'], 'required'],
            [['created_at', 'updated_at','staff_id'], 'safe'],
            [['pic_photo', 'pic_video', 'pic_sorting', 'created_by', 'updated_by'], 'integer'],
            [['pic_detail', 'pic_status', 'created_user_type', 'updated_user_type'], 'string', 'max' => 255],
            ['pic_photo', 'either', 'params' => ['other' => 'pic_video']],
            
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'pic_id' => M::t('app', 'ServiceID'),
            'staff_id' => M::t('app', 'Staff'),
            'pic_photo' => M::t('app', 'Photo'),
            'pic_video' => M::t('app', 'Video'),
            'pic_status' => M::t('app', 'Status'),
            'pic_sorting' => M::t('app', 'Sorting'),
            'pic_detail' => M::t('app', 'Detail'),
            'created_at' => M::t('app', 'CreatedAt'),
            'created_by' => M::t('app', 'CreatedBy'),
            'created_user_type' => M::t('app', 'CreatedUser'),
            'updated_at' => M::t('app', 'UpdatedAt'),
            'updated_by' => M::t('app', 'UpdatedBy'),
            'updated_user_type' => M::t('app', 'UpdatedUser'),
        ];
    }

    public static function getListName (){


        $models = (new \yii\db\Query())
            ->select(['t1.pic_id AS picId', 't2.fullName as staffName'])
            ->from('service_pic t1')
            ->leftJoin('frontend_user t2', 't2.id=t1.staff_id')
            ->where(['t1.pic_status' => 'active'])
            ->all();

        $arr = [];
        if(!empty($models)){
            foreach($models as $model){
                $arr[$model['picId']] = $model['staffName'];
            }
        }

        return $arr;
    }

    public static function getName ($picId){
        $models = (new \yii\db\Query())
            ->select(['t1.pic_id AS picId', 't2.fullname as staffName'])
            ->from('service_pic t1')
            ->leftJoin('frontend_user t2', 't2.id=t1.staff_id')
            ->where(['t1.pic_status' => 'active', 't1.pic_id' => $picId])
            ->one();

        if(!empty($models))
            return $models['staffName'];

        return '';
    }
    
    public function either($attribute_name, $params)
    {
        if (empty($this->$attribute_name) && empty($this->{$params['other']})) {
            $this->addError($attribute_name, 'Kategori ini hendaklah dipilih.');
        }
    }
    
    
    /**
     * Gets query for [[ServicePic]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getServiceTask()
    {
        return $this->hasOne(ServicePic::className(), ['staff_id' => 'staff_id']);
    }
    /**
     * Gets query for [[ServicePic]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(FrontendUser::className(), ['id' => 'staff_id']);
    }

}