Your IP : 216.73.216.79


Current Path : /var/www/html/crm/models/
Upload File :
Current File : /var/www/html/crm/models/ParamList.php

<?php

namespace app\models;

use yii\helpers\ArrayHelper;
use Yii;

/**
 * This is the model class for table "param_list".
 *
 * @property int $id
 * @property string $uuid
 * @property int $cat_id
 * @property string $code
 * @property string $label
 * @property int $sort
 * @property int $status
 * @property string $created_dt
 * @property int $created_by
 * @property string $updated_dt
 * @property int $updated_by
 */
class ParamList extends \yii\db\ActiveRecord {

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

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['uuid', 'code', 'label'], 'required'],
            [['cat_id', 'sort', 'status', 'created_by', 'updated_by'], 'integer'],
            [['created_dt', 'updated_dt', 'descr'], 'safe'],
            [['label'], 'string', 'max' => 255],
            [['code'], 'string', 'max' => 10],
            [['uuid', 'code'], 'unique'],
            [['sort'], 'default', 'value' => 0],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'uuid' => 'Uuid',
            'cat_id' => 'Category',
            'code' => 'Code',
            'label' => 'Label',
            'sort' => 'Sort',
            'status' => 'Status',
            'created_dt' => 'Created Dt',
            'created_by' => 'Created By',
            'updated_dt' => 'Updated Dt',
            'updated_by' => 'Updated By',
            'descr' => 'Description',
        ];
    }

    public function getparamlist($cat_id) {
        return ArrayHelper::map(static::find()->where(['cat_id' => $cat_id, 'status' => 1])->orderBy(['sort' => SORT_ASC])->all(), 'code', 'label');
    }

    public function getparamlist2($cat_id) {
        return ArrayHelper::map(static::find()->where(['cat_id' => $cat_id, 'status' => 1])->andWhere(['<>', 'code', 'sme'])->andWhere(['<>', 'code', 'reseller'])->orderBy(['sort' => SORT_ASC])->all(), 'code', 'label');
    }

    public function getlabel($cat_id, $code) {
        if (($model = static::findOne(['cat_id' => $cat_id, 'code' => $code])) !== null) {
            return $model->label;
        }
    }

    public function getlabel2($id) {
        if (($model = static::findOne($id)) !== null) {
            return $model->label;
        }
    }

    public function getcode($cat_id, $label) {
        $output = '';
        $model = static::find()->where(['=', 'cat_id', $cat_id])->andwhere(['like', 'label', $label])->all();
        if (!empty($model)) {
            foreach ($model as $row) {
                $output = $row->code;
            }
        }
        return $output;
    }

    public function getlabelfromcodes(array $codes) {
        $array = [];
        $out = '';
        $model = static::find()->where(array('IN', 'code', $codes))->orderBy(['sort' => SORT_ASC])->all();
        if (!empty($model)) {
            foreach ($model as $row) {
                $array[] = $row->label;
            }
        }
        return $array;
    }

    // CREATE
    public function getparamlistshipping($cat_id) {
        return ArrayHelper::map(static::find()->where(['cat_id' => $cat_id, 'status' => 1])->andWhere(['<>', 'id', 385])->orderBy(['label' => SORT_ASC])->all(), 'code', 'label');
    }

    // UPDATE
    public function getshippingparamlabel($cat_id) {
        return ArrayHelper::map(static::find()->where(['cat_id' => $cat_id, 'status' => 1])->andWhere(['<>', 'id', 385])->orderBy(['label' => SORT_ASC])->all(), 'label', 'label');
    }

}