gedcomx-php-client
  • Namespace
  • Class

Namespaces

  • Gedcomx
    • Agent
    • Atom
    • Common
    • Conclusion
    • Extensions
      • FamilySearch
        • Platform
          • Artifacts
          • Discussions
          • Tree
          • Users
        • Rs
          • Client
            • FamilyTree
            • Helpers
            • Memories
            • Util
        • Rt
        • Types
    • GedcomxFile
    • Links
    • Records
    • Rs
      • Client
        • Exception
        • Options
        • Util
    • Rt
    • Search
    • Source
    • Support
    • Types
    • Util
    • Vocab

Classes

  • Gedcomx\Agent\Address
  • Gedcomx\Agent\Agent
  • Gedcomx\Agent\OnlineAccount
  • Gedcomx\Atom\Category
  • Gedcomx\Atom\CommonAttributes
  • Gedcomx\Atom\Content
  • Gedcomx\Atom\Entry
  • Gedcomx\Atom\ExtensibleElement
  • Gedcomx\Atom\Feed
  • Gedcomx\Atom\Generator
  • Gedcomx\Atom\Person
  • Gedcomx\Common\Attribution
  • Gedcomx\Common\CustomEntity
  • Gedcomx\Common\CustomKeyedItem
  • Gedcomx\Common\EvidenceReference
  • Gedcomx\Common\ExtensibleData
  • Gedcomx\Common\Note
  • Gedcomx\Common\Qualifier
  • Gedcomx\Common\ResourceReference
  • Gedcomx\Common\TextValue
  • Gedcomx\Common\UniqueCustomKeyedItem
  • Gedcomx\Conclusion\Conclusion
  • Gedcomx\Conclusion\DateInfo
  • Gedcomx\Conclusion\DisplayProperties
  • Gedcomx\Conclusion\Document
  • Gedcomx\Conclusion\Event
  • Gedcomx\Conclusion\EventRole
  • Gedcomx\Conclusion\Fact
  • Gedcomx\Conclusion\Gender
  • Gedcomx\Conclusion\Identifier
  • Gedcomx\Conclusion\Name
  • Gedcomx\Conclusion\NameForm
  • Gedcomx\Conclusion\NamePart
  • Gedcomx\Conclusion\Person
  • Gedcomx\Conclusion\PlaceDescription
  • Gedcomx\Conclusion\PlaceDisplayProperties
  • Gedcomx\Conclusion\PlaceReference
  • Gedcomx\Conclusion\Relationship
  • Gedcomx\Conclusion\Subject
  • Gedcomx\Extensions\FamilySearch\Error
  • Gedcomx\Extensions\FamilySearch\FamilySearchPlatform
  • Gedcomx\Extensions\FamilySearch\Feature
  • Gedcomx\Extensions\FamilySearch\HealthConfig
  • Gedcomx\Extensions\FamilySearch\Platform\Artifacts\ArtifactMetadata
  • Gedcomx\Extensions\FamilySearch\Platform\Artifacts\ArtifactType
  • Gedcomx\Extensions\FamilySearch\Platform\Discussions\Comment
  • Gedcomx\Extensions\FamilySearch\Platform\Discussions\Discussion
  • Gedcomx\Extensions\FamilySearch\Platform\Error
  • Gedcomx\Extensions\FamilySearch\Platform\HealthConfig
  • Gedcomx\Extensions\FamilySearch\Platform\Tag
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\ChangeInfo
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\ChangeObjectModifier
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\ChangeObjectType
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\ChangeOperation
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\ChildAndParentsRelationship
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\DiscussionReference
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\MatchInfo
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\MatchStatus
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\Merge
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\MergeAnalysis
  • Gedcomx\Extensions\FamilySearch\Platform\Tree\MergeConflict
  • Gedcomx\Extensions\FamilySearch\Platform\Users\User
  • Gedcomx\Extensions\FamilySearch\Rs\Client\DiscussionsState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\DiscussionState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchClient
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchCollectionState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchPlaceDescriptionState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchPlaces
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchPlaceState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchSourceDescriptionState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchStateFactory
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\ChangeHistoryState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\ChildAndParentsRelationshipState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\FamilyTreeCollectionState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\FamilyTreePersonChildrenState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\FamilyTreePersonParentsState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\FamilyTreePersonState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\FamilyTreeRelationshipsState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\FamilyTreeRelationshipState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\FamilyTreeStateFactory
  • Gedcomx\Extensions\FamilySearch\Rs\Client\Helpers\FamilySearchRequest
  • Gedcomx\Extensions\FamilySearch\Rs\Client\Memories\FamilySearchMemories
  • Gedcomx\Extensions\FamilySearch\Rs\Client\PersonMatchResultsState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\PersonMergeState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\PersonNonMatchesState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\Rel
  • Gedcomx\Extensions\FamilySearch\Rs\Client\UserHistoryState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\UserState
  • Gedcomx\Extensions\FamilySearch\Rs\Client\Util\ChangeEntry
  • Gedcomx\Extensions\FamilySearch\Rs\Client\Util\ChangeHistoryPage
  • Gedcomx\Extensions\FamilySearch\Rs\Client\Util\LoggerMiddleware
  • Gedcomx\Extensions\FamilySearch\Rs\Client\Util\ThrottlingMiddleware
  • Gedcomx\Extensions\FamilySearch\Rt\FamilySearchPlatformLocalReferenceResolver
  • Gedcomx\Extensions\FamilySearch\Rt\FamilySearchPlatformModelVisitorBase
  • Gedcomx\Extensions\FamilySearch\Tag
  • Gedcomx\Extensions\FamilySearch\Types\FactType
  • Gedcomx\Gedcomx
  • Gedcomx\GedcomxFile\DefaultJsonSerialization
  • Gedcomx\GedcomxFile\DefaultXMLSerialization
  • Gedcomx\GedcomxFile\GedcomxFile
  • Gedcomx\GedcomxFile\GedcomxFileEntry
  • Gedcomx\GedcomxFile\GedcomxOutput
  • Gedcomx\GedcomxFile\Manifest
  • Gedcomx\GedcomxFile\ManifestAttribute
  • Gedcomx\Links\HypermediaEnabledData
  • Gedcomx\Links\Link
  • Gedcomx\Records\Collection
  • Gedcomx\Records\CollectionContent
  • Gedcomx\Records\Field
  • Gedcomx\Records\FieldDescriptor
  • Gedcomx\Records\FieldValue
  • Gedcomx\Records\FieldValueDescriptor
  • Gedcomx\Records\RecordDescriptor
  • Gedcomx\Records\RecordSet
  • Gedcomx\Records\RecordSetIterator
  • Gedcomx\Rs\Client\AgentState
  • Gedcomx\Rs\Client\AncestryResultsState
  • Gedcomx\Rs\Client\CollectionsState
  • Gedcomx\Rs\Client\CollectionState
  • Gedcomx\Rs\Client\DescendancyResultsState
  • Gedcomx\Rs\Client\GedcomxApplicationState
  • Gedcomx\Rs\Client\GedcomxSearchQuery
  • Gedcomx\Rs\Client\Options\CacheDirectives
  • Gedcomx\Rs\Client\Options\HeaderParameter
  • Gedcomx\Rs\Client\Options\Preconditions
  • Gedcomx\Rs\Client\Options\QueryParameter
  • Gedcomx\Rs\Client\PersonChildrenState
  • Gedcomx\Rs\Client\PersonParentsState
  • Gedcomx\Rs\Client\PersonSearchResultsState
  • Gedcomx\Rs\Client\PersonSpousesState
  • Gedcomx\Rs\Client\PersonsState
  • Gedcomx\Rs\Client\PersonState
  • Gedcomx\Rs\Client\PlaceDescriptionsState
  • Gedcomx\Rs\Client\PlaceDescriptionState
  • Gedcomx\Rs\Client\PlaceGroupState
  • Gedcomx\Rs\Client\PlaceSearchResultsState
  • Gedcomx\Rs\Client\RecordsState
  • Gedcomx\Rs\Client\RecordState
  • Gedcomx\Rs\Client\Rel
  • Gedcomx\Rs\Client\RelationshipsState
  • Gedcomx\Rs\Client\RelationshipState
  • Gedcomx\Rs\Client\SearchParameter
  • Gedcomx\Rs\Client\SourceDescriptionsState
  • Gedcomx\Rs\Client\SourceDescriptionState
  • Gedcomx\Rs\Client\StateFactory
  • Gedcomx\Rs\Client\Util\AncestryNode
  • Gedcomx\Rs\Client\Util\AncestryTree
  • Gedcomx\Rs\Client\Util\DataSource
  • Gedcomx\Rs\Client\Util\DescendancyNode
  • Gedcomx\Rs\Client\Util\DescendancyTree
  • Gedcomx\Rs\Client\Util\EmbeddedLinkLoader
  • Gedcomx\Rs\Client\Util\Embedding
  • Gedcomx\Rs\Client\Util\GedcomxBaseSearchQueryBuilder
  • Gedcomx\Rs\Client\Util\GedcomxPersonSearchQueryBuilder
  • Gedcomx\Rs\Client\Util\GedcomxPlaceSearchQueryBuilder
  • Gedcomx\Rs\Client\Util\HttpStatus
  • Gedcomx\Rs\Client\Util\RdfCollection
  • Gedcomx\Rs\Client\Util\RdfNode
  • Gedcomx\Rs\Client\Util\SearchParameter
  • Gedcomx\Rs\Client\VocabConstants
  • Gedcomx\Rs\Client\VocabElementListState
  • Gedcomx\Rs\Client\VocabElementState
  • Gedcomx\Rt\GedcomxLocalReferenceResolver
  • Gedcomx\Rt\GedcomxModelVisitorBase
  • Gedcomx\Search\ResultConfidence
  • Gedcomx\Source\CitationField
  • Gedcomx\Source\Coverage
  • Gedcomx\Source\SourceCitation
  • Gedcomx\Source\SourceDescription
  • Gedcomx\Source\SourceReference
  • Gedcomx\Types\ConfidenceLevel
  • Gedcomx\Types\DocumentType
  • Gedcomx\Types\EventRoleType
  • Gedcomx\Types\EventType
  • Gedcomx\Types\FactType
  • Gedcomx\Types\FieldType
  • Gedcomx\Types\FieldValueType
  • Gedcomx\Types\GenderType
  • Gedcomx\Types\IdentifierType
  • Gedcomx\Types\NamePartType
  • Gedcomx\Types\NameType
  • Gedcomx\Types\RecordType
  • Gedcomx\Types\RelationshipType
  • Gedcomx\Types\ResourceType
  • Gedcomx\Util\Collection
  • Gedcomx\Util\Duration
  • Gedcomx\Util\FormalDate
  • Gedcomx\Util\JsonMapper
  • Gedcomx\Util\SimpleDate
  • Gedcomx\Util\XmlMapper
  • Gedcomx\Vocab\VocabElement
  • Gedcomx\Vocab\VocabElementList

