/** * Adds a child and parents relationship to the current relationships collection. * * @param \Gedcomx\Extensions\FamilySearch\Platform\Tree\ChildAndParentsRelationship $chap * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,... * * @return mixed */ public function addChildAndParentsRelationship(ChildAndParentsRelationship $chap, StateTransitionOption $option = null) { $entity = new FamilySearchPlatform(); $entity->setChildAndParentsRelationships(array($chap)); $request = $this->createAuthenticatedRequest('POST', $this->getSelfUri()); return $this->stateFactory->createState('ChildAndParentsRelationshipState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken); }
/** * @link https://familysearch.org/developers/docs/api/tree/Read_Person_With_Multiple_Pending_Modifications_Activated_usecase */ public function testReadPersonWithMultiplePendingModificationsActivated() { $factory = new FamilyTreeStateFactory(); $this->collectionState($factory); /** @var Feature[] $features */ $features = array(); $request = $this->collectionState()->getClient()->createRequest("GET", "https://sandbox.familysearch.org/platform/pending-modifications"); $request->addHeader("Accept", Gedcomx::JSON_APPLICATION_TYPE); // Get all the features that are pending $response = $request->send($request); // Get each pending feature $json = json_decode($response->getBody(true), true); $fsp = new FamilySearchPlatform($json); foreach ($fsp->getFeatures() as $feature) { $features[] = $feature; } // Add every pending feature to the tree's current client $this->collectionState()->getClient()->addFilter(new ExperimentsFilter(array_map(function (Feature $feature) { return $feature->getName(); }, $features))); $state = $this->createPerson(); // Ensure a response came back $this->assertNotNull($state); $check = array(); /** @var HeaderInterface $header */ foreach ($state->getRequest()->getHeaders() as $header) { if ($header->getName() == "X-FS-Feature-Tag") { $check[] = $header; } } /** @var string $requestedFeatures */ $requestedFeatures = join(",", $check); // Ensure each requested feature was found in the request headers foreach ($features as $feature) { $this->assertTrue(strpos($requestedFeatures, $feature->getName()) !== false, $feature->getName() . " was not found in the requested features."); } }
/** * Read a preferred relationship for a user * * @param string $rel * @param string $treeUserId * @param string $personId * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,... * * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\PreferredRelationshipState * @throws GedcomxApplicationException */ protected function readPreferredRelationship($rel, $treeUserId, $personId, StateTransitionOption $option = null) { $link = $this->getLink($rel); if ($link == null || $link->getTemplate() == null) { return null; } $uri = array($link->getTemplate(), array("pid" => $personId, "uid" => $treeUserId)); $request = $this->createAuthenticatedRequest('GET', $uri, FamilySearchRequest::getMediaTypes()); $response = $this->passOptionsTo('invoke', array($request), func_get_args()); if ($response->getStatusCode() == HttpStatus::NO_CONTENT) { return null; } $fsp = new FamilySearchPlatform(json_decode($response->getBody())); if ($fsp->getChildAndParentsRelationships() != null && count($fsp->getChildAndParentsRelationships()) > 0) { return $this->stateFactory->createState('ChildAndParentsRelationshipState', $this->client, $request, $response, $this->accessToken); } else { return $this->stateFactory->createState('RelationshipState', $this->client, $request, $response, $this->accessToken); } }
/** * Performs the specified merge operation. * * @param \Gedcomx\Extensions\FamilySearch\Platform\Tree\Merge $merge * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,... * * @return PersonMergeState */ public function doMerge(Merge $merge, StateTransitionOption $option = null) { $entity = new FamilySearchPlatform(); $entity->addMerge($merge); return $this->passOptionsTo('mergeEntity', array($entity), func_get_args()); }
/** * Update a relationship passing in a Rel link to specify what needs to be updated. * * @param \Gedcomx\Extensions\FamilySearch\Platform\Tree\ChildAndParentsRelationship $relationship * @param string $rel * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,... * * @return ChildAndParentsRelationshipState */ protected function updateRelationship(ChildAndParentsRelationship $relationship, $rel, StateTransitionOption $option = null) { $target = $this->getSelfUri(); $link = $this->getLink($rel); if ($link != null && $link->getHref() != null) { $target = $link->getHref(); } $gx = new FamilySearchPlatform(); $gx->setChildAndParentsRelationships(array($relationship)); $request = $this->createAuthenticatedRequest('POST', $target, FamilySearchRequest::getMediaTypes(), null, $gx->toJson()); return $this->stateFactory->createState('ChildAndParentsRelationshipState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken); }
/** * Adds a discussion to this discussions state instance. * * @param Discussion $discussion * @param StateTransitionOption $option,... * * @return DiscussionState */ public function addDiscussion(Discussion $discussion, StateTransitionOption $option = null) { $entity = new FamilySearchPlatform(); $entity->addDiscussion($discussion); $request = $this->createAuthenticatedRequest('POST', $this->getSelfUri(), FamilySearchRequest::getMediaTypes(), null, $entity->toJson()); return $this->stateFactory->createState('DiscussionState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken); }
/** * Adds a person as a non match to this collection. * * @param Person $person * @param StateTransitionOption $option,... * * @return PersonNonMatchesState|null */ public function addNonMatch(Person $person, StateTransitionOption $option = null) { $entity = new FamilySearchPlatform(); $entity->setPersons(array($person)); return $this->passOptionsTo('post', array($entity), func_get_args()); }
/** * Get a list of valid pending modifications * * @return array Array of \Gedcomx\Extensions\FamilySearch\Feature */ public function getAvailablePendingModifications() { $uri = $this->homeState->getCollection()->getLink('pending-modifications')->getHref(); $headers = ['Accept' => Gedcomx::JSON_APPLICATION_TYPE]; $request = new Request('GET', $uri, $headers); $response = GedcomxApplicationState::send($this->client, $request); // Get each pending feature $json = json_decode($response->getBody(), true); $fsp = new FamilySearchPlatform($json); $features = array(); foreach ($fsp->getFeatures() as $feature) { $features[] = $feature; } return $features; }
/** * Updates the specified discussion. * * @param Discussion $discussion * @param string $rel * @param StateTransitionOption $option,... * * @return DiscussionState */ protected function updateInternal(Discussion $discussion, $rel, StateTransitionOption $option = null) { $target = $this->getSelfUri(); $link = $this->getLink($rel); if ($link != null && $link->getHref() != null) { $target = $link->getHref(); } $fsp = new FamilySearchPlatform(); $fsp->setDiscussions(array($discussion)); $request = $this->createAuthenticatedRequest('POST', $target, FamilySearchRequest::getMediaTypes(), null, $fsp->toJson()); return $this->stateFactory->createState('DiscussionState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken); }
/** * Adds a discussion to the current collection. * * @param Discussion $discussion * @param StateTransitionOption $option,... * * @return DiscussionState * @throws GedcomxApplicationException */ public function addDiscussion(Discussion $discussion, StateTransitionOption $option = null) { $link = $this->getLink(Rel::DISCUSSIONS); if ($link == null || $link->getHref() == null) { throw new GedcomxApplicationException("Unable to add discussion: missing link."); } $entity = new FamilySearchPlatform(); $entity->addDiscussion($discussion); $request = $this->createAuthenticatedRequest('POST', $link->getHref(), FamilySearchRequest::getMediaTypes(), null, $entity->toJson()); return $this->stateFactory->createState('DiscussionState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken); }