public function testSortRecords() { $this->repository->selectContentType('example01'); $this->repository->sortRecords([10 => 0, 9 => 10, 8 => 10]); $records = $this->repository->getRecords(); $this->assertEquals(10, $records[9]->getParent()); $this->assertEquals(10, $records[8]->getParent()); $this->assertEquals(0, $records[10]->getParent()); $this->assertNull($records[1]->getParent()); $this->assertNotNull($records[10]->getParent()); $this->assertEquals(1, $records[9]->getPosition()); $this->assertEquals(2, $records[8]->getPosition()); $records = $this->repository->getSortedRecords(0); $this->assertEquals([10, 9, 8], array_keys($records)); $this->assertEquals(2, $records[9]->getLevel()); $this->assertEquals(2, $records[8]->getLevel()); $this->assertEquals(1, $records[10]->getLevel()); $records = $this->repository->getSortedRecords(10); $this->assertEquals([9, 8], array_keys($records)); }
public function testReverseSortRecords() { $this->repository->selectContentType('example01'); // 1 // 2 // -- 4 // -- 8 // -- 5 // -- 6 // 3 // -- 9 // 7 $this->repository->sortRecords([1 => 0, 2 => 0, 4 => 2, 8 => 4, 5 => 4, 6 => 2, 3 => 0, 9 => 3, 7 => 0]); $records = $this->repository->getRecords(); $this->assertEquals(2, $records[6]->getParent()); $records = $this->repository->getSortedRecords(4); $this->assertEquals([8, 5], array_keys($records)); $records = $this->repository->getSortedRecords(4, true); $this->assertEquals([4, 8, 5], array_keys($records)); $records = $this->repository->getSortedRecords(4, true, 0, 1); $this->assertEquals([2, 4], array_keys($records)); $records = $this->repository->getSortedRecords(4, false, 0, 1); $this->assertEquals([2], array_keys($records)); $records = $this->repository->getSortedRecords(5, true, 0, 1); $this->assertEquals([2, 4, 5], array_keys($records)); $records = $this->repository->getSortedRecords(9, true, 0, 1); $this->assertEquals([3, 9], array_keys($records)); $records = $this->repository->getSortedRecords(4, true, 1, 1); $this->assertEquals([2, 4, 8, 5], array_keys($records)); $records = $this->repository->getSortedRecords(2, false, 1); $this->assertEquals([4, 6], array_keys($records)); $records = MenuBuilder::getBreadcrumb($this->repository, 'example01', 8); $this->assertEquals([2, 4, 8], array_keys($records)); $records = MenuBuilder::getExpandedMenu($this->repository, 'example01', 8); $this->assertEquals([1, 2, 4, 8, 5, 6, 3, 7], array_keys($records)); $records = MenuBuilder::getExpandedMenu($this->repository, 'example01', 6); $this->assertEquals([1, 2, 4, 6, 3, 7], array_keys($records)); $records = MenuBuilder::getExpandedMenu($this->repository, 'example01', 4); $this->assertEquals([1, 2, 4, 8, 5, 6, 3, 7], array_keys($records)); }
public function getSortedRecords($parentId, $includeParent = false, $depth = null, $height = 0) { if ($this->isContentQueryRecordsCaching()) { $dataDimensions = $this->getCurrentDataDimensions(); $cacheKey = $this->createCacheKey('records-sort', [$this->getCurrentContentTypeName(), $parentId, (int) $includeParent, serialize($depth), $height], $dataDimensions); $data = $this->getCacheProvider()->fetch($cacheKey); if ($data) { $data = json_decode($data, true); $recordFactory = $this->getRecordFactory(); $records = $recordFactory->createRecordsFromJSONRecordsArray($this->getCurrentContentTypeDefinition(), $data); foreach ($records as $record) { $record->setRepository($this); } return $records; } $records = parent::getSortedRecords($parentId, $includeParent, $depth, $height); $data = json_encode($records); $this->getCacheProvider()->save($cacheKey, $data, $this->contentQueryRecordsCaching); return $records; } return parent::getSortedRecords($parentId, $includeParent, $depth, $height); }
public static function getBreadcrumb(Repository $repository, $contentTypeName, $recordId) { $repository->selectContentType($contentTypeName); return $repository->getSortedRecords($recordId, true, 0, 99); }
public function getSortedRecords($parentId, $includeParent = false, $depth = null) { return parent::getSortedRecords($parentId, $includeParent, $depth); }