Interfaces

  • Gedcomx\Common\Attributable
  • Gedcomx\Common\HasNotes
  • Gedcomx\Conclusion\HasFacts
  • Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\PreferredRelationshipState
  • Gedcomx\Extensions\FamilySearch\Rt\FamilySearchPlatformModelVisitor
  • Gedcomx\GedcomxFile\GedcomxEntryDeserializer
  • Gedcomx\GedcomxFile\GedcomxEntrySerializer
  • Gedcomx\Links\SupportsLinks
  • Gedcomx\Records\HasFields
  • Gedcomx\Rs\Client\Options\StateTransitionOption
  • Gedcomx\Rs\Client\SupportsExtensionElements
  • Gedcomx\Rt\GedcomxModelVisitor
  • Gedcomx\Source\ReferencesSources
  • Gedcomx\Support\HasJsonKey

Exceptions

  • Gedcomx\GedcomxFile\GedcomxFileException
  • Gedcomx\Rs\Client\Exception\GedcomxApplicationException
  • Gedcomx\Rs\Client\Exception\GedcomxInvalidQueryParameter
  • Gedcomx\Rs\Client\Exception\NullValueException
  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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 
<?php

namespace Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree;

use Gedcomx\Conclusion\Person;
use Gedcomx\Extensions\FamilySearch\Rs\Client\DiscussionState;
use Gedcomx\Extensions\FamilySearch\Rs\Client\PersonMergeState;
use Gedcomx\Extensions\FamilySearch\Rs\Client\PersonNonMatchesState;
use Gedcomx\Extensions\FamilySearch\Platform\Tree\ChildAndParentsRelationship;
use Gedcomx\Extensions\FamilySearch\Platform\Tree\DiscussionReference;
use Gedcomx\Gedcomx;
use Gedcomx\Links\Link;
use Gedcomx\Rs\Client\Exception\GedcomxApplicationException;
use Gedcomx\Rs\Client\Options\StateTransitionOption;
use Gedcomx\Rs\Client\PersonState;
use Gedcomx\Extensions\FamilySearch\FamilySearchPlatform;
use Gedcomx\Extensions\FamilySearch\Rs\Client\Helpers\FamilySearchRequest;
use Gedcomx\Extensions\FamilySearch\Rs\Client\Rel;
use Gedcomx\Rs\Client\SourceDescriptionsState;
use Gedcomx\Rs\Client\Util\HttpStatus;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;

