/**
  * Returns a peer instance associated with this om.
  *
  * Since Peer classes are not to have any instance attributes, this method returns the
  * same instance for all member of this class. The method could therefore
  * be static, but this would prevent one from overriding the behavior.
  *
  * @return     CollectionPeer
  */
 public function getPeer()
 {
     if (self::$peer === null) {
         self::$peer = new CollectionPeer();
     }
     return self::$peer;
 }
Example #2
0
 /**
  * Merge collection with other collection based with fields
  *
  * @param  BaseCollection $collection      Remote collection to merge
  * @param  array $fieldsToCompare Array of fields to find the values
  *               array('field1', field2)
  *               array('local_field_name' => 'remote_field_name')
  * @param  array $fieldsToMerge   Array of fields on remote collection to merge with the local collection
  * @return void
  */
 public function mergeByFields($collection, $fieldsToCompare, $fieldsToMerge)
 {
     foreach ($this->items as $item) {
         foreach ($fieldsToCompare as $localField => $remoteField) {
             //Check if field names are diferent
             if (is_numeric($localField)) {
                 $localField = $remoteField;
             }
             //Check if field exist
             if (is_null($item->{$localField})) {
                 throw new AttributeNotFoundException("Field [{$localField}] not found in the local collection");
             }
             //Set conditions to find items
             $conditions = array($remoteField => $item->{$localField});
             $itemToFind = $collection->findByFields($conditions)->first();
             if ($itemToFind) {
                 foreach ($fieldsToMerge as $newField) {
                     //Check if field exist on remote collection
                     if (is_null($itemToFind->{$newField})) {
                         throw new AttributeNotFoundException("Field [{$newField}] not found in the remote collection");
                     }
                     $item->{$newField} = $itemToFind->{$newField};
                 }
             }
         }
     }
     return $this;
 }
Example #3
0
 public function __construct(array $items, $addons)
 {
     parent::__construct(['layouts' => ['default' => 'codex::layouts.default'], 'menus' => ['default' => 'codex::menus.header-dropdown', 'sidebar' => 'codex::menus.sidebar', 'sidebar-child' => 'codex::menus.sidebar-child', 'projects' => 'codex::menus.header-dropdown', 'versions' => 'codex::menus.header-dropdown'], 'processors' => ['header' => 'codex::processors.header', 'toc' => 'codex::processors.toc', 'buttons' => 'codex::processors.buttons'], 'document' => 'codex::document', 'error' => 'codex::error'], $addons);
 }