Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Genealogical numbering system support #3297

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 33 additions & 5 deletions app/Report/ReportParserGenerate.php
Expand Up @@ -159,6 +159,9 @@ class ReportParserGenerate extends ReportParserBase

/** @var int The current generational level */
private $generation = 1;

/** @var int The current kekule order number */
private $kekule_number = 1;

/** @var array Source data for processing lists */
private $list = [];
Expand Down Expand Up @@ -1471,6 +1474,8 @@ protected function setVarStartHandler(array $attrs): void
$value = $this->desc;
} elseif ($value === '@generation') {
$value = (string) $this->generation;
} elseif ($value === '@kekule_number') {
$value = (string) $this->kekule_number;
} elseif (preg_match("/@(\w+)/", $value, $match)) {
$gmatch = [];
if (preg_match("/\d $match[1] (.+)/", $this->gedrec, $gmatch)) {
Expand Down Expand Up @@ -1553,6 +1558,8 @@ protected function ifStartHandler(array $attrs): void
$value = '"' . addslashes($this->desc) . '"';
} elseif ($id === 'generation') {
$value = '"' . $this->generation . '"';
} elseif ($id === 'kekule_number') {
$value = '"' . $this->kekule_number .'"';
} else {
$level = (int) explode(' ', trim($this->gedrec))[0];
if ($level === 0) {
Expand Down Expand Up @@ -2546,6 +2553,9 @@ protected function relativesEndHandler(): void
if (isset($value->generation)) {
$this->generation = $value->generation;
}
if (isset($value->kekule_number)) {
$this->kekule_number = $value->kekule_number;
}
$tmp = Factory::gedcomRecord()->make((string) $xref, $this->tree);
$this->gedrec = $tmp->privatizeGedcom(Auth::accessLevel($this->tree));

Expand Down Expand Up @@ -2594,6 +2604,17 @@ protected function generationStartHandler(): void
$this->current_element->addText((string) $this->generation);
}

/**
* Handle <kekuleNumber />
* Prints the kekule order number
*
* @return void
*/
protected function kekuleNumberStartHandler(): void
{
$this->current_element->addText((string) $this->kekule_number);
}

/**
* Handle <newPage />
* Has to be placed in an element (header, body or footer)
Expand Down Expand Up @@ -2704,9 +2725,12 @@ private function addDescendancy(&$list, $pid, $parents = false, $generations = -
private function addAncestors(array &$list, string $pid, bool $children = false, int $generations = -1): void
{
$genlist = [$pid];
$kekulelist = [1];
$list[$pid]->generation = 1;
$list[$pid]->kekule_number = 1;
while (count($genlist) > 0) {
$id = array_shift($genlist);
$kekule_number = array_shift($kekulelist) + 1;
if (strpos($id, 'empty') === 0) {
continue; // id can be something like “empty7”
}
Expand All @@ -2715,19 +2739,23 @@ private function addAncestors(array &$list, string $pid, bool $children = false,
$husband = $family->husband();
$wife = $family->wife();
if ($husband) {
$list[$husband->xref()] = $husband;
$list[$husband->xref()]->generation = $list[$id]->generation + 1;
$list[$husband->xref()] = $husband;
$list[$husband->xref()]->generation = $list[$id]->generation + 1;
$list[$husband->xref()]->kekule_number = $kekule_number;
}
if ($wife) {
$list[$wife->xref()] = $wife;
$list[$wife->xref()]->generation = $list[$id]->generation + 1;
$list[$wife->xref()] = $wife;
$list[$wife->xref()]->generation = $list[$id]->generation + 1;
$list[$wife->xref()]->kekule_number = $kekule_number + 1;
}
if ($generations == -1 || $list[$id]->generation + 1 < $generations) {
if ($husband) {
$genlist[] = $husband->xref();
$genlist[] = $husband->xref();
$kekulelist[] = ($kekule_number) * 2 - 1;
}
if ($wife) {
$genlist[] = $wife->xref();
$kekulelist[] = ($kekule_number + 1) * 2 - 1;
}
}
if ($children) {
Expand Down
4 changes: 2 additions & 2 deletions resources/xml/reports/ahnentafel_report.xml
Expand Up @@ -100,8 +100,8 @@
<SetVar name="empty_name" value="f" />
</if>
<!-- Generation counter -->
<TextBox width="25" height="30">
<Text style="text"><var var="num" />.</Text>
<TextBox width="50" height="30">
<Text style="text"><kekuleNumber />.</Text>
</TextBox>
<!-- Sentence 1 Individual, name... -->
<TextBox height="12" newline="1">
Expand Down