class FamilyTreePersonState extends PersonState
{
    /**
     * Create new instance of FamilyTreePersonState
     *
     * @param \GuzzleHttp\Client                                                          $client
     * @param \GuzzleHttp\Psr7\Request                                                 $request
     * @param \GuzzleHttp\Psr7\Response                                                $response
     * @param string                                                                       $accessToken
     * @param \Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\FamilyTreeStateFactory $stateFactory
     */
    public function __construct(Client $client, Request $request, Response $response, $accessToken, FamilyTreeStateFactory $stateFactory)
    {
        parent::__construct($client, $request, $response, $accessToken, $stateFactory);
    }

    /**
     * Clone this instance of FamilyTreePersonState
     *
     * @param \GuzzleHttp\Psr7\Request  $request
     * @param \GuzzleHttp\Psr7\Response $response
     *
     * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\FamilyTreePersonState
     */
    protected function  reconstruct(Request $request, Response $response)
    {
        /** @var \Gedcomx\Rs\Client\StateFactory $stateFactory */
        return new FamilyTreePersonState($this->client, $request, $response, $this->accessToken, $this->stateFactory);
    }

    /**
     * Parse the response body if we have an HTTP status that indicates one should be present.
     *
     * @return \Gedcomx\Extensions\FamilySearch\FamilySearchPlatform|null
     */
    protected function loadEntityConditionally()
    {
        if ($this->request->getMethod() =='GET'
            && ($this->response->getStatusCode() == HttpStatus::OK || $this->response->getStatusCode() == HttpStatus::GONE)
            || $this->response->getStatusCode() == HttpStatus::PRECONDITION_FAILED
        ) {
            return $this->loadEntity();
        } else {
            return null;
        }
    }

