* @author Timo Hund */ abstract class AbstractFacetItemCollection extends AbstractCollection { /** * @param AbstractFacetItem $item * @return AbstractFacetItemCollection */ public function add($item) { if ($item === null) { return $this; } $this->data[$item->getCollectionKey()] = $item; return $this; } /** * @param string $value * @return AbstractFacetItem */ public function getByValue($value) { return isset($this->data[$value]) ? $this->data[$value] : null; } /** * Retrieves the count (with get prefixed to be usable in fluid). * * @return int */ public function getCount() { return $this->count(); } /** * @return AbstractFacetItemCollection */ public function getSelected() { return $this->getFilteredCopy(function(AbstractFacetItem $item) { return $item->getSelected(); }); } /** * @param array $manualSorting * @return AbstractFacetItemCollection */ public function getManualSortedCopy(array $manualSorting) { $result = clone $this; $copiedItems = $result->data; $sortedOptions = []; foreach ($manualSorting as $item) { if (isset($copiedItems[$item])) { $sortedOptions[$item] = $copiedItems[$item]; unset($copiedItems[$item]); } } // in the end all items get appended that are not configured in the manual sort order $sortedOptions = $sortedOptions + $copiedItems; $result->data = $sortedOptions; return $result; } /** * @return AbstractFacetItemCollection */ public function getReversedOrderCopy() { $result = clone $this; $result->data = array_reverse($result->data, true); return $result; } }