function getSubCategories() { $this->getBrowseCategory(); if ($this->browseCategory) { // Set Selected Browse Category $this->browseCategory->getSubCategories(); // add subcategory information to the selected category $subCategories = array(); /** @var SubBrowseCategories $subCategory */ foreach ($this->browseCategory->subBrowseCategories as $subCategory) { // Get Needed Info about sub-category /** @var BrowseCategory $temp */ $temp = BrowseCategory::staticGet('id', $subCategory->subCategoryId); if ($temp) { $this->subCategories[] = $temp; $subCategories[] = array('label' => $temp->label, 'textId' => $temp->textId); } } if ($subCategories) { global $interface; $interface->assign('subCategories', $subCategories); $result = $interface->fetch('Search/browse-sub-category-menu.tpl'); return $result; } } }
/** * @param LocationBrowseCategory|LibraryBrowseCategory|null $localBrowseCategories * @return BrowseCategory[] */ public function getBrowseCategories($localBrowseCategories = null) { global $interface; $browseCategories = array(); $specifiedCategory = isset($_REQUEST['browseCategory']); $specifiedSubCategory = $specifiedCategory && isset($_REQUEST['subCategory']); // make a specified main browse category required if ($localBrowseCategories) { $first = key($localBrowseCategories); // get key of first category foreach ($localBrowseCategories as $index => $localBrowseCategory) { $browseCategory = new BrowseCategory(); $browseCategory->textId = $localBrowseCategory->browseCategoryTextId; if ($browseCategory->find(true)) { $browseCategories[] = clone $browseCategory; if ($specifiedCategory && $_REQUEST['browseCategory'] == $browseCategory->textId || !$specifiedCategory && $index == $first) { $selectedBrowseCategory = clone $browseCategory; //TODO needed? $interface->assign('selectedBrowseCategory', $selectedBrowseCategory); if ($specifiedSubCategory) { $selectedBrowseCategory->getSubCategories(); $validSubCategory = false; $subCategories = array(); /** @var SubBrowseCategories $subCategory */ foreach ($selectedBrowseCategory->subBrowseCategories as $subCategory) { // Get Needed Info about sub-category /** @var BrowseCategory $temp */ $temp = BrowseCategory::staticGet('id', $subCategory->subCategoryId); if ($temp) { if ($temp->textId == $_REQUEST['subCategory']) { $validSubCategory = true; } $subCategories[] = array('label' => $temp->label, 'textId' => $temp->textId); } } if ($validSubCategory) { $interface->assign('subCategoryTextId', $_REQUEST['subCategory']); $interface->assign('subCategories', $subCategories); } } } } } } else { // get All BrowseCategories $browseCategory = new BrowseCategory(); $browseCategory->find(); while ($browseCategory->fetch()) { // $browseCategory->getSubCategories(); // add subcategory information to the object $browseCategories[] = clone $browseCategory; if ($specifiedCategory && $_REQUEST['browseCategory'] == $browseCategory->textId) { $selectedBrowseCategory = clone $browseCategory; $interface->assign('selectedBrowseCategory', $selectedBrowseCategory); if ($specifiedSubCategory) { $selectedBrowseCategory->getSubCategories(); $validSubCategory = false; $subCategories = array(); /** @var SubBrowseCategories $subCategory */ foreach ($selectedBrowseCategory->subBrowseCategories as $subCategory) { // Get Needed Info about sub-category /** @var BrowseCategory $temp */ $temp = BrowseCategory::staticGet('id', $subCategory->subCategoryId); if ($temp) { if ($temp->textId == $_REQUEST['subCategory']) { $validSubCategory = true; } $subCategories[] = array('label' => $temp->label, 'textId' => $temp->textId); } } if ($validSubCategory) { $interface->assign('subCategoryTextId', $_REQUEST['subCategory']); $interface->assign('subCategories', $subCategories); } } } } } return $browseCategories; }