/**
  * Adds a source description the current collection of source descriptions.
  *
  * @param \Gedcomx\Source\SourceDescription $source
  * @param Options\StateTransitionOption     $option,...
  *
  * @return SourceDescriptionState|null
  */
 public function addSourceDescription(SourceDescription $source, StateTransitionOption $option = null)
 {
     $entity = new Gedcomx();
     $entity->addSourceDescription($source);
     $request = $this->createAuthenticatedGedcomxRequest('POST', $this->getSelfUri(), [], null, $entity->toJson());
     return $this->stateFactory->createState('SourceDescriptionState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }
Пример #2
0
 /**
  * Return all the link objects for embedded resources
  *
  * @param Gedcomx $entity
  *
  * @return array
  */
 public function loadEmbeddedLinks(Gedcomx $entity)
 {
     $embeddedLinks = array();
     $embeddedRels = $this->getEmbeddedLinkRels();
     $persons = $entity->getPersons();
     if ($persons != null) {
         foreach ($persons as $person) {
             foreach ($embeddedRels as $rel) {
                 $link = $person->getLink($rel);
                 if ($link != null) {
                     $embeddedLinks[] = $link;
                 }
             }
         }
     }
     $relationships = $entity->getRelationships();
     if ($relationships != null) {
         foreach ($relationships as $relationship) {
             foreach ($embeddedRels as $rel) {
                 $link = $relationship->getLink($rel);
                 if ($link != null) {
                     $embeddedLinks[] = $link;
                 }
             }
         }
     }
     return $embeddedLinks;
 }
 public static function resolveByString($ref, Gedcomx $document)
 {
     if (substr($ref, 0, 1) != "#") {
         return null;
     }
     $visitor = new FamilySearchPlatformLocalReferenceResolver(substr($ref, 1));
     $document->accept($visitor);
     return $visitor->getResource();
 }
Пример #4
0
 /**
  * Builds an array of persons to be placed in the descendancy tree.
  *
  * @param \Gedcomx\Gedcomx $gx
  *
  * @return \Gedcomx\Rs\Client\Util\DescendancyNode|null
  */
 protected function buildTree(Gedcomx $gx)
 {
     $root = null;
     if ($gx->getPersons() != null && count($gx->getPersons()) > 0) {
         $rootArray = array();
         foreach ($gx->getPersons() as $person) {
             if ($person->getDisplayExtension() != null && $person->getDisplayExtension()->getDescendancyNumber() != null) {
                 $number = $person->getDisplayExtension()->getDescendancyNumber();
                 $spouse = substr($number, -2) === "-S" || substr($number, -2) === "-s";
                 if ($spouse) {
                     $number = substr($number, 0, strlen($number) - 2);
                 }
                 $coordinates = $this->parseCoordinates($number);
                 $current =& $rootArray;
                 $i = 0;
                 $node = null;
                 while ($current !== null) {
                     $coordinate = $coordinates[$i];
                     while (count($current) < $coordinate) {
                         array_push($current, null);
                     }
                     $node = $current[$coordinate - 1];
                     if ($node == null) {
                         $node = new DescendancyNode();
                         $current[$coordinate - 1] = $node;
                     }
                     unset($current);
                     if (++$i < count($coordinates)) {
                         //if we still have another generation to descend, make sure the list is initialized.
                         $children =& $node->Children;
                         if ($children == null) {
                             $children = array();
                             $node->Children = $children;
                         }
                         $current =& $children;
                     } else {
                         $current = null;
                     }
                 }
                 if ($spouse) {
                     $node->Spouse = $person;
                 } else {
                     $node->Person = $person;
                 }
             }
         }
         if (count($rootArray) > 0) {
             $root = $rootArray[0];
         }
     }
     return $root;
 }
Пример #5
0
 /**
  * Writes the contents of this Content to an XML writer. The startElement is expected to be already provided.
  *
  * @param \XMLWriter $writer The XML writer.
  */
 public function writeXmlContents($writer)
 {
     if ($this->type) {
         $writer->writeAttribute('type', $this->type);
     }
     if ($this->gedcomx) {
         $writer->startElementNs('gx', 'gedcomx', null);
         $this->gedcomx->writeXmlContents($writer);
         $writer->endElement();
     }
 }
Пример #6
0
 /**
  * Builds an array of persons to be placed in the ancestry tree.
  *
  * @param \Gedcomx\Gedcomx $gx
  *
  * @return array
  */
 protected function buildArray(Gedcomx $gx)
 {
     $this->ancestry = array();
     if ($gx->getPersons() != null) {
         foreach ($gx->getPersons() as $person) {
             $display = $person->getDisplayExtension();
             if ($display && $display->getAscendancyNumber()) {
                 try {
                     $number = (int) $display->getAscendancyNumber();
                     while (count($this->ancestry) < $number) {
                         array_push($this->ancestry, null);
                     }
                     $this->ancestry[$number - 1] = $person;
                 } catch (NumberFormatException $e) {
                     //fall through...
                 }
             }
         }
     }
     return $this->ancestry;
 }
Пример #7
0
 /**
  * Writes the contents of this RecordSet to an XML writer. The startElement is expected to be already provided.
  *
  * @param \XMLWriter $writer The XML writer.
  */
 public function writeXmlContents(\XMLWriter $writer)
 {
     if ($this->lang) {
         $writer->writeAttribute('xml:lang', $this->lang);
     }
     parent::writeXmlContents($writer);
     if ($this->metadata) {
         $writer->startElementNs('gx', 'metadata', null);
         $this->metadata->writeXmlContents($writer);
         $writer->endElement();
     }
     if ($this->records) {
         foreach ($this->records as $i => $x) {
             $writer->startElementNs('gx', 'record', null);
             $x->writeXmlContents($writer);
             $writer->endElement();
         }
     }
 }
Пример #8
0
 /**
  * Adds a persona to the current source description using a GEDCOM X object.
  *
  * @param Gedcomx $persona
  * @param StateTransitionOption $option,...
  *
  * @return PersonState
  */
 public function addGedcomxPersona(Gedcomx $persona, StateTransitionOption $option = null)
 {
     $target = $this->getSelfUri();
     $link = $this->getLink(Rel::PERSONS);
     if ($link != null && $link->getHref() != null) {
         $target = $link->getHref();
     }
     $request = $this->createAuthenticatedGedcomxRequest('POST', $target, [], null, $persona->toJson());
     return $this->stateFactory->createState('PersonState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }
Пример #9
0
 /**
  * Update notes added to a person.
  *
  * @param \Gedcomx\Conclusion\Person                       $person
  * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
  *
  * @return \Gedcomx\Rs\Client\PersonState
  */
 public function updatePersonNotes(Person $person, StateTransitionOption $option = null)
 {
     $target = $this->getSelfUri();
     $conclusionsLink = $this->getLink(Rel::NOTES);
     if ($conclusionsLink != null && $conclusionsLink->getHref() != null) {
         $target = $conclusionsLink->getHref();
     }
     $gx = new Gedcomx();
     $gx->setPersons(array($person));
     /** @var EntityEnclosingRequest $request */
     $request = $this->createAuthenticatedGedcomxRequest('POST', $target, [], null, $gx->toJson());
     return $this->stateFactory->createState('PersonState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }
Пример #10
0
 /**
  * Merges given data with current object
  *
  * @param FamilySearchPlatform|ExtensibleData $gedcomx Assumes Gedcomx\Gedcomx or a subclass
  */
 public function embed(ExtensibleData $gedcomx)
 {
     $childRelationships = $gedcomx->getChildAndParentsRelationships();
     if ($childRelationships != null) {
         foreach ($childRelationships as $chr) {
             $found = false;
             if ($chr->getId() != null) {
                 if ($this->getChildAndParentsRelationships() != null) {
                     foreach ($this->getChildAndParentsRelationships() as $target) {
                         if ($chr->getId() == $target->getId()) {
                             $target->embed($chr);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addChildAndParentsRelationship($chr);
             }
         }
     }
     $discussions = $gedcomx->getDiscussions();
     if ($discussions != null) {
         foreach ($discussions as $d) {
             $found = false;
             if ($d->getId() != null) {
                 if ($this->getDiscussions() != null) {
                     foreach ($this->getDiscussions() as $target) {
                         if ($d->getId() == $target->getId()) {
                             $target->embed($d);
                             $found = true;
                             break;
                         }
                     }
                 }
             }
             if (!$found) {
                 $this->addDiscussion($d);
             }
         }
     }
     parent::embed($gedcomx);
 }
Пример #11
0
 /**
  * Adds a collection to the subcollection resource specified by this state instance.
  *
  * @param Collection $collection
  * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
  *
  * @throws \Gedcomx\Rs\Client\Exception\GedcomxApplicationException
  * @return \Gedcomx\Rs\Client\CollectionState|null
  */
 public function addCollection(Collection $collection, StateTransitionOption $option = null)
 {
     $link = $this->getLink(Rel::SUBCOLLECTIONS);
     if ($link == null || $link->getHref() == null) {
         throw new GedcomxApplicationException(sprintf("Collection at %s doesn't support adding subcollections.", $this->getUri()));
     }
     $entity = new Gedcomx();
     $entity->setCollections(array($collection));
     $request = $this->createAuthenticatedGedcomxRequest('POST', $link->getHref(), null, null, $entity->toJson());
     return $this->stateFactory->createState('CollectionState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }
Пример #12
0
 /**
  * Executes a POST verb request against the current REST API request and returns a state instance with the response.
  *
  * @param \Gedcomx\Gedcomx                                 $entity
  * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
  *
  * @return mixed
  */
 public function post(Gedcomx $entity, StateTransitionOption $option = null)
 {
     $headers = [];
     $accept = $this->request->getHeader("Accept");
     if (count($accept) > 0) {
         $headers["Accept"] = $accept[0];
     }
     $contentType = $this->request->getHeader("Content-Type");
     if (count($contentType) > 0) {
         $headers["Content-Type"] = $contentType[0];
     }
     if ($entity instanceof Gedcomx && !isset($headers["Content-Type"])) {
         $headers["Content-Type"] = Gedcomx::JSON_MEDIA_TYPE;
     }
     $request = $this->createAuthenticatedRequest('POST', $this->getSelfUri(), $headers, null, $entity->toJson());
     return $this->reconstruct($request, $this->passOptionsTo('invoke', array($request), func_get_args()));
 }
Пример #13
0
 /**
  * Updates the specified relationship.
  *
  * @param \Gedcomx\Conclusion\Relationship                 $relationship
  * @param                                                  $rel
  * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
  *
  * @return mixed
  */
 protected function updateRelationship(Relationship $relationship, $rel, StateTransitionOption $option = null)
 {
     $target = $this->getSelfUri();
     $link = $this->getLink($rel);
     if ($link != null && $link->getHref() != null) {
         $target = $link->getHref();
     }
     $gx = new Gedcomx();
     $gx->setRelationships(array($relationship));
     /** @var $request EntityEnclosingRequest */
     $request = $this->createAuthenticatedGedcomxRequest('POST', $target, [], null, $gx->toJson());
     return $this->stateFactory->createState('RelationshipState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }
Пример #14
0
 /**
  * Declares the match status for the current person the specified search result entry.
  *
  * @param Entry $entry
  * @param string $status
  * @param StateTransitionOption $options
  * @return PersonMatchResultsState
  */
 public function updateMatchStatus(Entry $entry, $status, StateTransitionOption $options = null)
 {
     $updateStatusUri = $this->getSelfUri();
     $entity = new Gedcomx();
     $person = new Person();
     $id = new Identifier();
     $id->setType(IdentifierType::PERSISTENT);
     $id->setValue($entry->getId());
     $person->setIdentifiers(array($id));
     $entity->setPersons(array($person));
     $request = $this->createAuthenticatedGedcomxRequest("POST", $updateStatusUri, [], null, $entity->toJson());
     $request = $request->withoutHeader("Accept");
     return $this->stateFactory->createState("PersonMatchResultsState", $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }
 /**
  * Moves the current source description to the specified collection.
  *
  * @param CollectionState $collection
  * @param StateTransitionOption $options,...
  * @return FamilySearchSourceDescriptionState|null
  */
 public function moveToCollection(CollectionState $collection, StateTransitionOption $options = null)
 {
     $link = $collection->getLink(Rel::SOURCE_DESCRIPTIONS);
     if ($link == null || $link->getHref() == null) {
         return null;
     }
     /** @var SourceDescription $me */
     $me = $this->getSourceDescription();
     if ($me == null || $me->getId() == null) {
         return null;
     }
     /** @var Gedcomx $gx */
     $gx = new Gedcomx();
     $sd = new SourceDescription();
     $sd->setId($me->getId());
     $gx->setSourceDescriptions(array($sd));
     $request = $this->createAuthenticatedRequest('POST', $link->getHref(), FamilySearchRequest::getMediaTypes(), null, $gx->toJson());
     return $this->stateFactory->createState('SourceDescriptionState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }
Пример #16
0
 /**
  * Flag the Person passed as not a match to the current person using a Person conclusion object
  *
  * @param \Gedcomx\Conclusion\Person                       $person
  * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
  *
  * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\PersonNonMatchesState|null
  */
 public function addNonMatchPerson(Person $person, StateTransitionOption $option = null)
 {
     $link = $this->getLink(Rel::NOT_A_MATCHES);
     if ($link == null || $link->getHref() == null) {
         return null;
     }
     $entity = new Gedcomx();
     $entity->addPerson($person);
     $request = $this->createAuthenticatedRequest('POST', $link->getHref(), FamilySearchRequest::getMediaTypes(), null, $entity->toJson());
     return $this->stateFactory->createState('PersonNonMatchesState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }