Exemplo n.º 1
0
/**
 * @param array $attrs an array of key value pairs for the attributes
 *
 * @see  RelativesEHandler()
 */
function RelativesSHandler($attrs)
{
    global $repeats, $repeatBytes, $list, $repeatsStack, $processRepeats, $parser, $vars, $sortby;
    $processRepeats++;
    if ($processRepeats > 1) {
        return;
    }
    $sortby = "NAME";
    if (isset($attrs['sortby'])) {
        $sortby = $attrs['sortby'];
    }
    $match = array();
    if (preg_match("/\\\$(\\w+)/", $sortby, $match)) {
        $sortby = $vars[$match[1]]['id'];
        $sortby = trim($sortby);
    }
    $maxgen = -1;
    if (isset($attrs['maxgen'])) {
        $maxgen = $attrs['maxgen'];
    }
    if ($maxgen == "*") {
        $maxgen = -1;
    }
    $group = "child-family";
    if (isset($attrs['group'])) {
        $group = $attrs['group'];
    }
    if (preg_match("/\\\$(\\w+)/", $group, $match)) {
        $group = $vars[$match[1]]['id'];
        $group = trim($group);
    }
    $id = "";
    if (isset($attrs['id'])) {
        $id = $attrs['id'];
    }
    if (preg_match("/\\\$(\\w+)/", $id, $match)) {
        $id = $vars[$match[1]]['id'];
        $id = trim($id);
    }
    $list = array();
    $person = WT_Individual::getInstance($id);
    if (!empty($person)) {
        $list[$id] = $person;
        switch ($group) {
            case "child-family":
                foreach ($person->getChildFamilies() as $family) {
                    $husband = $family->getHusband();
                    $wife = $family->getWife();
                    if (!empty($husband)) {
                        $list[$husband->getXref()] = $husband;
                    }
                    if (!empty($wife)) {
                        $list[$wife->getXref()] = $wife;
                    }
                    $children = $family->getChildren();
                    foreach ($children as $child) {
                        if (!empty($child)) {
                            $list[$child->getXref()] = $child;
                        }
                    }
                }
                break;
            case "spouse-family":
                foreach ($person->getSpouseFamilies() as $family) {
                    $husband = $family->getHusband();
                    $wife = $family->getWife();
                    if (!empty($husband)) {
                        $list[$husband->getXref()] = $husband;
                    }
                    if (!empty($wife)) {
                        $list[$wife->getXref()] = $wife;
                    }
                    $children = $family->getChildren();
                    foreach ($children as $child) {
                        if (!empty($child)) {
                            $list[$child->getXref()] = $child;
                        }
                    }
                }
                break;
            case "direct-ancestors":
                add_ancestors($list, $id, false, $maxgen);
                break;
            case "ancestors":
                add_ancestors($list, $id, true, $maxgen);
                break;
            case "descendants":
                $list[$id]->generation = 1;
                add_descendancy($list, $id, false, $maxgen);
                break;
            case "all":
                add_ancestors($list, $id, true, $maxgen);
                add_descendancy($list, $id, true, $maxgen);
                break;
        }
    }
    switch ($sortby) {
        case "NAME":
            uasort($list, array("WT_GedcomRecord", "compare"));
            break;
        case "BIRT:DATE":
            uasort($list, array("WT_Individual", "CompareBirtDate"));
            break;
        case "DEAT:DATE":
            uasort($list, array("WT_Individual", "CompareDeatDate"));
            break;
        case "generation":
            $newarray = array();
            reset($list);
            $genCounter = 1;
            while (count($newarray) < count($list)) {
                foreach ($list as $key => $value) {
                    $generation = $value->generation;
                    if ($generation == $genCounter) {
                        $newarray[$key] = new stdClass();
                        $newarray[$key]->generation = $generation;
                    }
                }
                $genCounter++;
            }
            $list = $newarray;
            break;
        default:
            // unsorted
            break;
    }
    array_push($repeatsStack, array($repeats, $repeatBytes));
    $repeatBytes = xml_get_current_line_number($parser) + 1;
}
Exemplo n.º 2
0
/**
* @todo add info
* @param array $attrs an array of key value pairs for the attributes
* @see PGVRRelativesEHandler()
*/
function PGVRRelativesSHandler($attrs)
{
    global $pgvreport, $gedrec, $repeats, $repeatBytes, $list, $repeatsStack, $processRepeats, $parser, $vars, $sortby;
    $processRepeats++;
    if ($processRepeats > 1) {
        return;
    }
    $sortby = "NAME";
    if (isset($attrs["sortby"])) {
        $sortby = $attrs["sortby"];
    }
    $vmatch = array();
    if (preg_match("/\\\$(\\w+)/", $sortby, $vmatch) > 0) {
        $sortby = $vars[$vmatch[1]]["id"];
        $sortby = trim($sortby);
    }
    $maxgen = -1;
    if (isset($attrs["maxgen"])) {
        $maxgen = $attrs["maxgen"];
    }
    if ($maxgen == "*") {
        $maxgen = -1;
    }
    $group = "child-family";
    if (isset($attrs["group"])) {
        $group = $attrs["group"];
    }
    if (preg_match("/\\\$(\\w+)/", $group, $vmatch) > 0) {
        $group = $vars[$vmatch[1]]["id"];
        $group = trim($group);
    }
    $id = "";
    if (isset($attrs["id"])) {
        $id = $attrs["id"];
    }
    if (preg_match("/\\\$(\\w+)/", $id, $vmatch) > 0) {
        $id = $vars[$vmatch[1]]["id"];
        $id = trim($id);
    }
    $showempty = false;
    if (isset($attrs["showempty"])) {
        $showempty = $attrs["showempty"];
    }
    if (preg_match("/\\\$(\\w+)/", $showempty, $vmatch) > 0) {
        $showempty = $vars[$vmatch[1]]["id"];
        $showempty = trim($showempty);
    }
    $list = array();
    $person = Person::getInstance($id);
    if (!empty($person)) {
        $list[$id] = $person;
        switch ($group) {
            case "child-family":
                $famids = $person->getChildFamilies();
                foreach ($famids as $family) {
                    $husband = $family->getHusband();
                    $wife = $family->getWife();
                    if (!empty($husband)) {
                        $list[$husband->getXref()] = $husband;
                    }
                    if (!empty($wife)) {
                        $list[$wife->getXref()] = $wife;
                    }
                    $children = $family->getChildren();
                    foreach ($children as $child) {
                        if (!empty($child)) {
                            $list[$child->getXref()] = $child;
                        }
                    }
                }
                break;
            case "spouse-family":
                $famids = $person->getSpouseFamilies();
                foreach ($famids as $family) {
                    $husband = $family->getHusband();
                    $wife = $family->getWife();
                    if (!empty($husband)) {
                        $list[$husband->getXref()] = $husband;
                    }
                    if (!empty($wife)) {
                        $list[$wife->getXref()] = $wife;
                    }
                    $children = $family->getChildren();
                    foreach ($children as $child) {
                        if (!empty($child)) {
                            $list[$child->getXref()] = $child;
                        }
                    }
                }
                break;
            case "direct-ancestors":
                add_ancestors($list, $id, false, $maxgen, $showempty);
                break;
            case "ancestors":
                add_ancestors($list, $id, true, $maxgen, $showempty);
                break;
            case "descendants":
                $list[$id]->generation = 1;
                add_descendancy($list, $id, false, $maxgen);
                break;
            case "all":
                add_ancestors($list, $id, true, $maxgen, $showempty);
                add_descendancy($list, $id, true, $maxgen);
                break;
        }
    }
    switch ($sortby) {
        case 'NAME':
            uasort($list, array('GedcomRecord', 'Compare'));
            break;
        case 'ID':
            uasort($list, array('GedcomRecord', 'CompareId'));
            break;
        case 'BIRT:DATE':
            uasort($list, array('PGVReportBase', 'CompareBirthDate'));
            break;
        case 'DEAT:DATE':
            uasort($list, array('PGVReportBase', 'CompareDeathDate'));
            break;
        case 'generation':
            $newarray = array();
            reset($list);
            $genCounter = 1;
            while (count($newarray) < count($list)) {
                foreach ($list as $key => $value) {
                    $generation = $value->generation;
                    if ($generation == $genCounter) {
                        $newarray[$key]->generation = $generation;
                    }
                }
                $genCounter++;
            }
            $list = $newarray;
            break;
        default:
            // unsorted
            break;
    }
    array_push($repeatsStack, array($repeats, $repeatBytes));
    $repeatBytes = xml_get_current_line_number($parser) + 1;
}