1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
<?php
namespace Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree;
use Gedcomx\Common\ResourceReference;
use Gedcomx\Conclusion\Relationship;
use Gedcomx\Extensions\FamilySearch\FamilySearchPlatform;
use Gedcomx\Extensions\FamilySearch\Platform\Tree\ChildAndParentsRelationship;
use Gedcomx\Rs\Client\Exception\GedcomxApplicationException;
use Gedcomx\Rs\Client\Options\StateTransitionOption;
use Gedcomx\Rs\Client\PersonState;
use Gedcomx\Rs\Client\RelationshipsState;
use Gedcomx\Types\RelationshipType;
use GuzzleHttp\Psr7\Request;
class FamilyTreeRelationshipsState extends RelationshipsState {
public function getChildAndParentsRelationships() {
if ($this->getEntity() != null) {
return $this->getEntity()->getChildAndParentsRelationships();
}
return null;
}
public function addRelationship(Relationship $relationship, StateTransitionOption $option = null)
{
if ($relationship->getKnownType() == RelationshipType::PARENTCHILD) {
throw new GedcomxApplicationException("FamilySearch Family Tree doesn't support adding parent-child relationships. You must instead add a child-and-parents relationship.");
}
return $this->passOptionsTo('addRelationship', array($relationship), func_get_args(), 'parent');
}
public function addChildAndParents(PersonState $child, PersonState $father = null, PersonState $mother = null, StateTransitionOption $option = null) {
$chap = new ChildAndParentsRelationship();
$chap->setChild(new ResourceReference($child->getSelfUri()));
if ($father != null) {
$chap->setFather(new ResourceReference($father->getSelfUri()));
}
if ($mother != null) {
$chap->setMother(new ResourceReference($mother->getSelfUri()));
}
return $this->passOptionsTo('addChildAndParentsRelationship', array($chap), func_get_args());
}
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
);
}
}