示例#1
0
 public function getPedigreeMapData()
 {
     $places = array();
     $this->iterateFamilies('getPlaces', $places);
     $this->stdPlaces = PlaceSearcher::getPlaceTitleLatLong($places);
     $eventXml = '';
     $this->iterateFamilies('getMapData', $eventXml);
     return $eventXml;
 }
示例#2
0
    public function OutputJSONData()
    {
        $places = $this->getPlaces();
        $this->stdPlaces = PlaceSearcher::getPlaceTitleLatLong($places);
        //print_r($this->families);#for debug
        //print_r($this->stdPlaces);#for debug
        $persons = array();
        $extras = array();
        print "{\n\t\"items\":[";
        $first = true;
        // we go through all the families and create a JSON Family object from each
        // we add to the persons array going through it
        // which we use down below to make a bunch of JSON Person objects
        // we also add to an event array containing marriages, deaths, and births
        // each event has a place and a date
        foreach ($this->families as $family) {
            if ($first) {
                $first = false;
            } else {
                print ',';
            }
            // lot of work for a dumb comma
            print "\n\t\t{";
            print "\n\t\t\ttype: 'Family'";
            print ",\n\t\t\tlabel: '" . str_replace("'", "\\'", $family['title']) . "'";
            $title = Title::newFromText($family['title'], NS_FAMILY);
            $url = $title->getLocalURL();
            print ",\n\t\t\tURL: '{$url}'";
            $id = $this->counter++;
            $extras[] = @array('id' => $id, 'URL' => $url, 'Family' => $family['title'], 'type' => 'Marriage', 'Date' => $family['marriagedate'], 'Place' => $family['marriageplace']);
            print ",\n\t\t\tMarriage: '{$id}'";
            if (isset($family['husband']) && $family['husband'] != "UNKNOWN") {
                $family['husband']['family'] = $family['title'];
                $persons[$family['husband']['title']] = $family['husband'];
            }
            if (isset($family['wife']) && $family['wife'] != "UNKNOWN") {
                $family['wife']['family'] = $family['title'];
                $persons[$family['wife']['title']] = $family['wife'];
            }
            if (isset($family['children'])) {
                $count = count($family['children']);
                print ",\n\t\t\tChildCount: {$count}";
                foreach ($family['children'] as $child) {
                    $child['family'] = $family['title'];
                    $child['siblingCount'] = $count - 1;
                    $persons[$child['title']] = $child;
                }
            }
            print "\n\t\t}";
        }
        foreach ($persons as $person) {
            print ",\n\t\t{";
            print "\n\t\t\ttype: 'Person'";
            print ",\n\t\t\tlabel: '" . str_replace("'", "\\'", $person['title']) . "'";
            $title = Title::newFromText($person['title'], NS_PERSON);
            $url = $title->getLocalURL();
            print ",\n\t\t\tURL: '{$url}'";
            print ",\n\t\t\tFamily: '" . str_replace("'", "\\'", $person['family']) . "'";
            if (isset($person['siblingCount'])) {
                print ",\n\t\t\tSiblingCount: " . $person['siblingCount'];
            }
            $arr = array();
            preg_match('/(.*)\\s+(\\S+)\\s+(\\(\\S+\\))/', $person['title'], $arr);
            if (isset($person['given']) && strlen($person['given']) > 0) {
                print ",\n\t\t\tGiven: '" . str_replace("'", "\\'", $person['given']) . "'";
            } elseif (count($arr) == 4 && strlen($arr[1]) > 0) {
                print ",\n\t\t\tGiven: '" . str_replace("'", "\\'", trim($arr[1])) . "'";
            }
            if (isset($person['surname']) && strlen($person['surname']) > 0) {
                print ",\n\t\t\tSurname: '" . str_replace("'", "\\'", $person['surname']) . "'";
            } elseif (count($arr) == 4 && strlen($arr[2]) > 0) {
                print ",\n\t\t\tSurname: '" . str_replace("'", "\\'", trim($arr[2])) . "'";
            }
            $id = $this->counter++;
            $extras[] = @array('id' => $id, 'URL' => $url, 'Person' => $person['title'], 'Family' => $person['family'], 'type' => 'Birth', 'Date' => $person['birthdate'], 'Place' => $person['birthplace']);
            print ",\n\t\t\tBirth: '{$id}'";
            $id = $this->counter++;
            $extras[] = @array('id' => $id, 'URL' => $url, 'Person' => $person['title'], 'Family' => $person['family'], 'type' => 'Death', 'Date' => $person['deathdate'], 'Place' => $person['deathplace']);
            print ",\n\t\t\tDeath: '{$id}'";
            print "\n\t\t}";
        }
        foreach ($extras as $extra) {
            print ",\n\t\t{";
            print "\n\t\t\ttype: '" . $extra['type'] . "'";
            print ",\n\t\t\tid: '" . $extra['id'] . "'";
            print ",\n\t\t\tURL: '" . $extra['URL'] . "'";
            $label = '';
            if (isset($extra['Place']) && strlen($extra['Place']) > 0) {
                $place = $this->cleanPlace($extra['Place']);
                if (strlen($place) > 0) {
                    print ",\n\t\t\tLocation: '" . str_replace("'", "\\'", $this->formatPlace($place)) . "'";
                    if (isset($this->stdPlaces[$place])) {
                        // this should be unnecessary, but there appears to be a bug
                        print ",\n\t\t\tLatLon: '" . $this->stdPlaces[$place]['lat'] . ',' . $this->stdPlaces[$place]['lon'] . "'";
                    }
                    $pos = strpos($place, ',');
                    if ($pos >= 0) {
                        $label .= str_replace("'", "\\'", substr($place, 0, $pos));
                    } else {
                        $label .= str_replace("'", "\\'", $place);
                    }
                    $label .= ': ';
                }
            }
            if (isset($extra['Person'])) {
                if (isset($extra['Family'])) {
                    print ",\n\t\t\tFamily: '" . str_replace("'", "\\'", $extra['Family']) . "'";
                }
                print ",\n\t\t\tPerson: '" . str_replace("'", "\\'", $extra['Person']) . "'";
                $label .= $extra['type'] . ' of ' . str_replace("'", "\\'", $extra['Person']);
            } else {
                if (isset($extra['Family'])) {
                    print ",\n\t\t\tFamily: '" . str_replace("'", "\\'", $extra['Family']) . "'";
                    $label .= $extra['type'] . ' of ' . str_replace("'", "\\'", $extra['Family']);
                }
            }
            if (isset($extra['Date']) && strlen($extra['Date']) > 0) {
                $date = $this->cleanDate(str_replace("'", "\\'", $extra['Date']));
                if (strlen($date) > 0) {
                    print ",\n\t\t\tDate: '{$date}'";
                } else {
                    $label .= ': ' . str_replace("'", "\\'", $extra['Date']);
                }
            }
            print ",\n\t\t\tlabel: '{$label}'";
            print "\n\t\t}";
        }
        print "\n\t],";
        //		"Date" : { valueType: "date" },
        print '
	"properties": {
		"Marriage" : { valueType: "item" },
		"Family" : { valueType: "item" },
		"Person" : { valueType: "item" },
		"Death" : { valueType: "item" },
		"Birth" : { valueType: "item" },
		"Date" : { valueType: "date" },
		"URL" : { valueType: "url" }
	},
	"types": {
		"Person" : { pluralLabel: "People" },
		"Family" : { pluralLabel: "Families" },
		"Marriage" : { pluralLabel: "Marriages" },
		"Birth" : { pluralLabel: "Births" },
		"Death" : { pluralLabel: "Deaths" },
		"Date" : { pluralLabel: "Dates" },
		"Location" : { pluralLabel: "Locations" }
	}
}';
    }