示例#1
0
 /**
  * Merges given data with current object
  *
  * @param ExtensibleData $gedcomx Assumes Gedcomx\Gedcomx or a subclass
  */
 public function embed(ExtensibleData $gedcomx)
 {
     $links = $gedcomx->getLinks();
     if ($links != null) {
         foreach ($links as $link) {
             $found = false;
             if ($link->getRel() != null) {
                 if ($this->getLinks() != null) {
                     foreach ($this->getLinks() as $target) {
                         if ($link->getRel() == $target->getRel()) {
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addLink($link);
             }
         }
     }
     $persons = $gedcomx->getPersons();
     if ($persons != null) {
         foreach ($persons as $person) {
             $found = false;
             if ($person->getId() != null) {
                 if ($this->getPersons() != null) {
                     foreach ($this->getPersons() as $target) {
                         if ($person->getId() == $target->getId()) {
                             $target->embed($person);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addPerson($person);
             }
         }
     }
     $relationships = $gedcomx->getRelationships();
     if ($relationships != null) {
         foreach ($relationships as $relationship) {
             $found = false;
             if ($relationship->getId() != null) {
                 if ($this->getRelationships() != null) {
                     foreach ($this->getRelationships() as $target) {
                         if ($relationship->getId() == $target->getId()) {
                             $target->embed($relationship);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addRelationship($relationship);
             }
         }
     }
     $sourceDescriptions = $gedcomx->getSourceDescriptions();
     if ($sourceDescriptions != null) {
         foreach ($sourceDescriptions as $sourceDescription) {
             $found = false;
             if ($sourceDescription->getId() != null) {
                 if ($this->getSourceDescriptions() != null) {
                     foreach ($this->getSourceDescriptions() as $target) {
                         if ($sourceDescription->getId() == $target->getId()) {
                             $target->embed($sourceDescription);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addSourceDescription($sourceDescription);
             }
         }
     }
     $agents = $gedcomx->getAgents();
     if ($agents != null) {
         foreach ($agents as $agent) {
             $found = false;
             if ($agent->getId() != null) {
                 if ($this->getAgents() != null) {
                     foreach ($this->getAgents() as $target) {
                         if ($agent->getId() == $target->getId()) {
                             $target->embed($agent);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addAgent($agent);
             }
         }
     }
     $events = $gedcomx->getEvents();
     if ($events != null) {
         foreach ($events as $event) {
             $found = false;
             if ($event->getId() != null) {
                 if ($this->getEvents() != null) {
                     foreach ($this->getEvents() as $target) {
                         if ($event->getId() == $target->getId()) {
                             $target->embed($event);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 addEvent(event);
             }
         }
     }
     $placeDescriptions = $gedcomx->getPlaces();
     if ($placeDescriptions != null) {
         foreach ($placeDescriptions as $placeDescription) {
             $found = false;
             if ($placeDescription->getId() != null) {
                 if ($this->getPlaces() != null) {
                     foreach ($this->getPlaces() as $target) {
                         if ($placeDescription->getId() == $target->getId()) {
                             $target->embed(placeDescription);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addPlace($placeDescription);
             }
         }
     }
     $documents = $gedcomx->getDocuments();
     if ($documents != null) {
         foreach ($documents as $document) {
             $found = false;
             if ($document->getId() != null) {
                 if ($this->getDocuments() != null) {
                     foreach ($this->getDocuments() as $target) {
                         if ($document . getId() == $target->getId()) {
                             $target->embed($document);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addDocument($document);
             }
         }
     }
     $collections = $gedcomx->getCollections();
     if ($collections != null) {
         foreach ($collections as $collection) {
             $found = false;
             if ($collection->getId() != null) {
                 if ($this->getCollections() != null) {
                     foreach ($this->getCollections() as $target) {
                         if ($collection->getId() == $target->getId()) {
                             $target->embed($collection);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addCollection($collection);
             }
         }
     }
     $fields = $gedcomx->getFields();
     if ($fields != null) {
         foreach ($fields as $field) {
             $found = false;
             if ($field->getId() != null) {
                 if ($this->getFields() != null) {
                     foreach ($this->getFields() as $target) {
                         if ($field->getId() == $target->getId()) {
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addField($field);
             }
         }
     }
     $recordDescriptors = $gedcomx->getRecordDescriptors();
     if ($recordDescriptors != null) {
         foreach ($recordDescriptors as $recordDescriptor) {
             $found = false;
             if ($recordDescriptor->getId() != null) {
                 if ($this->getRecordDescriptors() != null) {
                     foreach ($this->getRecordDescriptors() as $target) {
                         if ($recordDescriptor . getId() == $target->getId()) {
                             $target->embed($recordDescriptor);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addRecordDescriptor(recordDescriptor);
             }
         }
     }
 }