/**
* returns INDIviduals matching filter
* @return Array of string
*/
function autocomplete_INDI($FILTER, $OPTION)
{
    global $pgv_lang, $MAX_ALIVE_AGE;
    // when adding ASSOciate $OPTION may contain :
    // current INDI/FAM [, current event date]
    if ($OPTION) {
        list($pid, $event_date) = explode("|", $OPTION . "|");
        $record = GedcomRecord::getInstance($pid);
        // INDI or FAM
        $tmp = new GedcomDate($event_date);
        $event_jd = $tmp->JD();
        // INDI
        $indi_birth_jd = 0;
        if ($record && $record->getType() == "INDI") {
            $indi_birth_jd = $record->getEstimatedBirthDate()->minJD();
        }
        // HUSB & WIFE
        $husb_birth_jd = 0;
        $wife_birth_jd = 0;
        if ($record && $record->getType() == "FAM") {
            $husb = $record->getHusband();
            if ($husb) {
                $husb_birth_jd = $husb->getEstimatedBirthDate()->minJD();
            }
            $wife = $record->getWife();
            if ($wife) {
                $wife_birth_jd = $wife->getEstimatedBirthDate()->minJD();
            }
        }
    }
    $rows = get_autocomplete_INDI($FILTER);
    $data = array();
    foreach ($rows as $row) {
        $person = Person::getInstance($row);
        if ($person->canDisplayName()) {
            // filter ASSOciate
            if ($OPTION && $event_jd) {
                // no self-ASSOciate
                if ($pid && $person->getXref() == $pid) {
                    continue;
                }
                // filter by birth date
                $person_birth_jd = $person->getEstimatedBirthDate()->minJD();
                if ($person_birth_jd) {
                    // born after event or not a contemporary
                    if ($event_jd && $person_birth_jd > $event_jd) {
                        continue;
                    } elseif ($indi_birth_jd && abs($indi_birth_jd - $person_birth_jd) > $MAX_ALIVE_AGE * 365) {
                        continue;
                    } elseif ($husb_birth_jd && $wife_birth_jd && abs($husb_birth_jd - $person_birth_jd) > $MAX_ALIVE_AGE * 365 && abs($wife_birth_jd - $person_birth_jd) > $MAX_ALIVE_AGE * 365) {
                        continue;
                    } elseif ($husb_birth_jd && abs($husb_birth_jd - $person_birth_jd) > $MAX_ALIVE_AGE * 365) {
                        continue;
                    } elseif ($wife_birth_jd && abs($wife_birth_jd - $person_birth_jd) > $MAX_ALIVE_AGE * 365) {
                        continue;
                    }
                }
                // filter by death date
                $person_death_jd = $person->getEstimatedDeathDate()->MaxJD();
                if ($person_death_jd) {
                    // dead before event or not a contemporary
                    if ($event_jd && $person_death_jd < $event_jd) {
                        continue;
                    } elseif ($indi_birth_jd && $person_death_jd < $indi_birth_jd) {
                        continue;
                    } elseif ($husb_birth_jd && $wife_birth_jd && $person_death_jd < $husb_birth_jd && $person_death_jd < $wife_birth_jd) {
                        continue;
                    } elseif ($husb_birth_jd && $person_death_jd < $husb_birth_jd) {
                        continue;
                    } elseif ($wife_birth_jd && $person_death_jd < $wife_birth_jd) {
                        continue;
                    }
                }
            }
            // display
            $data[$person->getXref()] = $person->getFullName();
            if ($OPTION && $event_date && $person->getBirthDate()->isOK()) {
                $data[$person->getXref()] .= " <span class=\"age\">(" . $pgv_lang["age"] . " " . $person->getBirthDate()->MinDate()->getAge(false, $event_jd) . ")</span>";
            } else {
                $data[$person->getXref()] .= " <u>" . ltrim($person->getBirthYear(), "0") . "-" . ltrim($person->getDeathYear(), "0") . "</u>";
            }
        }
    }
    return $data;
}
Beispiel #2
0
/**
* returns INDIviduals matching filter
* @return Array of string
*/
function autocomplete_INDI($FILTER, $OPTION)
{
    global $TBLPREFIX, $pgv_lang, $MAX_ALIVE_AGE, $gBitDb;
    // when adding ASSOciate $OPTION may contain :
    // current INDI/FAM [, current event date]
    if ($OPTION) {
        list($pid, $event_date) = explode("|", $OPTION . "|");
        $record = GedcomRecord::getInstance($pid);
        // INDI or FAM
        $tmp = new GedcomDate($event_date);
        $event_jd = $tmp->JD();
        // INDI
        $indi_birth_jd = 0;
        if ($record && $record->getType() == "INDI") {
            $indi_birth_jd = $record->getEstimatedBirthDate()->minJD();
        }
        // HUSB & WIFE
        $husb_birth_jd = 0;
        $wife_birth_jd = 0;
        if ($record && $record->getType() == "FAM") {
            $husb = $record->getHusband();
            if ($husb) {
                $husb_birth_jd = $husb->getEstimatedBirthDate()->minJD();
            }
            $wife = $record->getWife();
            if ($wife) {
                $wife_birth_jd = $wife->getEstimatedBirthDate()->minJD();
            }
        }
    }
    $sql = "SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex" . " FROM {$TBLPREFIX}individuals, {$TBLPREFIX}name" . " WHERE (i_id LIKE ? OR n_sort LIKE ?)" . " AND i_id=n_id AND i_file=n_file AND i_file=?" . " ORDER BY n_sort";
    $rows = $gBitDb->query($sql, array("%{$FILTER}%", "%{$FILTER}%", PGV_GED_ID), PGV_AUTOCOMPLETE_LIMIT);
    $data = array();
    while ($row = $rows->fetchRow()) {
        $person = Person::getInstance($row);
        if ($person->canDisplayName()) {
            // filter ASSOciate
            if ($OPTION && $event_jd) {
                // no self-ASSOciate
                if ($pid && $person->getXref() == $pid) {
                    continue;
                }
                // filter by birth date
                $person_birth_jd = $person->getEstimatedBirthDate()->minJD();
                if ($person_birth_jd) {
                    // born after event or not a contemporary
                    if ($event_jd && $person_birth_jd > $event_jd) {
                        continue;
                    } elseif ($indi_birth_jd && abs($indi_birth_jd - $person_birth_jd) > $MAX_ALIVE_AGE * 365) {
                        continue;
                    } elseif ($husb_birth_jd && $wife_birth_jd && abs($husb_birth_jd - $person_birth_jd) > $MAX_ALIVE_AGE * 365 && abs($wife_birth_jd - $person_birth_jd) > $MAX_ALIVE_AGE * 365) {
                        continue;
                    } elseif ($husb_birth_jd && abs($husb_birth_jd - $person_birth_jd) > $MAX_ALIVE_AGE * 365) {
                        continue;
                    } elseif ($wife_birth_jd && abs($wife_birth_jd - $person_birth_jd) > $MAX_ALIVE_AGE * 365) {
                        continue;
                    }
                }
                // filter by death date
                $person_death_jd = $person->getEstimatedDeathDate()->MaxJD();
                if ($person_death_jd) {
                    // dead before event or not a contemporary
                    if ($event_jd && $person_death_jd < $event_jd) {
                        continue;
                    } elseif ($indi_birth_jd && $person_death_jd < $indi_birth_jd) {
                        continue;
                    } elseif ($husb_birth_jd && $wife_birth_jd && $person_death_jd < $husb_birth_jd && $person_death_jd < $wife_birth_jd) {
                        continue;
                    } elseif ($husb_birth_jd && $person_death_jd < $husb_birth_jd) {
                        continue;
                    } elseif ($wife_birth_jd && $person_death_jd < $wife_birth_jd) {
                        continue;
                    }
                }
            }
            // display
            $data[$person->getXref()] = $person->getFullName();
            if ($OPTION && $event_date && $person->getBirthDate()->isOK()) {
                $data[$person->getXref()] .= " <span class=\"age\">(" . $pgv_lang["age"] . " " . $person->getBirthDate()->MinDate()->getAge(false, $event_jd) . ")</span>";
            } else {
                $data[$person->getXref()] .= " <u>" . ltrim($person->getBirthYear(), "0") . "-" . ltrim($person->getDeathYear(), "0") . "</u>";
            }
        }
    }
    return $data;
}