| Current Path : /var/www/html/mtdc/backend/models/frontendmenu/ |
| Current File : /var/www/html/mtdc/backend/models/frontendmenu/FrontendRoleMapping.php |
<?php
namespace backend\models\frontendmenu;
use Yii;
/**
* This is the model class for table "frontend_role_mapping".
*
* @property int $id
* @property string $role_code
* @property int $menu_id
* @property int $parent_id
* @property string $created_by
* @property string $created_at
* @property string $updated_by
* @property string $updated_at
*
* @property FrontendMenu $menu
*/
class FrontendRoleMapping extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'frontend_role_mapping';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['role_code', 'menu_id', 'parent_id', 'created_by', 'created_at', 'updated_by'], 'required'],
[['menu_id', 'parent_id'], 'integer'],
[['created_at', 'updated_at', 'sort'], 'safe'],
[['role_code', 'created_by', 'updated_by'], 'string', 'max' => 255],
[['menu_id'], 'exist', 'skipOnError' => true, 'targetClass' => FrontendMenu::className(), 'targetAttribute' => ['menu_id' => 'menu_id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => Yii::t('app', 'ID'),
'role_code' => Yii::t('app', 'Role Code'),
'menu_id' => Yii::t('app', 'Menu ID'),
'parent_id' => Yii::t('app', 'Parent ID'),
'created_by' => Yii::t('app', 'Created By'),
'created_at' => Yii::t('app', 'Created At'),
'updated_by' => Yii::t('app', 'Updated By'),
'updated_at' => Yii::t('app', 'Updated At'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getMenu() {
return $this->hasOne(FrontendMenu::className(), ['menu_id' => 'menu_id']);
}
public static function nestedmenu(int $id, string $role, $i = 0) {
/* model */
$model = self::find()->where(['role_code' => $role, 'parent_id' => $id])->orderBy('sort ASC')->all();
/* increment level */
$i++;
if (!empty($model)) {
foreach ($model as $menu) {
$menu_name = '';
if (!empty($menu->menu->menu_name))
$menu_name = $menu->menu->menu_name;
echo '<div class="listmenu" style="margin-left:' . ($i * 5) . 'em">
<span>' . $menu_name . '</span>
<div class="input-group pull-right">
<a class="btn btn-default" title="' . Yii::t('app', 'To top') . '" href="index.php?r=frontendmenu/frontend-menu/level&id=' . $menu->id . '&role=' . $menu->role_code . '&pos=<&sort=DESC"><i class="fa fa-arrow-up"></i></a>
<a class="btn btn-default" title="' . Yii::t('app', 'To bottom') . '" href="index.php?r=frontendmenu/frontend-menu/level&id=' . $menu->id . '&role=' . $menu->role_code . '&pos=>&sort=ASC"><i class="fa fa-arrow-down"></i></a>
<a class="btn btn-default" title="' . Yii::t('app', 'Add Submenu') . '" href="index.php?r=frontendmenu/frontend-menu/assign-menu&parentid=' . $menu->id . '&role=' . $menu->role_code . '"><i class="fa fa-plus"></i></a>
<a class="btn btn-default" title="' . Yii::t('app', 'Delete') . '" href="index.php?r=frontendmenu/frontend-menu/roledelete&id=' . $menu->id . '" data-method="post"><i class="fa fa-trash"></i></a>
</div>
<div class="clearfix"></div>
</div>';
self::nestedmenu($menu->id, $role, $i);
}
}
return;
}
public static function checkModule($menu_id, $role_code) {
$output = 0;
if (($model = static::findOne(['menu_id' => $menu_id, 'role_code' => $role_code])) !== null) {
$output = 1;
}
return $output;
}
}