    /**
     * Parse the response body.
     *
     * @return \Gedcomx\Extensions\FamilySearch\FamilySearchPlatform
     */
    protected function loadEntity()
    {
        $json = json_decode($this->response->getBody(), true);

        return new FamilySearchPlatform($json);
    }

    /**
     * Return the Person conclusion objects on this state
     *
     * @return Person[]|null
     */
    public function getPersons()
    {
        return $this->getEntity() == null ? null : $this->getEntity()->getPersons();
    }

    /**
     * Return the ChildAndParentsRelationship objects on this state
     *
     * @return ChildAndParentsRelationship[]|null
     */
    public function getChildAndParentsRelationships()
    {
        return $this->getEntity() == null ? null : $this->getEntity()->getChildAndParentsRelationships();
    }

    /**
     * Return the ChildAndParentsRelationship objects where this person is the child
     *
     * @return ChildAndParentsRelationship[]|null
     */
    public function getRelationshipsToChildren()
    {
        $relationships = $this->getChildAndParentsRelationships();
        if ($relationships == null) {
            $relationships = array();
        }
        if (!empty($relationships)) {
            foreach ($relationships as $idx => $r) {
                if ($this->refersToMe($r->getChild())) {
                    unset($relationships[$idx]);
                }
            }
        }

        return $relationships;
    }

