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
<?php
namespace Gedcomx\Rs\Client\Util;
use Gedcomx\Gedcomx;
use Gedcomx\Rs\Client\Rel;
/**
* This class extracts specific links from Gedcomx::getPersons() and Gedcomx::getRelationships(). Each of these are lists of instances
* that derive from SupportsLinks, thus the links are pulled directly from SupportsLinks getLinks().
* It is important to note that not all links will be extracted. Only the following will be extracted by default:
* * CHILD_RELATIONSHIPS
* * CONCLUSIONS
* * EVIDENCE_REFERENCES
* * MEDIA_REFERENCES
* * NOTES
* * PARENT_RELATIONSHIPS
* * SOURCE_REFERENCES
* * SPOUSE_RELATIONSHIPS
*
* Class EmbeddedLinkLoader
*
* @package Gedcomx\Rs\Client\Util
*/
class EmbeddedLinkLoader
{
private $defaultEmbeddedLinkRels;
/**
* Constructs a new instance of EmbeddedLinkLoader with default links.
*/
public function __construct()
{
$this->defaultEmbeddedLinkRels = array(
Rel::CHILD_RELATIONSHIPS,
Rel::CONCLUSIONS,
Rel::EVIDENCE_REFERENCES,
Rel::MEDIA_REFERENCES,
Rel::NOTES,
Rel::PARENT_RELATIONSHIPS,
Rel::SOURCE_REFERENCES,
Rel::SPOUSE_RELATIONSHIPS
);
}
/**
* Gets the list of embedded links that will be extracted when loadEmbeddedLinks() is called.
*
* @return array
*/
protected function getEmbeddedLinkRels()
{
return $this->defaultEmbeddedLinkRels;
}
/**
* Return all the link objects for embedded resources
*
* @param Gedcomx $entity
*
* @return array
*/
public function loadEmbeddedLinks(Gedcomx $entity)
{
$embeddedLinks = array();
$embeddedRels = $this->getEmbeddedLinkRels();
$persons = $entity->getPersons();
if ($persons != null) {
foreach ($persons as $person) {
foreach ($embeddedRels as $rel) {
$link = $person->getLink($rel);
if ($link != null) {
$embeddedLinks[] = $link;
}
}
}
}
$relationships = $entity->getRelationships();
if ($relationships != null) {
foreach ($relationships as $relationship) {
foreach ($embeddedRels as $rel) {
$link = $relationship->getLink($rel);
if ($link != null) {
$embeddedLinks[] = $link;
}
}
}
}
return $embeddedLinks;
}
}