Пример #1
0
function compare_facts_date($arec, $brec)
{
    if (is_array($arec)) {
        $arec = $arec[1];
    }
    if (is_array($brec)) {
        $brec = $brec[1];
    }
    // If either fact is undated, the facts sort equally.
    if (!preg_match("/2 _?DATE (.*)/", $arec, $amatch) || !preg_match("/2 _?DATE (.*)/", $brec, $bmatch)) {
        if (preg_match('/2 _SORT (\\d+)/', $arec, $match1) && preg_match('/2 _SORT (\\d+)/', $brec, $match2)) {
            return $match1[1] - $match2[1];
        }
        return 0;
    }
    $adate = new GedcomDate($amatch[1]);
    $bdate = new GedcomDate($bmatch[1]);
    // If either date can't be parsed, don't sort.
    if (!$adate->isOK() || !$bdate->isOK()) {
        if (preg_match('/2 _SORT (\\d+)/', $arec, $match1) && preg_match('/2 _SORT (\\d+)/', $brec, $match2)) {
            return $match1[1] - $match2[1];
        }
        return 0;
    }
    // Remember that dates can be ranges and overlapping ranges sort equally.
    $amin = $adate->MinJD();
    $bmin = $bdate->MinJD();
    $amax = $adate->MaxJD();
    $bmax = $bdate->MaxJD();
    // BEF/AFT XXX sort as the day before/after XXX
    if ($adate->qual1 == 'BEF') {
        $amin = $amin - 1;
        $amax = $amin;
    } else {
        if ($adate->qual1 == 'AFT') {
            $amax = $amax + 1;
            $amin = $amax;
        }
    }
    if ($bdate->qual1 == 'BEF') {
        $bmin = $bmin - 1;
        $bmax = $bmin;
    } else {
        if ($bdate->qual1 == 'AFT') {
            $bmax = $bmax + 1;
            $bmin = $bmax;
        }
    }
    if ($amax < $bmin) {
        return -1;
    } else {
        if ($amin > $bmax) {
            return 1;
        } else {
            //-- ranged date... take the type of fact sorting into account
            $factWeight = 0;
            if (preg_match('/2 _SORT (\\d+)/', $arec, $match1) && preg_match('/2 _SORT (\\d+)/', $brec, $match2)) {
                $factWeight = $match1[1] - $match2[1];
            }
            //-- fact is prefered to come before, so compare using the minimum ranges
            if ($factWeight < 0 && $amin != $bmin) {
                return $amin - $bmin;
            } else {
                if ($factWeight > 0 && $bmax != $amax) {
                    //-- fact is prefered to come after, so compare using the max of the ranges
                    return $bmax - $amax;
                } else {
                    //-- facts are the same or the ranges don't give enough info, so use the average of the range
                    $aavg = ($amin + $amax) / 2;
                    $bavg = ($bmin + $bmax) / 2;
                    if ($aavg < $bavg) {
                        return -1;
                    } else {
                        if ($aavg > $bavg) {
                            return 1;
                        } else {
                            return $factWeight;
                        }
                    }
                }
            }
            return 0;
        }
    }
}
Пример #2
0
        for ($jd = $cal_date->minJD; $jd <= $cal_date->maxJD; ++$jd) {
            foreach (apply_filter(get_anniversary_events($jd, $events), $filterof, $filtersx) as $event) {
                $tmp = $event['date']->MinDate();
                if ($tmp->d >= 1 && $tmp->d <= $tmp->DaysInMonth()) {
                    $d = $jd - $cal_date->minJD + 1;
                } else {
                    $d = 0;
                }
                $found_facts[$d][] = $event;
            }
        }
        break;
    case 'year':
        $cal_date->m = 0;
        $cal_date->SetJDfromYMD();
        $found_facts = apply_filter(get_calendar_events($ged_date->MinJD(), $ged_date->MaxJD(), $events), $filterof, $filtersx);
        // Eliminate duplictes (e.g. BET JUL 1900 AND SEP 1900 will appear twice in 1900)
        foreach ($found_facts as $key => $value) {
            $found_facts[$key] = serialize($found_facts[$key]);
        }
        $found_facts = array_unique($found_facts);
        foreach ($found_facts as $key => $value) {
            $found_facts[$key] = unserialize($found_facts[$key]);
        }
        break;
}
// Group the facts by family/individual
switch ($action) {
    case 'year':
    case 'today':
        $indis = array();