    /*
     * Return the ChildAndParentsRelationship objects where this person is the parent
     *
     * @return ChildAndParentsRelationship[]|null
     */
    public function getRelationshipsToParents()
    {
        $relationships = $this->getChildAndParentsRelationships();
        if ($relationships == null) {
            $relationships = array();
        }
        if (!empty($relationships)) {
            foreach ($relationships as $idx => $r) {
                if ($this->refersToMe($r->getFather()) || $this->refersToMe($r->getMother())) {
                    unset($relationships[$idx]);
                }
            }
        }

        return $relationships;
    }

    /**
     * Create a request object to pull in resource data
     *
     * @param string              $method
     * @param \Gedcomx\Links\Link $link
     *
     * @return Request
     */
    protected function createRequestForEmbeddedResource($method, Link $link)
    {
        $headers = array();
        if($link->getRel() == Rel::DISCUSSION_REFERENCES){
            $headers = FamilySearchRequest::getMediaTypes();
        }
        $request = $this->createAuthenticatedGedcomxRequest($method, $link->getHref(), $headers);

        return $request;
    }

    /**
     * Load discussion references for this person
     *
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return mixed
     */
    public function loadDiscussionReferences(StateTransitionOption $option = null)
    {
        return $this->passOptionsTo('loadEmbeddedResources', array(array(Rel::DISCUSSION_REFERENCES)), func_get_args());
    }

    /**
     * Load portraits associated with this person
     *
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return \Gedcomx\Rs\Client\SourceDescriptionsState
     */
    public function readPortraits(StateTransitionOption $option = null)
    {
        $link = $this->getLink(Rel::PORTRAITS);
        if ($link == null || $link->getHref() == null) {
            return null;
        }

        $request = $this->createAuthenticatedGedcomxRequest('GET', $link->getHref());

        return $this->stateFactory->createState(
            'SourceDescriptionsState',
            $this->client,
            $request,
            $this->passOptionsTo('invoke', array($request), func_get_args()),
            $this->accessToken
        );
    }

    /**
     * Read the portrait for this person
     *
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return \GuzzleHttp\Psr7\Response
     */
    public function readPortrait(StateTransitionOption $option = null)
    {
        $link = $this->getLink(Rel::PORTRAIT);
        if ($link == null || $link->getHref() == null) {
            return null;
        }

        $request = $this->createAuthenticatedGedcomxRequest('GET', $link->getHref());

        return $this->passOptionsTo('invoke', array($request), func_get_args());
    }

    /**
     * Add a discussion reference to this person using a state object
     *
     * @param \Gedcomx\Extensions\FamilySearch\Rs\Client\DiscussionState $discussion
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return FamilyTreePersonState
     */
    public function addDiscussionState(DiscussionState $discussion, StateTransitionOption $option = null)
    {
        $reference = new DiscussionReference();
        $reference->setResource($discussion->getSelfUri());

        return $this->passOptionsTo('addDiscussionReference', array($reference), func_get_args());
    }

    /**
     * Add a discussion reference to this person using a DiscussionReference object
     *
     * @param \Gedcomx\Extensions\FamilySearch\Platform\Tree\DiscussionReference $reference
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption                   $option,...
     *
     * @return FamilyTreePersonState
     */
    public function addDiscussionReference(DiscussionReference $reference, StateTransitionOption $option = null)
    {
        return $this->passOptionsTo('addDiscussionReferences', array(array($reference)), func_get_args());
    }

    /**
     * Add a list of discussion references to this person
     *
     * @param \Gedcomx\Extensions\FamilySearch\Platform\Tree\DiscussionReference[] $refs
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption                     $option,...
     *
     * @return FamilyTreePersonState
     */
    public function addDiscussionReferences(array $refs, StateTransitionOption $option = null)
    {
        return $this->passOptionsTo('updateDiscussionReferences', array($refs), func_get_args());
    }

    /**
     * Update a discussion reference on this person
     *
     * @param \Gedcomx\Extensions\FamilySearch\Platform\Tree\DiscussionReference $reference
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption                   $option,...
     *
     * @return FamilyTreePersonState
     */
    public function updateDiscussionReference(DiscussionReference $reference, StateTransitionOption $option = null)
    {
        return $this->passOptionsTo('updateDiscussionReferences', array(array($reference)), func_get_args());
    }

