Linkmenu.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%linkmenu}}".
  6. *
  7. * @property int $menu_id 菜单ID
  8. * @property int $key_id 菜单标识ID
  9. * @property int $map_id 映射值
  10. * @property string $name 名称
  11. * @property int $parent_id 父ID
  12. * @property int $has_child 是否有子菜单
  13. * @property string|null $arr_child_ids 子级菜单ID集合
  14. * @property int $level 层级
  15. * @property int $list_order 排序
  16. * @property string $description 描述
  17. * @property string $settings 设置
  18. */
  19. class Linkmenu extends \app\common\models\EActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%linkmenu}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['key_id', 'map_id', 'parent_id', 'has_child', 'level', 'list_order','disabled'], 'integer'],
  35. [['name'], 'required'],
  36. [['arr_child_ids'], 'string'],
  37. [['name'], 'string', 'max' => 30],
  38. [['flagtext','description'], 'string', 'max' => 500],
  39. [['settings'], 'string', 'max' => 255],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'menu_id' => Yii::t('attr','linkmenu.menu_id'),
  49. 'key_id' => Yii::t('attr','linkmenu.key_id'),
  50. 'map_id' => Yii::t('attr','linkmenu.map_id'),
  51. 'name' => Yii::t('attr','linkmenu.name'),
  52. 'parent_id' => Yii::t('attr','linkmenu.parent_id'),
  53. 'has_child' => Yii::t('attr','linkmenu.has_child'),
  54. 'arr_child_ids' => Yii::t('attr','linkmenu.arr_child_ids'),
  55. 'level' => Yii::t('attr','linkmenu.level'),
  56. 'list_order' => Yii::t('attr','linkmenu.list_order'),
  57. 'flagtext' => Yii::t('attr','linkmenu.flagtext'),
  58. 'description' => Yii::t('attr','linkmenu.description'),
  59. 'settings' => Yii::t('attr','linkmenu.settings'),
  60. 'disabled' => Yii::t('attr','linkmenu.disabled'),
  61. ];
  62. }
  63. //递归获取父级名称和Id
  64. public static function getParentMenuRs($menu_id,$info = array())
  65. {
  66. $model = self::findOne($menu_id);
  67. $info[] = array('map_id'=>$model->map_id,'menu_id'=>$model->menu_id,'name'=>$model->name);
  68. if(!empty($model)&&$model->parent_id==0)
  69. {
  70. $info = array_reverse($info);
  71. return $info;
  72. }
  73. else
  74. {
  75. return self::getParentMenuRs($model->parent_id,$info);
  76. }
  77. }
  78. //返回格式化后的区域ID
  79. public static function getParentMenuIdRs($menu_id)
  80. {
  81. $parentMenus = self::getParentMenuRs($menu_id);
  82. $menuIds = array();
  83. if(is_array($parentMenus))foreach($parentMenus as $menu)
  84. {
  85. $menuIds[] = $menu['menu_id'];
  86. }
  87. return $menuIds;
  88. }
  89. //返回格式化后的区域名称
  90. public static function getMenuNameRs($menu_id)
  91. {
  92. $parentMenus = self::getParentMenuRs($menu_id);
  93. $nameList = array();
  94. if(is_array($parentMenus))foreach($parentMenus as $menu)
  95. {
  96. $nameList[] = $menu['name'];
  97. }
  98. return $nameList;
  99. }
  100. //返回格式化后的区域
  101. public static function getMenuNameStr($menu_id,$start=0,$glue='')
  102. {
  103. $parentMenus = self::getParentMenuRs($menu_id);
  104. $nameList = array();
  105. if(is_array($parentMenus))foreach($parentMenus as $menu)
  106. {
  107. $nameList[] = $menu['name'];
  108. }
  109. return join($glue,array_slice($nameList,$start));
  110. }
  111. }