public function init($parentId) { if (isset($parentId)) { $categoryDa = new CategoryDa(); $categories = $categoryDa->getListByParentId($parentId); $children = array(); if (isset($categories) && count($categories) > 0) { foreach ($categories as $cate) { $cate->Link = base_url('danh-muc/' . $cate->Id); $cate->children = array(); if ($cate->ParentId == $parentId) { array_push($this->categories, $cate); } else { array_push($children, $cate); } } if (count($this->categories) > 0) { if (count($children) > 0) { foreach ($this->categories as $parent) { foreach ($children as $child) { if ($child->ParentId == $parent->Id) { array_push($parent->children, $child); } } } } } } } }
public function init() { $categoryDa = new CategoryDa(); $categories = $categoryDa->getLv1Categories(); if (isset($categories) && count($categories) > 0) { foreach ($categories as $cate) { $cate->listProducts = new ProductsByCategoryModel(); $check = $cate->listProducts->init($cate->Id, 4, 'NEW_OLD'); if ($check) { array_push($this->listCategories, $cate); } } } }
public function init() { $categoryDa = new CategoryDa(); $categories = $categoryDa->getCategories(); if (isset($this->categoryId)) { $cateActiveId = $categoryDa->getCategoryLv1Active($this->categoryId); } $childs = array(); if (isset($categories) && count($categories) > 0) { foreach ($categories as $cate) { $cate->CategoryUrl = base_url('/danh-muc/' . $cate->Id); if (!isset($cate->ParentId) || $cate->ParentId == "0") { if (isset($cateActiveId) && $cate->Id == $cateActiveId) { $cate->active = true; } else { $cate->active = false; } array_push($this->listCategories, $cate); } else { array_push($childs, $cate); } } if (isset($this->listCategories) && count($this->listCategories) > 0) { foreach ($this->listCategories as $parent) { $parent->listChilds = array(); foreach ($childs as $child) { if ($child->ParentId == $parent->Id) { $child->listChilds = array(); foreach ($childs as $gchild) { if ($gchild->ParentId == $child->Id) { array_push($child->listChilds, $gchild); } } array_push($parent->listChilds, $child); } } } } } }
public function init() { $categoryDa = new CategoryDa(); $categories = $categoryDa->getCategories(); if (isset($this->categoryId)) { $cateActiveId = $categoryDa->getCategoryLv1Active($this->categoryId); } $childs = array(); if (isset($categories) && count($categories) > 0) { foreach ($categories as $cate) { $cate->CategoryUrl = base_url('/danh-muc/' . $cate->Id); if (!isset($cate->ParentId) || $cate->ParentId == "0") { if (isset($cateActiveId) && $cate->Id == $cateActiveId) { $cate->active = true; } else { $cate->active = false; } array_push($this->listCategories, $cate); } else { array_push($childs, $cate); } } $providerDa = new ProviderDa(); if (isset($this->listCategories) && count($this->listCategories) > 0) { foreach ($this->listCategories as $parent) { $parent->groupChilds = array(0 => array()); $cnt = 1; $maxPages = 2; $limit = 15; $page = 0; $parent->groupChilds[0]['listItems'] = array(); $curChilds = array(); foreach ($childs as $child) { if ($child->ParentId == $parent->Id) { $child->isLv2 = true; array_push($curChilds, $child); foreach ($childs as $gchild) { if ($gchild->ParentId == $child->Id) { $gchild->isLv2 = false; array_push($curChilds, $gchild); } } } } $maxItems = count($curChilds); $realItemsPerPage = ceil($maxItems / $maxPages); $limit = max($realItemsPerPage, $limit); foreach ($curChilds as $child) { array_push($parent->groupChilds[$page]['listItems'], $child); if ($cnt < $limit) { $cnt++; } else { $cnt = 1; $page++; $parent->groupChilds[$page]['listItems'] = array(); } } $parent->providers = array(); $providers = $providerDa->getListProvidersByCateLv1($parent->Id); if (isset($providers) && count($providers) > 0) { foreach ($providers as $provider) { $provider->Link = base_url('thuong-hieu/' . $provider->Id); array_push($parent->providers, $provider); } } } } } }