getChildProgram($parentID); if(count($children) === 0) return array(); $parent[] = array('id' => 0, 'icon' => 'icon-cards-view', 'text' => $lang->program->all); foreach($children as $child) { $item = array('id' => $child->id, 'icon' => 'icon-cards-view', 'text' => $child->name, 'items' => array()); if(isset($child->icon)) $item['icon'] = $child->icon; $items = $this->buildMenuTree($item['items'], $child->id); if(count($items) !== 0) { $item['items'] = $items; } else { unset($item['items']); } $parent[] = $item; } return $parent; } private function getTitle($activeKey) { global $lang; if(empty($activeKey)) return $lang->program->all; foreach($this->programs as $program) { if($program->id == $activeKey) return $program->name; } return $lang->program->all; } private function getChildProgram($id) { return array_filter($this->programs, function($program) use($id) {return $program->parent == $id;}); } protected function build() { $this->programs = (array)$this->prop('programs'); $activeKey = $this->prop('activeKey'); $link = $this->prop('link'); $leadingAngle = $this->prop('leadingAngle'); $closeLink = str_replace('{id}', '0', $link); return zui::dropmenu ( set('_id', 'programMenu'), set::className('program-menu btn'), set::defaultValue($activeKey), set::leadingAngle($leadingAngle), set::text($this->getTitle($activeKey)), set::caret(true), set::popWidth(200), set::popClass('popup text-md'), set::data(array('search' => false, 'checkIcon' => false, 'title' => data('lang.product.selectProgram'), 'link' => $link, 'data' => $this->buildMenuTree(array(), 0))) ); } }