public findCollectionsForPageVersion ( DvsPageVersion $pageVersion ) : array($collectionName | ||
$pageVersion | DvsPageVersion | |
return | array($collectionName |
public function findCollectionsForPageVersion(\DvsPageVersion $pageVersion)
{
$collections = array();
// get a list of instances for this page
// we order it by sort so that they are in order in our $collections array already
$collectionInstances = $pageVersion->collectionInstances()->with('collectionSet')->orderBy('sort', 'ASC')->get();
// loop over the instances and add it to the collections array
foreach ($collectionInstances as $index => $collectionInstance) {
// we want to add a dynamically created key name to the instance?
// not being used in this context as far as I know of... but I'm
// leaving this here just in case we need to bring it back at some point
// $keyName = ($index + 1) . ') ' .$collectionInstance->name;
$keyName = $collectionInstance->collectionSet->name;
// make this an array if it is not already set
$collections[] = isset($collections[$keyName]) ? $collections[$keyName] : [];
// add these collection fields to this array
$collections[$keyName][] = $this->CollectionFieldsFactory->createFromCollectionInstance($collectionInstance);
}
// put these instances into a Laravel collection
foreach ($collections as $keyName => $collectionInstances) {
$collections[$keyName] = new Collection($collectionInstances);
}
return $collections;
}
/** * Wrap all fields around the page * * @param Page $page * @param $pageVersion * @return Page */ protected function wrapFieldsAroundPage($page, $pageVersion) { $language = $this->LanguageDetector->current(); $globalFields = $this->GlobalField->where('language_id', $language->id)->get(); $page = $this->wrapTheseFieldsAroundThisPage($globalFields, $page); $page = $this->wrapTheseFieldsAroundThisPage($pageVersion->fields, $page); $page = $this->wrapTheseCollectionsAroundThisPage($this->CollectionsRepository->findCollectionsForPageVersion($pageVersion), $page); return $page; }