fields($fields)->orderBy($orderBy)->selectAll(EAnd(EEqual('type', !empty($itemType)?$itemType:'Category'),$rootId?(EFTS('closure', ','.$rootId.',')):false, $conditions)); $additionItems = array(); foreach($items as &$item) { if($item['id'] == $rootId) { unset($items[$item['id']]); } else if(!empty($item['thirdParentId'])) { $additionItems += $table->itemsPerPage($itemsPerPage?$itemsPerPage:2000)->fields($fields.', IF(parentId = '.$item['thirdParentId'].', '.$item['id'].', parentId) as parentId')->orderBy($orderBy)->selectAll(EAnd(EEqual('type', !empty($itemType)?$itemType:'Category'),EFTS('closure', ','.$item['thirdParentId'].','), $status?EEqual('status', 1):false)); } if($childType == 'Application') { $categoryCondition = false; if($childCategories = CTable('Item')->fields('id')->selectAll(EAnd(EFTS('closure', ','.$item['id'].','), EEqual('status', 1), EEqual('childType', 'Application'))) and sizeof($childCategories) > 1) { $categoryCondition = EIn('categoryId', array_keys($childCategories)); } else { $categoryCondition = EEqual('categoryId', $item['id']); } $item['title'] .= ' ('.CTable('Application')->count(EAnd( $categoryCondition, EEqual('status', 1), EEqual('demo', 0), EEqual('directoryListing', 1) )).')'; } else if($countTotalItems) { $totalItems = CTable($countTotalItems)->count(EAnd(EEqual('categoryId', $item['id']), EEqual('status', 1))); $item['title'] .= $totalItems?' ('.$totalItems.')':''; } if(empty($item['image'])) { $metaData = json_decode($item['metaData'],true); if(!empty($metaData['logo']) and !empty($metaData['hoverLogo'])) { $item['image'] = $metaData['logo']; $item['hoverLogo'] = $metaData['hoverLogo']; } } } $items += $additionItems; CLanguage::updateList($items, 'Item'); $items = $this->makeTree($items, $rootId, $childrenFieldName, $maxLevel, 0, $displayItems); if($excludeRoot and sizeof($items) == 1) { $items = reset($items); $items = $items['items']; } cache($cacheName, $items); return $items; } public function makeTree($items, $parent, $childrenFieldName, $maxLevel, $level = 0, $displayItems = 0){ $result = array(); $this->visitedNodes[$parent] = 1; $this->count ++; $found = false; if(($level < $maxLevel or (isset(CPage::$currentCategory['closure']) and strpos(CPage::$currentCategory['closure'], ','.$parent.',') !== false)) and !empty($items)){ $count = 0; foreach($items as $k => $v){ if(isset($v['parentId']) and !isset($this->visitedNodes[$v['id']])){ if($v['parentId'] == $parent){ $found = true; $result[$count] = $v; $result[$count]['treeLevel'] = $level; if(isset($this->closure[$parent]) and $level != 0 and $maxLevel<$level+1) { $maxLevel = $level + 2; } $result[$count][$childrenFieldName] = $this->makeTree($items, $v['id'], $childrenFieldName, $maxLevel, $level + 1, $displayItems); $count ++; } } } if($displayItems and $level >= 1 and ($count > $displayItems)) { $viewMore = array( 'id' => 0, 'title' => lang('View more'), 'treeLevel' => $level, 'url' => 'javascript:void(0);', $childrenFieldName => array_splice($result, $displayItems) ); foreach($viewMore[$childrenFieldName] as $id=>$vmi) { $viewMore[$childrenFieldName][$id]['treeLevel'] ++; } $result[$displayItems] = $viewMore; } } if($level == 0 and !$found) { $result = array(); $ref = array(); $levelItems = array(); $found = true; while($found) { $found = false; foreach($items as $key => $item){ if(!isset($ref[$item['id']])) { if(isset($items[$item['parentId']])) { if(isset($ref[$item['parentId']])) { $ref[$item['parentId']]['items'][$key] = $item; $ref[$item['id']] = &$ref[$item['parentId']]['items'][$key]; $levelItems[$item['id']] = $levelItems[$item['parentId']]+1; $found = true; } } else { $result[$item['id']] = $item; $ref[$item['id']] = &$result[$item['id']]; $levelItems[$item['id']] = 0; $found = true; } } } } } else if($maxLevel == 100 and $level == 0 and empty(CPage::$pageId)) { foreach($items as $k => $v){ if(!isset($this->visitedNodes[$v['id']])) { $count = sizeof($result); $result[$count] = $v; $result[$count]['treeLevel'] = $level; $result[$count][$childrenFieldName] = $this->makeTree($items, $v['id'], $childrenFieldName, $maxLevel, $level + 1, $displayItems); } } } return $result; } function getHTMLTree($rootId, $excludeRoot, $maxLevel,$conditions = false, $dontHaveLink = false, $class = '', $ulId = '', $childType = '', $itemType, $itemsPerPage, $siteId = '', $span = 0, $status = 0, $menuDisplay = 0, $footerDisplay = 0,$subType=false, $showIcon = false, $linkImage = false, $options = array(), $displayItems = 0, $countTotalItems = '', $useHeading = 0) { if(!is_numeric($rootId) and $rootId.'' == 'rootProductCategoryId') { $rootId = portal()->rootProductCategoryId; } if(!is_numeric($rootId) and $rootId.'' == 'accountCategoryId' and $currentAccountId = session('currentAccountId') and $currentAccount = CTable('Account')->select($currentAccountId)) { $rootId = $currentAccount['rootCategoryId']; } $tree = $this->getTree($rootId, 'id,code,title,page,url,parentId,type,childType,status,metaData'.(!$showIcon?'':',image'), false, $excludeRoot, $maxLevel,$conditions, '', false, $childType, $itemType, $itemsPerPage, $siteId, $status, $menuDisplay, $footerDisplay,false,false,$subType,false,$displayItems, $countTotalItems); if($options) { $tree = array_merge($options, $tree); } $categories = ''; $this->_makeHTMLTree($tree, $categories, $dontHaveLink, $class, $ulId, $span, $showIcon, $linkImage, 0, $useHeading); return $categories; } private function _makeHTMLTree(&$tree, &$categories, $dontHaveLink, $class, $ulId, $span, $showIcon, $linkImage, $level, $useHeading) { if($tree) { $categories .= '