| Current Path : /var/www/html/lpbm/common/models/ |
| Current File : /var/www/html/lpbm/common/models/Menu.php |
<?php
namespace common\models;
use common\models\Dermaga;
use Yii;
/**
* This is the model class for table "ost_menu".
*
* @property integer $id
* @property string $menu_txt
* @property string $menu_loc
* @property integer $menu_parent_id
* @property string $default_menu
* @property integer $sort
* @property string $icon_name
* @property string $balloon_title
* @property integer $module_ind
* @property string $remarks
* @property string $hide_ind
* @property string $pic
* @property string $menucat
*/
class Menu extends Dermaga {
/**
* @inheritdoc
*/
public static function tableName() {
return 'dmg_menu';
}
/**
* @inheritdoc
*/
public function rules() {
return [
[['menu_parent_id', 'sort', 'module_ind'], 'integer'],
[['pic'], 'string'],
[['menucat', 'created_at', 'updated_at', 'deleted_at'], 'safe'],
[['menu_txt', 'menu_loc', 'balloon_title', 'remarks'], 'string', 'max' => 100],
[['default_menu', 'hide_ind'], 'string', 'max' => 1],
[['icon_name', 'created_by', 'updated_by'], 'string', 'max' => 50],
];
}
/**
* @inheritdoc
*/
public function attributeLabels() {
return [
'id' => 'ID',
'menu_txt' => 'Menu/Function',
'menu_loc' => 'Menu Location',
'menu_parent_id' => 'Main Menu',
'default_menu' => 'Default Menu',
'sort' => 'Order',
'icon_name' => 'Icon Name',
'balloon_title' => 'Balloon Title',
'module_ind' => 'Module',
'remarks' => 'Remarks',
'hide_ind' => 'Not Active?',
'pic' => 'Pic',
'menucat' => 'Kategori Menu',
];
}
public function getModules() {
return $this->hasOne(Menu::className(), ['id' => 'menu_parent_id']);
}
public function getRole() {
return $this->hasMany(Role::className(), ['menu_id' => 'id']);
}
public function getAccess() {
return $this->hasMany(StaffAccess::className(), ['role_code' => 'role_code'])
->viaTable('dmg_role_mapping', ['menu_id' => 'id']);
}
public static function getAccessByModule() {
return $this->hasMany(Menu::className(), []);
}
public function getAccessWorkFlow() {
return $this->hasMany(\backend\models\WorkFlowRole::className(), ['role_code' => 'role_code'])
->viaTable('dmg_workflow_role', ['menu_id' => 'id']);
}
public function getWorkFlowRole() {
$menu_query = Menu::find()
->select('a.menu_loc')
->from('dmg_menu a')
->innerJoin('dmg_workflow_role b', 'b.main_menu_id = a.modulecd')
->innerJoin('dmg_role_mapping c', 'b.role_code = c.role_code');
return $menu_query;
}
public function getMenuByPortfolioRole($portfolio) {
$menus = Menu::find()->joinWith([
'access' => function ($query) {
$query->andWhere(['=', 'staff_info_id', Yii::$app->user->identity->staff->id]);
},
])->where(['hide_ind' => '0', 'modulecd' => $portfolio])
->andWhere(['module_ind' => '1'])
->orderBy('sort')
->all();
return $menus;
}
public function getMenuByRole() {
$menus = Menu::find()->joinWith([
'access' => function ($query) {
$query->andWhere(['=', 'staff_info_id', Yii::$app->user->identity->staff->id]);
},
])->where(['hide_ind' => '0'])
->andWhere(['module_ind' => '1'])
->orderBy('sort')
->all();
return $menus;
}
public function getMenus($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;
}
public function displayModule() {
if ($this->module_ind == 0)
return 'No';
else
return 'Yes';
}
public function displayActive() {
if ($this->hide_ind == 0)
return 'No';
else
return 'Yes';
}
}