コード例 #1
0
 /**
  * Builds an array of persons to be placed in the descendancy tree.
  *
  * @param \Gedcomx\Gedcomx $gx
  *
  * @return \Gedcomx\Rs\Client\Util\DescendancyNode|null
  */
 protected function buildTree(Gedcomx $gx)
 {
     $root = null;
     if ($gx->getPersons() != null && count($gx->getPersons()) > 0) {
         $rootArray = array();
         foreach ($gx->getPersons() as $person) {
             if ($person->getDisplayExtension() != null && $person->getDisplayExtension()->getDescendancyNumber() != null) {
                 $number = $person->getDisplayExtension()->getDescendancyNumber();
                 $spouse = substr($number, -2) === "-S" || substr($number, -2) === "-s";
                 if ($spouse) {
                     $number = substr($number, 0, strlen($number) - 2);
                 }
                 $coordinates = $this->parseCoordinates($number);
                 $current =& $rootArray;
                 $i = 0;
                 $node = null;
                 while ($current !== null) {
                     $coordinate = $coordinates[$i];
                     while (count($current) < $coordinate) {
                         array_push($current, null);
                     }
                     $node = $current[$coordinate - 1];
                     if ($node == null) {
                         $node = new DescendancyNode();
                         $current[$coordinate - 1] = $node;
                     }
                     unset($current);
                     if (++$i < count($coordinates)) {
                         //if we still have another generation to descend, make sure the list is initialized.
                         $children =& $node->Children;
                         if ($children == null) {
                             $children = array();
                             $node->Children = $children;
                         }
                         $current =& $children;
                     } else {
                         $current = null;
                     }
                 }
                 if ($spouse) {
                     $node->Spouse = $person;
                 } else {
                     $node->Person = $person;
                 }
             }
         }
         if (count($rootArray) > 0) {
             $root = $rootArray[0];
         }
     }
     return $root;
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
ファイル: AncestryTree.php プロジェクト: BRGWeb/gedcomx-php
 /**
  * Builds an array of persons to be placed in the ancestry tree.
  *
  * @param \Gedcomx\Gedcomx $gx
  *
  * @return array
  */
 protected function buildArray(Gedcomx $gx)
 {
     $this->ancestry = array();
     if ($gx->getPersons() != null) {
         foreach ($gx->getPersons() as $person) {
             $display = $person->getDisplayExtension();
             if ($display && $display->getAscendancyNumber()) {
                 try {
                     $number = (int) $display->getAscendancyNumber();
                     while (count($this->ancestry) < $number) {
                         array_push($this->ancestry, null);
                     }
                     $this->ancestry[$number - 1] = $person;
                 } catch (NumberFormatException $e) {
                     //fall through...
                 }
             }
         }
     }
     return $this->ancestry;
 }