示例#1
0
 /**
  * @param \Menus $menu
  * @param array $lists
  * @param $deep
  */
 protected function _getItems($menu, &$lists, $deep)
 {
     $deep--;
     /** @var \Menus[] $child */
     $child = $menu->getChildren();
     if ($menu->getType() == \Menus::INTERNAL) {
         $param = json_decode($menu->getRouteParam());
     }
     if (!$child && $deep > 0 && $menu->getType() == \Menus::INTERNAL && $menu->getRoute() == 'category/default' && @$param->fetch_child) {
         if (@$param->id) {
             $cat = Terms::retrieveById(@$param->id);
             if ($cat) {
                 $childCat = $cat->getChildren();
                 foreach ($childCat as $cc) {
                     $c = new \Menus();
                     $c->setType(\Menus::INTERNAL);
                     $c->setName($cc->getName());
                     $c->setRoute('category/default');
                     $c->setRouteParam('{"id":' . $cc->getId() . '}');
                     if (!is_array($child)) {
                         $child = array();
                     }
                     $child[] = $c;
                 }
             } else {
                 return;
             }
         }
     }
     if (!$child && $deep > 0 && $menu->getType() == \Menus::INTERNAL && $menu->getRoute() == 'products/category' && @$param->fetch_child) {
         if (@$param->id) {
             $cat = Terms::retrieveById(@$param->id);
             if ($cat) {
                 $childCat = $cat->getChildren();
                 foreach ($childCat as $cc) {
                     $c = new \Menus();
                     $c->setType(\Menus::INTERNAL);
                     $c->setName($cc->getName());
                     $c->setRoute('products/category');
                     $c->setRouteParam('{"id":' . $cc->getId() . '}');
                     if (!is_array($child)) {
                         $child = array();
                     }
                     $child[] = $c;
                 }
             } else {
                 return;
             }
         }
     }
     if (!$child || $deep < 0) {
         return;
     }
     if (isset($lists['items'])) {
         $lists['items'] = array();
     }
     foreach ($child as $c) {
         if ($c->getType() == \Menus::SEPARATE) {
             $url = array('#');
         } else {
             if ($c->getType() == \Menus::EXTERNAL) {
                 $url = array($c->getLink());
             } else {
                 if ($c->getType() == \Menus::INTERNAL) {
                     $param = $c->getRouteParam() ? json_decode($c->getRouteParam(), true) : array();
                     $url = array($c->getRoute());
                     foreach ($param as $k => $v) {
                         $url[$k] = $v;
                     }
                 }
             }
         }
         $_item = array('label' => $c->getName(), 'url' => $url);
         $this->_getItems($c, $_item, $deep);
         $lists['items'][] = $_item;
     }
 }