1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- namespace common\services;
- use common\models\BaseMenu;
- use common\util\MenuObject;
- class MenuService
- {
- /**
- * @param $info
- * @return MenuObject[]
- */
- public static function getMenuObjData($info): array
- {
- $data = [];
- $objList = [];
- foreach ($info as $value) {
- /** @var BaseMenu $value */
- $obj = new MenuObject($value);
- $objList[$obj->getId()] = $obj;
- if (is_null($obj->getPid())) {
- $data[] = $obj;
- }
- }
- foreach ($objList as $key => $obj) {
- if (!is_null($obj->getPid()) && isset($objList[$obj->getPid()])) {
- $objList[$obj->getPid()]->addChildrenToTop($obj);
- }
- }
- return $data;
- }
- }
|