Your IP : 216.73.216.79


Current Path : /var/www/html/sprm/backend/models/
Upload File :
Current File : /var/www/html/sprm/backend/models/MainMenu.php

<?php

namespace backend\models;

use Yii;
use common\models\Dermaga;
use asinfotrack\yii2\audittrail\behaviors\AuditTrailBehavior;

/**
 * This is the model class for table "ost_ref".
 *
 * @property integer $id
 * @property string $cat
 * @property string $code
 * @property string $descr
 * @property integer $sort
 * @property string $param1
 */
class MainMenu extends Dermaga {

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


    public function behaviors()
    {
        return [
            'audittrail'=>[
                'class'=>AuditTrailBehavior::className(),
                
                // some of the optional configurations
                'ignoredAttributes'=>['created_at','updated_at'],
                'consoleUserId'=>1, 
                'attributeOutput'=>[
                    'desktop_id'=>function ($value) {
                        $model = Desktop::findOne($value);
                        return sprintf('%s %s', $model->manufacturer, $model->device_name);
                    },
                    'last_checked'=>'datetime',
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['code', 'descr'], 'required'],
            [['sort'], 'integer'],
            [['created_at', 'updated_at', 'deleted_at'], 'safe'],
            [['cat', 'code'], 'string', 'max' => 25],
            [['descr'], 'string', 'max' => 150],
            [['param1'], 'string', 'max' => 5],
            [['icon_name'], 'string', 'max' =>50],
            [['created_by', 'updated_by'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'cat' => Yii::t('app','Category'),
            'code' => Yii::t('app','Code'),
            'descr' => Yii::t('app','Description'),
            'sort' => Yii::t('app','Order'),
            'param1' => Yii::t('app','Param1'),
            'icon_name' => Yii::t('app', 'Icon Name'),
            'created_at' => Yii::t('app','Created Date'),
        ];
    }

    public static function getList($kat, $param1 = null, $choose = true, $sort = 'descr,sort') {
        $arr2 = [];

        if ($choose) {
            // $arr2['0'] = '--Sila Pilih--';
        }

        if (empty($param1)) {
            $arr = self::find()->where("cat = '$kat'")->orderBy($sort)->all();
        } else {
            $arr = self::find()->where("cat = '$kat' AND param1 = '$param1'")->orderBy('descr,sort')->all();
        }

        foreach ($arr as $param) {
            $arr2[$param->code] = $param->descr;
        }
        
        return $arr2;
    }
    
    public function getWorkFlowStatusStart() {
        return $this->hasOne(WorkFlowStatus::className(), ['name' => 'status_start'])->andWhere(['category' => 'STATUS']);
    }

    public static function getDesc($cat, $code, $field = '') {
        $ref = self::find()->where("cat = '$cat' AND code = '$code'")->one();
        if (!is_null($ref)) {
            if ($field)
                return $ref->$field;
            else
                return $ref->descr;
        } else {
            return '';
        }
    }
    
//    public static function getAccessByModule() {
//        
//    }
    
    public function getMainMenus($default_menu='1',$hide_ind='0',$module_ind='1',$parentid='',$menucat='10'){
        if ($parentid!==''){
            $menus = Menu::find()
                ->where(['menu_parent_id'=>$parentid])
                ->andWhere(['hide_ind'=>$hide_ind])
                ->andWhere(['menucat'=>$menucat])
                ->orderBy('sort')
                ->all();
        }else{
            $menus = Menu::find()
                ->where(['default_menu'=>$default_menu])
                ->andWhere(['hide_ind'=>$hide_ind])
                ->andWhere(['module_ind'=>$module_ind])
                ->andWhere(['menucat'=>$menucat])
                ->orderBy('sort')
                ->all();
        }
        return $menus;
    }
}