123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace app\models;
- use Yii;
- /**
- * This is the model class for table "{{%linkmenu}}".
- *
- * @property int $menu_id 菜单ID
- * @property int $key_id 菜单标识ID
- * @property int $map_id 映射值
- * @property string $name 名称
- * @property int $parent_id 父ID
- * @property int $has_child 是否有子菜单
- * @property string|null $arr_child_ids 子级菜单ID集合
- * @property int $level 层级
- * @property int $list_order 排序
- * @property string $description 描述
- * @property string $settings 设置
- */
- class Linkmenu extends \app\common\models\EActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%linkmenu}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['key_id', 'map_id', 'parent_id', 'has_child', 'level', 'list_order','disabled'], 'integer'],
- [['name'], 'required'],
- [['arr_child_ids'], 'string'],
- [['name'], 'string', 'max' => 30],
- [['flagtext','description'], 'string', 'max' => 500],
- [['settings'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'menu_id' => Yii::t('attr','linkmenu.menu_id'),
- 'key_id' => Yii::t('attr','linkmenu.key_id'),
- 'map_id' => Yii::t('attr','linkmenu.map_id'),
- 'name' => Yii::t('attr','linkmenu.name'),
- 'parent_id' => Yii::t('attr','linkmenu.parent_id'),
- 'has_child' => Yii::t('attr','linkmenu.has_child'),
- 'arr_child_ids' => Yii::t('attr','linkmenu.arr_child_ids'),
- 'level' => Yii::t('attr','linkmenu.level'),
- 'list_order' => Yii::t('attr','linkmenu.list_order'),
- 'flagtext' => Yii::t('attr','linkmenu.flagtext'),
- 'description' => Yii::t('attr','linkmenu.description'),
- 'settings' => Yii::t('attr','linkmenu.settings'),
- 'disabled' => Yii::t('attr','linkmenu.disabled'),
- ];
- }
- //递归获取父级名称和Id
- public static function getParentMenuRs($menu_id,$info = array())
- {
- $model = self::findOne($menu_id);
- $info[] = array('map_id'=>$model->map_id,'menu_id'=>$model->menu_id,'name'=>$model->name);
- if(!empty($model)&&$model->parent_id==0)
- {
- $info = array_reverse($info);
- return $info;
- }
- else
- {
- return self::getParentMenuRs($model->parent_id,$info);
- }
- }
- //返回格式化后的区域ID
- public static function getParentMenuIdRs($menu_id)
- {
- $parentMenus = self::getParentMenuRs($menu_id);
- $menuIds = array();
- if(is_array($parentMenus))foreach($parentMenus as $menu)
- {
- $menuIds[] = $menu['menu_id'];
- }
- return $menuIds;
- }
- //返回格式化后的区域名称
- public static function getMenuNameRs($menu_id)
- {
- $parentMenus = self::getParentMenuRs($menu_id);
- $nameList = array();
- if(is_array($parentMenus))foreach($parentMenus as $menu)
- {
- $nameList[] = $menu['name'];
- }
- return $nameList;
- }
- //返回格式化后的区域
- public static function getMenuNameStr($menu_id,$start=0,$glue='')
- {
- $parentMenus = self::getParentMenuRs($menu_id);
- $nameList = array();
- if(is_array($parentMenus))foreach($parentMenus as $menu)
- {
- $nameList[] = $menu['name'];
- }
- return join($glue,array_slice($nameList,$start));
- }
- }
|