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
<?php
namespace Gedcomx\Extensions\FamilySearch\Rs\Client;
use Gedcomx\Extensions\FamilySearch\Rs\Client\Helpers\FamilySearchRequest;
use Gedcomx\Gedcomx;
use Gedcomx\Rs\Client\CollectionState;
use Gedcomx\Rs\Client\Options\StateTransitionOption;
use Gedcomx\Rs\Client\SourceDescriptionState;
use Gedcomx\Rs\Client\StateFactory;
use Gedcomx\Source\SourceDescription;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
/**
* The FamilySearchSourceDescriptionState exposes management functions for a FamilySearch source description.
*
* Class FamilySearchSourceDescriptionState
*
* @package Gedcomx\Extensions\FamilySearch\Rs\Client
*/
class FamilySearchSourceDescriptionState extends SourceDescriptionState
{
/**
* Constructs a new FamilySearch source description state using the specified client, request, response, access token, and state factory.
*
* @param \GuzzleHttp\Client $client
* @param \GuzzleHttp\Psr7\Request $request
* @param \GuzzleHttp\Psr7\Response $response
* @param string $accessToken
* @param \Gedcomx\Rs\Client\StateFactory $stateFactory
*/
function __construct(Client $client, Request $request, Response $response, $accessToken, StateFactory $stateFactory)
{
parent::__construct($client, $request, $response, $accessToken, $stateFactory);
}
/**
* Clones the current state instance.
*
* @param \GuzzleHttp\Psr7\Request $request
* @param \GuzzleHttp\Psr7\Response $response
*
* @return \Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchSourceDescriptionState
*/
protected function reconstruct(Request $request, Response $response)
{
return new FamilySearchSourceDescriptionState($this->client, $request, $response, $this->accessToken, $this->stateFactory);
}
/**
* Reads the comments on the current source description.
*
* @param StateTransitionOption $options,...
* @return DiscussionState|null
*/
public function readComments(StateTransitionOption $options = null)
{
$link = $this->getLink(Rel::COMMENTS);
if ($link == null || $link->getHref() == null) {
return null;
}
$request = $this->createAuthenticatedRequest('GET', $link->getHref(), FamilySearchRequest::getMediaTypes());
return $this->stateFactory->createState(
'DiscussionState',
$this->client,
$request,
$this->passOptionsTo('invoke', array($request), func_get_args()),
$this->accessToken
);
}
//TODO: Create FamilysearchSourceReferencesQueryState class, add it to FamilySearchStateFactory when link is created
///**
// * @return FamilySearchSourceReferencesQueryState|null
// */
/*
public function readSourceReferencesQuery()
{
$link = $this->getLink( //TODO: Put Rel here when added );
if ($link == null || $link->getHref() = null) {
return null;
}
$request = $this->createAuthenticatedRequest('GET', $link->getHref(), FamilySearchRequest::getMediaTypes());
return $this->stateFactory->createState(
'FamilySearchSourceReferencesQueryState',
$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
);
}
}