    /**
     * Update a list of discussion references on this person
     *
     * @param \Gedcomx\Extensions\FamilySearch\Platform\Tree\DiscussionReference[] $refs
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption                     $option,...
     *
     * @return FamilyTreePersonState
     */
    public function updateDiscussionReferences(array $refs, StateTransitionOption $option = null)
    {
        $person = $this->createEmptySelf();
        foreach ($refs as $ref) {
            $person->addExtensionElement($ref);
        }

        return $this->passOptionsTo('updatePersonDiscussionReferences', array($person), func_get_args());
    }

    /**
     * Update the discussion references on a Person object
     *
     * @param \Gedcomx\Conclusion\Person                       $person
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return FamilyTreePersonState
     */
    public function updatePersonDiscussionReferences(Person $person, StateTransitionOption $option = null)
    {
        $target = $this->getSelfUri();
        $link = $this->getLink(Rel::DISCUSSION_REFERENCES);
        if ($link != null && $link->getHref() != null) {
            $target = $link->getHref();
        }

        $gx = new Gedcomx();
        $gx->setPersons(array($person));
        $request = $this->createAuthenticatedRequest('POST', $target, FamilySearchRequest::getMediaTypes(), null, $gx->toJson());

        return $this->stateFactory->createState(
            'PersonState',
            $this->client,
            $request,
            $this->passOptionsTo('invoke', array($request), func_get_args()),
            $this->accessToken
        );
    }

    /**
     * Delete a discussion reference
     *
     * @param \Gedcomx\Extensions\FamilySearch\Platform\Tree\DiscussionReference $reference
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @throws \Gedcomx\Rs\Client\Exception\GedcomxApplicationException
     * @return FamilyTreePersonState
     */
    public function  deleteDiscussionReference(DiscussionReference $reference, StateTransitionOption $option = null)
    {
        $link = null;
        if ($reference->getLinks() != null) {
            $link = $reference->getLink(Rel::DISCUSSION_REFERENCE);
            if ($link == null) {
                $link = $reference->getLink(Rel::SELF);
            }
        }
        if ($link == null) {
            $link = new Link();
            $link->setHref($reference->getResource());
        }
        if ($link == null || $link->getHref() == null) {
            throw new GedcomxApplicationException("Discussion reference cannot be deleted: missing link.");
        }

        $request = $this->createAuthenticatedRequest('DELETE', $link->getHref(), FamilySearchRequest::getMediaTypes());

        return $this->stateFactory->createState(
            'PersonState',
            $this->client,
            $request,
            $this->passOptionsTo('invoke', array($request), func_get_args()),
            $this->accessToken);
    }

    /**
     * Read the child and parent relationships for this person
     *
     * @param ChildAndParentsRelationship $relationship
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return ChildAndParentsRelationshipState
     */
    public function readChildAndParentsRelationship(ChildAndParentsRelationship $relationship, StateTransitionOption $option = null)
    {
        $link = $relationship->getLink(Rel::RELATIONSHIP);
        if ($link == null) {
            $link = $relationship->getLink(Rel::SELF);
        }
        if ($link == null || $link->getHref() == null) {
            return null;
        }

        $request = $this->createAuthenticatedRequest('GET', $link->getHref(), FamilySearchRequest::getMediaTypes());

        return $this->stateFactory->createState(
            'ChildAndParentsRelationshipState',
            $this->client,
            $request,
            $this->passOptionsTo('invoke', array($request), func_get_args()),
            $this->accessToken
        );
    }

    /**
     * Read the change history for this person
     *
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return ChangeHistoryState
     */
    public function  readChangeHistory(StateTransitionOption $option = null)
    {
        $link = $this->getLink(Rel::CHANGE_HISTORY);
        if ($link == null || $link->getHref() == null) {
            return null;
        }

        $request = $this->createAuthenticatedFeedRequest('GET', $link->getHref());

        return $this->stateFactory->createState(
            'ChangeHistoryState',
            $this->client,
            $request,
            $this->passOptionsTo('invoke', array($request), func_get_args()),
            $this->accessToken
        );
    }

