. */ declare(strict_types=1); namespace Fisharebest\Webtrees; use Fisharebest\Webtrees\Functions\FunctionsCharts; use stdClass; /** * Class FactLocation */ class FactLocation extends Location { /** @var Individual */ private $individual; /** @var Fact */ private $fact; /** * FactLocation constructor. * * @param Fact $fact * @param Individual $individual */ public function __construct(Fact $fact, Individual $individual) { $this->individual = $individual; $this->fact = $fact; parent::__construct($fact->place()->getGedcomName()); $coords = $this->getCoordsFromGedcom(); if ($coords !== null) { // give priority to co-ordinates stored in gedcom $this->record->pl_lati = $coords->latitude; $this->record->pl_long = $coords->longitude; } } /** * @param string $datatype * @param int $sosa * * @return array */ public function shortSummary(string $datatype, int $sosa): array { $self = $this->individual->xref(); $parent = $this->fact->record(); $name = ''; $url = ''; $tag = $this->fact->label(); $addbirthtag = false; if ($parent instanceof Family) { //marriage $spouse = $parent->getSpouse($this->individual); if ($spouse) { $url = $spouse->url(); $name = $spouse->getFullName(); } } elseif ($parent->xref() !== $self) { //birth of a child $url = $parent->url(); $name = $parent->getFullName(); $tag = GedcomTag::getLabel('_BIRT_CHIL', $parent); } if ($datatype === 'pedigree' && $sosa > 1) { $addbirthtag = true; $tag = ucfirst(FunctionsCharts::getSosaName($sosa)); } return [ 'tag' => $tag, 'url' => $url, 'name' => $name, 'value' => $this->fact->value(), 'date' => $this->fact->date()->display(true), 'place' => $this->fact->place(), 'addtag' => $addbirthtag, ]; } /** * @return array */ public function getIconDetails(): array { $tag = $this->fact->getTag(); if (in_array($tag, Gedcom::BIRTH_EVENTS)) { $icon = [ 'color' => 'Crimson', 'name' => 'birthday-cake', ]; } elseif (in_array($tag, Gedcom::MARRIAGE_EVENTS)) { $icon = [ 'color' => 'Green', 'name' => 'venus-mars', ]; } elseif (in_array($tag, Gedcom::DEATH_EVENTS)) { $icon = [ 'color' => 'Black', 'name' => 'plus', ]; } elseif ($tag === 'CENS') { $icon = [ 'color' => 'MediumBlue', 'name' => 'users', ]; } elseif ($tag === 'RESI') { $icon = [ 'color' => 'MediumBlue', 'name' => 'home', ]; } elseif ($tag === 'OCCU') { $icon = [ 'color' => 'MediumBlue', 'name' => 'briefcase', ]; } elseif ($tag === 'GRAD') { $icon = [ 'color' => 'MediumBlue', 'name' => 'graduation-cap', ]; } elseif ($tag === 'EDUC') { $icon = [ 'color' => 'MediumBlue', 'name' => 'university', ]; } else { $icon = [ 'color' => 'Gold', 'name' => 'bullseye ', ]; } return $icon; } /** * @return string */ public function toolTip() { return $this->fact->place()->getGedcomName(); } /** * Populate this objects lat/lon values, if possible * * @return stdClass|null */ private function getCoordsFromGedcom() { $coords = null; if (!$this->fact->place()->isEmpty()) { $gedcom = $this->fact->gedcom(); $f1 = preg_match("/\d LATI (.*)/", $gedcom, $match1); $f2 = preg_match("/\d LONG (.*)/", $gedcom, $match2); if ($f1 && $f2) { $coords = (object) [ 'latitude' => $match1[1], 'longitude' => $match2[1], ]; } } return $coords; } }