Esempio n. 1
0
 /**
  * @param \Gedcomx\Source\SourceDescription   $needle
  * @param \Gedcomx\Source\SourceDescription[] $haystack
  *
  * @return bool
  */
 private function findInCollection($needle, $haystack)
 {
     $found = false;
     foreach ($haystack as $sourceDescription) {
         if ($sourceDescription->getId() == $needle->getId()) {
             $found = true;
             break;
         }
     }
     return $found;
 }
Esempio n. 2
0
 /**
  * @return \Gedcomx\Source\SourceDescription
  */
 private function createSourceDescription()
 {
     $sd = new SourceDescription();
     $citation = new SourceCitation();
     $citation->setValue("\"United States Census, 1900.\" database and digital images, FamilySearch (https://familysearch.org/: accessed 17 Mar 2012), Ethel Hollivet, 1900; citing United States Census Office, Washington, D.C., 1900 Population Census Schedules, Los Angeles, California, population schedule, Los Angeles Ward 6, Enumeration District 58, p. 20B, dwelling 470, family 501, FHL microfilm 1,240,090; citing NARA microfilm publication T623, roll 90.");
     $sd->setCitations(array($citation));
     $title = new TextValue();
     $title->setValue("1900 US Census, Ethel Hollivet");
     $sd->setTitles(array($title));
     $note = new Note();
     $note->setText("Ethel Hollivet (line 75) with husband Albert Hollivet (line 74); also in the dwelling: step-father Joseph E Watkins (line 72), mother Lina Watkins (line 73), and grandmother -- Lina's mother -- Mary Sasnett (line 76).  Albert's mother and brother also appear on this page -- Emma Hollivet (line 68), and Eddie (line 69).");
     $sd->setNotes(array($note));
     $attribution = new Attribution();
     $rr = new ResourceReference();
     $rr->setResource("https://familysearch.org/platform/users/agents/MM6M-8QJ");
     $rr->setResourceId("MM6M-8QJ");
     $attribution->setContributor($rr);
     $attribution->setModified(time());
     $attribution->setChangeMessage("This is the change message");
     $sd->setAttribution($attribution);
     return $sd;
 }
Esempio n. 3
0
 /**
  * Reads the specified collection.
  *
  * @param Collection|SourceDescription|null $collection
  * @param StateTransitionOption $options,...
  * @return CollectionState|null The collection that contains these collections.
  */
 public function readCollection($collection, StateTransitionOption $options = null)
 {
     $link = null;
     if ($collection === null) {
         $link = $this->getLink(Rel::COLLECTION);
         if ($link == null || $link->getHref() == null) {
             return null;
         }
         $link = $link->getHref();
     } else {
         if ($collection instanceof Collection) {
             $link = $collection->getLink("self");
             if ($link == null || $link->getHref() == null) {
                 return null;
             }
             $link = $link->getHref();
         } else {
             if ($collection instanceof SourceDescription) {
                 $link = $collection->getAbout();
                 if (!$link) {
                     return null;
                 }
             }
         }
     }
     $request = $this->createAuthenticatedGedcomxRequest("GET", $link);
     return $this->stateFactory->createState("CollectionState", $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }
Esempio n. 4
0
 /**
  * Adds an artifact to the collection.
  *
  * @param \Gedcomx\Rs\Client\Util\DataSource               $artifact
  * @param \Gedcomx\Source\SourceDescription                $description
  * @param \Gedcomx\Rs\Client\GedcomxApplicationState       $state
  * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
  *
  * @throws \Gedcomx\Rs\Client\Exception\GedcomxApplicationException
  * @return \Gedcomx\Rs\Client\SourceDescriptionState
  */
 public function addArtifact(DataSource $artifact, SourceDescription $description = null, GedcomxApplicationState $state = null, StateTransitionOption $option = null)
 {
     if ($state == null) {
         $state = $this;
     }
     $link = $state->getLink(Rel::ARTIFACTS);
     if ($link == null || $link->getHref() == null) {
         throw new GedcomxApplicationException(sprintf("Resource at %s doesn't support adding artifacts.", state . getUri()));
     }
     $postData = [];
     if ($artifact->isFile()) {
         $postData[] = ['name' => 'artifact', 'contents' => fopen($artifact->getFile(), 'r')];
         if ($artifact->getTitle()) {
             $postData[] = ['name' => 'title', 'contents' => $artifact->getTitle()];
         }
     } else {
         foreach ($artifact->getParameters() as $key => $value) {
             $postData[] = ['name' => $key, 'contents' => $value];
         }
     }
     if ($description != null) {
         if ($description->getTitles() != null) {
             foreach ($description->getTitles() as $value) {
                 $postData[] = ['name' => 'title', 'contents' => $value->getValue()];
             }
         }
         if ($description->getDescriptions() != null) {
             foreach ($description->getDescriptions() as $value) {
                 $postData[] = ['name' => 'description', 'contents' => $value->getValue()];
             }
         }
         if ($description->getCitations() != null) {
             foreach ($description->getCitations() as $citation) {
                 $postData[] = ['name' => 'citation', 'contents' => $value->getValue()];
             }
         }
     }
     $body = new \GuzzleHttp\Psr7\MultipartStream($postData);
     $headers = ['Content-Type' => 'multipart/form-data; boundary=' . $body->getBoundary()];
     $request = $state->createAuthenticatedGedcomxRequest('POST', $link->getHref(), $headers, null, $body);
     return $state->stateFactory->createState('SourceDescriptionState', $this->client, $request, $state->passOptionsTo('invoke', array($request), func_get_args()), $state->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);
 }