    /**
     * Get the person records flagged as possible matches to this record
     *
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\PersonMatchResultsState
     */
    public function readMatches(StateTransitionOption $option = null)
    {
        $link = $this->getLink(Rel::MATCHES);
        if ($link == null || $link->getHref() == null) {
            return null;
        }

        $request = $this->createAuthenticatedFeedRequest('GET', $link->getHref());

        return $this->stateFactory->createState(
            'PersonMatchResultsState',
            $this->client,
            $request,
            $this->passOptionsTo('invoke', array($request), func_get_args()),
            $this->accessToken
        );
    }

    /**
     * Read persons that have been marked as not a match for this person
     *
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $options
     *
     * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\PersonNonMatchesState
     */
    public function readNonMatches(StateTransitionOption $options = null)
    {
        $link = $this->getLink(Rel::NOT_A_MATCHES);
        if ($link == null || $link->getHref() == null) {
            return null;
        }

        $request = $this->createAuthenticatedRequest('GET', $link->getHref(), FamilySearchRequest::getMediaTypes());

        return $this->stateFactory->createState(
            'PersonNonMatchesState',
            $this->client,
            $request,
            $this->passOptionsTo('invoke', array($request), func_get_args()),
            $this->accessToken
        );
    }

    /**
     * Restore this person if it has been deleted
     *
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return FamilyTreePersonState
     */
    public function restore(StateTransitionOption $option = null)
    {
        $link = $this->getLink(Rel::RESTORE);
        if ($link == null || $link->getHref() == null) {
            return null;
        }

        $request = $this->createAuthenticatedRequest('POST', $link->getHref(), FamilySearchRequest::getMediaTypes());

        return $this->stateFactory->createState(
            'PersonState',
            $this->client,
            $request,
            $this->passOptionsTo('invoke', array($request), func_get_args()),
            $this->accessToken
        );
    }

    /**
     * Reads merge options for merging the candidate with the current person
     *
     * @param FamilyTreePersonState                            $candidate
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\PersonMergeState
     */
    public function readMergeOptions(FamilyTreePersonState $candidate, StateTransitionOption $option = null)
    {
        return $this->passOptionsTo('transitionToPersonMerge', array('OPTIONS', $candidate), func_get_args());
    }

    /**
     * Reads the merge analysis resulting from comparing the current person with the candidate
     *
     * @param FamilyTreePersonState                            $candidate
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\PersonMergeState
     */
    public function readMergeAnalysis(FamilyTreePersonState $candidate, StateTransitionOption $option = null)
    {
        return $this->passOptionsTo('transitionToPersonMerge', array('GET', $candidate), func_get_args());
    }

    /**
     * Processes the request for merge analysis
     *
     * @param string                                           $method
     * @param FamilyTreePersonState                            $candidate
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
     *
     * @throws \InvalidArgumentException
     * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\PersonMergeState
     */
    protected function transitionToPersonMerge($method, FamilyTreePersonState $candidate, StateTransitionOption $option = null)
    {
        $link = $this->getLink(Rel::MERGE);
        if ($link == null || $link->getTemplate() == null) {
            return null;
        }

        $person = $this->getPerson();
        if ($person == null || $person->getId() == null) {
            throw new \InvalidArgumentException ("Cannot read merge options: no person id available.");
        }
        $personId = $person->getId();

        $person = $candidate->getPerson();
        if ($person == null || $person->getId() == null) {
            throw new \InvalidArgumentException ("Cannot read merge options: no person id provided on the candidate.");
        }
        $candidateId = $person->getId();

        $uri = array(
            $link->getTemplate(),
            array(
                "pid" => $personId,
                "dpid" => $candidateId
            )
        );

        $request = $this->createAuthenticatedRequest($method, $uri, FamilySearchRequest::getMediaTypes());

        return $this->stateFactory->createState(
            'PersonMergeState',
            $this->client,
            $request,
            $this->passOptionsTo('invoke', array($request), func_get_args()),
            $this->accessToken
        );
    }

    /**
     * Flag the Person passed as not a match to the current person using a state object
     *
     * @param FamilyTreePersonState                            $person
     * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option ,..
     *
     * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\PersonNonMatchesState
     */
    public function addNonMatchState(FamilyTreePersonState $person, StateTransitionOption $option = null)
    {
        return $this->passOptionsTo('addNonMatchPerson', array($person->getPerson()), func_get_args());
    }

    /**
     * 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
        );
    }
}
gedcomx-php-client API documentation generated by ApiGen