Last active
February 12, 2016 14:42
-
-
Save wizhippo/ef057ee0d3c161458f0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
protected function addLocationWithChildrenToMenu(ItemInterface $menu, Location $location, $depth = 1, $skip = true) | |
{ | |
if (!$depth || $location->invisible) { | |
return $menu; | |
} | |
if ($skip) { | |
$childMenu = $menu; | |
} else { | |
$childMenu = $this->addLocationToMenu($menu, $location); | |
} | |
$query = new LocationQuery( | |
[ | |
'query' => new Criterion\LogicalAnd( | |
[ | |
new Criterion\ParentLocationId($location->id), | |
new Criterion\Visibility(Criterion\Visibility::VISIBLE), | |
new Criterion\LanguageCode($this->configResolver->getParameter('languages')), | |
new Criterion\ContentTypeIdentifier($this->identifierList) | |
] | |
) | |
] | |
); | |
$query->sortClauses = [$this->criteriaHelper->getLocationSortClauseBySortField($location->sortField, $location->sortOrder)]; | |
$childLocationList = $this->searchService->findLocations($query); | |
foreach ($childLocationList->searchHits as $searchHit) { | |
$childLocation = $searchHit->valueObject; | |
$this->addLocationToMenu($childMenu, $childLocation); | |
$this->addLocationWithChildrenToMenu($childMenu, $childLocation, $depth - 1, false); | |
} | |
return $menu; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function getLocationSortClauseBySortField($sortField, $sortOrder = Location::SORT_ORDER_ASC) | |
{ | |
$sortOrder = $sortOrder == Location::SORT_ORDER_DESC ? Query::SORT_DESC : Query::SORT_ASC; | |
switch ($sortField) { | |
case Location::SORT_FIELD_PATH: | |
return new SortClause\Location\Path($sortOrder); | |
case Location::SORT_FIELD_PUBLISHED: | |
return new SortClause\DatePublished($sortOrder); | |
case Location::SORT_FIELD_MODIFIED: | |
return new SortClause\DateModified($sortOrder); | |
case Location::SORT_FIELD_SECTION: | |
return new SortClause\SectionIdentifier($sortOrder); | |
case Location::SORT_FIELD_DEPTH: | |
return new SortClause\Location\Depth($sortOrder); | |
//@todo: sort clause not yet implemented | |
// case Location::SORT_FIELD_CLASS_IDENTIFIER: | |
//@todo: sort clause not yet implemented | |
// case Location::SORT_FIELD_CLASS_NAME: | |
case Location::SORT_FIELD_PRIORITY: | |
return new SortClause\Location\Priority($sortOrder); | |
case Location::SORT_FIELD_NAME: | |
return new SortClause\ContentName($sortOrder); | |
//@todo: sort clause not yet implemented | |
// case Location::SORT_FIELD_MODIFIED_SUBNODE: | |
case Location::SORT_FIELD_NODE_ID: | |
return new SortClause\Location\Id($sortOrder); | |
case Location::SORT_FIELD_CONTENTOBJECT_ID: | |
return new SortClause\ContentId($sortOrder); | |
default: | |
return new SortClause\Location\Path($sortOrder); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment