DvsPageVersion::collectionInstances PHP Method

collectionInstances() public method

Page version has many collection instances
public collectionInstances ( )
    public function collectionInstances()
    {
        return $this->hasMany('DvsCollectionInstance', 'page_version_id');
    }

Usage Example

Example #1
0
 /**
  * Get the list of collections for this page
  *
  * @param  DvsPageVersion $page
  * @return array($collectionName => array(CollectionFields))
  */
 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;
 }