diff options
| -rw-r--r-- | app/Functions/Functions.php | 12 | ||||
| -rw-r--r-- | app/Functions/FunctionsCharts.php | 540 | ||||
| -rw-r--r-- | app/Functions/FunctionsRtl.php | 4 | ||||
| -rw-r--r-- | app/Module/AncestorsChartModule.php | 38 | ||||
| -rw-r--r-- | app/Module/DescendancyChartModule.php | 68 | ||||
| -rw-r--r-- | app/Module/PedigreeMapModule.php | 28 | ||||
| -rw-r--r-- | resources/views/modules/ancestors-chart/page.phtml | 10 | ||||
| -rw-r--r-- | tests/app/Functions/FunctionsChartsTest.php | 34 |
8 files changed, 39 insertions, 695 deletions
diff --git a/app/Functions/Functions.php b/app/Functions/Functions.php index a64efe2233..9910ccec38 100644 --- a/app/Functions/Functions.php +++ b/app/Functions/Functions.php @@ -2231,18 +2231,18 @@ class Functions } if ($down < $up) { - return self::cousinName2($cousin + 1, $sex2, self::getRelationshipNameFromPath('sib' . $descent, null, null)); + return self::cousinName2($cousin + 1, $sex2, self::getRelationshipNameFromPath('sib' . $descent)); } if ($sex2 === 'M') { - return self::cousinName2($cousin + 1, $sex2, self::getRelationshipNameFromPath('bro' . $descent, null, null)); + return self::cousinName2($cousin + 1, $sex2, self::getRelationshipNameFromPath('bro' . $descent)); } if ($sex2 === 'F') { - return self::cousinName2($cousin + 1, $sex2, self::getRelationshipNameFromPath('sis' . $descent, null, null)); + return self::cousinName2($cousin + 1, $sex2, self::getRelationshipNameFromPath('sis' . $descent)); } - return self::cousinName2($cousin + 1, $sex2, self::getRelationshipNameFromPath('sib' . $descent, null, null)); + return self::cousinName2($cousin + 1, $sex2, self::getRelationshipNameFromPath('sib' . $descent)); case 'en_AU': // See: http://en.wikipedia.org/wiki/File:CousinTree.svg case 'en_GB': @@ -2302,8 +2302,8 @@ class Functions // I18N: A complex relationship, such as “third-cousin’s great-uncle” $tmp = I18N::translate( '%1$s’s %2$s', - self::getRelationshipNameFromPath($path1, null, null), - self::getRelationshipNameFromPath($path2, null, null) + self::getRelationshipNameFromPath($path1), + self::getRelationshipNameFromPath($path2) ); if (!$relationship || strlen($tmp) < strlen($relationship)) { $relationship = $tmp; diff --git a/app/Functions/FunctionsCharts.php b/app/Functions/FunctionsCharts.php deleted file mode 100644 index 88d98d33f0..0000000000 --- a/app/Functions/FunctionsCharts.php +++ /dev/null @@ -1,540 +0,0 @@ -<?php -/** - * webtrees: online genealogy - * Copyright (C) 2019 webtrees development team - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -declare(strict_types=1); - -namespace Fisharebest\Webtrees\Functions; - -use Fisharebest\Webtrees\Auth; -use Fisharebest\Webtrees\Family; -use Fisharebest\Webtrees\Gedcom; -use Fisharebest\Webtrees\I18N; -use Fisharebest\Webtrees\Individual; -use Fisharebest\Webtrees\Module\ModuleThemeInterface; -use function view; - -/** - * Class FunctionsCharts - common functions - */ -class FunctionsCharts -{ - /** - * print a table cell with sosa number - * - * @param string $daboville - * @param string $pid optional pid - * @param string $icon which arrow to use - * - * @return void - */ - public static function printDabovilleNumber(string $daboville, string $pid = '', string $icon = ''): void - { - // Remove trailing "." - $personLabel = substr($daboville, 0, -1); - - if ($icon === '') { - $visibility = 'hidden'; - } else { - $visibility = 'normal'; - } - echo '<td class="subheaders text-center" style="vertical-align: middle; text-indent: 0px; margin-top: 0px; white-space: nowrap; visibility: ', $visibility, ';">'; - echo $personLabel; - if ($daboville !== '1' && $pid !== '' && $icon !== 'blank') { - echo '<br>'; - echo '<a href="#' . e($pid) . '" title="' . e($pid) . '">'; - echo view($icon); - echo '</a>'; - } - echo '</td>'; - } - - /** - * print a table cell with sosa number - * - * @param int $sosa - * @param string $pid optional pid - * @param string $icon which arrow to use - * - * @return void - */ - public static function printSosaNumber(int $sosa, string $pid = '', string $icon = ''): void - { - if ($icon === '') { - $visibility = 'hidden'; - } else { - $visibility = 'normal'; - } - - echo '<td class="subheaders text-center" style="vertical-align: middle; text-indent: 0px; margin-top: 0px; white-space: nowrap; visibility: ', $visibility, ';">'; - echo (string) $sosa; - if ($sosa !== 1 && $pid !== '' && $icon !== '') { - echo '<br>'; - echo '<a href="#' . e($pid) . '">'; - echo view($icon); - echo '</a>'; - } - echo '</td>'; - } - - /** - * print the parents table for a family - * - * @param Family $family family gedcom ID - * @param int $sosa child sosa number - * @param string $daboville indi label (descendancy booklet) - * @param string $parid parent ID (descendancy booklet) - * @param string $gparid gd-parent ID (descendancy booklet) - * - * @return void - */ - public static function printFamilyParents(Family $family, int $sosa = 0, string $daboville = '', string $parid = '', string $gparid = ''): void - { - $pbheight = app(ModuleThemeInterface::class)->parameter('chart-box-y') + 14; - - $husb = $family->husband(); - if ($husb) { - echo '<a name="', $husb->xref(), '"></a>'; - } else { - $husb = new Individual('M', "0 @M@ INDI\n1 SEX M", null, $family->tree()); - } - $wife = $family->wife(); - if ($wife) { - echo '<a name="', $wife->xref(), '"></a>'; - } else { - $wife = new Individual('F', "0 @F@ INDI\n1 SEX F", null, $family->tree()); - } - - if ($sosa) { - echo '<p class="name_head">', $family->fullName(), '</p>'; - } - - /** - * husband side - */ - echo '<table cellspacing="0" cellpadding="0" border="0"><tr><td rowspan="2">'; - echo '<table cellspacing="0" cellpadding="0" border="0"><tr>'; - - if ($parid) { - if ($husb->xref() === $parid) { - self::printDabovilleNumber($daboville, '', 'blank'); - } else { - self::printDabovilleNumber($daboville, '', ''); - } - } elseif ($sosa) { - self::printSosaNumber($sosa * 2, '', ''); - } - if ($husb->isPendingAddition()) { - echo '<td class="new">'; - } elseif ($husb->isPendingDeletion()) { - echo '<td class="old">'; - } else { - echo '<td>'; - } - echo view('chart-box', ['individual' => $husb]); - echo '</td></tr></table>'; - echo '</td>'; - // husband’s parents - $hfam = $husb->primaryChildFamily(); - if ($hfam instanceof Family) { - echo '<td rowspan="2"><img src="' . e(asset('css/images/hline.png')) . '"></td><td rowspan="2"><img src="' . e(asset('css/images/vline.png')) . '" width="3" height="' . ($pbheight - 14) . '"></td>'; - echo '<td><img class="linea1 lined1" src="' . e(asset('css/images/hline.png')) . '"></td><td>'; - // husband’s father - if ($hfam->husband() instanceof Individual) { - echo '<table cellspacing="0" cellpadding="0" border="0"><tr>'; - if ($sosa > 0) { - self::printSosaNumber($sosa * 4, $hfam->husband()->xref(), 'icons/arrow-down'); - } - if (!empty($gparid) && $hfam->husband()->xref() === $gparid) { - self::printDabovilleNumber(trim(substr($daboville, 0, -3), '.') . '.', '', 'icons/arrow-up'); - } - echo '<td>'; - echo view('chart-box', ['individual' => $hfam->husband()]); - echo '</td></tr></table>'; - } else { - // Empty box for grandfather - echo '<table cellspacing="0" cellpadding="0" border="0"><tr>'; - echo '<td>'; - echo view('chart-box', ['individual' => null]); - echo '</td></tr></table>'; - } - echo '</td>'; - if ($sosa !== -1) { - echo '<td rowspan="2">'; - echo '<a href="' . ($sosa === 0 ? $hfam->url() : '#' . $hfam->xref()) . '">' . view('icons/arrow-right') . '</a>'; - echo '</td>'; - } - - // husband’s mother - echo '</tr><tr><td><img class="linea2 lined2" src="' . e(asset('css/images/hline.png')) . '"></td><td>'; - if ($hfam->wife() instanceof Individual) { - echo '<table cellspacing="0" cellpadding="0" border="0"><tr>'; - if ($sosa > 0) { - self::printSosaNumber($sosa * 4 + 1, $hfam->wife()->xref(), 'icons/arrow-down'); - } - if (!empty($gparid) && $hfam->wife()->xref() === $gparid) { - self::printDabovilleNumber(trim(substr($daboville, 0, -3), '.') . '.', '', 'icons/arrow-up'); - } - echo '<td>'; - echo view('chart-box', ['individual' => $hfam->wife()]); - echo '</td></tr></table>'; - } else { - // Empty box for grandmother - echo '<table cellspacing="0" cellpadding="0" border="0"><tr>'; - echo '<td>'; - echo view('chart-box', ['individual' => null]); - echo '</td></tr></table>'; - } - echo '</td>'; - } - echo '</tr></table>'; - echo '<br>'; - if ($sosa && $family->canShow()) { - foreach ($family->facts(Gedcom::MARRIAGE_EVENTS) as $fact) { - echo '<a href="' . e($family->url()) . '" class="details1">' . $fact->summary() . '</a>'; - } - } - echo '<br>'; - - /** - * wife side - */ - echo '<table cellspacing="0" cellpadding="0" border="0"><tr><td rowspan="2">'; - echo '<table cellspacing="0" cellpadding="0" border="0"><tr>'; - if ($parid) { - if ($wife->xref() === $parid) { - self::printDabovilleNumber($daboville, '', 'blank'); - } else { - self::printDabovilleNumber($daboville, '', ''); - } - } elseif ($sosa) { - self::printSosaNumber($sosa * 2 + 1, '', ''); - } - if ($wife->isPendingAddition()) { - echo '<td class="new">'; - } elseif ($wife->isPendingDeletion()) { - echo '<td class="old">'; - } else { - echo '<td>'; - } - echo view('chart-box', ['individual' => $wife]); - echo '</td></tr></table>'; - echo '</td>'; - // wife’s parents - $wfam = $wife->primaryChildFamily(); - if ($wfam instanceof Family) { - echo '<td rowspan="2"><img src="' . e(asset('css/images/hline.png')) . '"></td><td rowspan="2"><img src="' . e(asset('css/images/vline.png')) . '" width="3" height="' . ($pbheight - 14) . '"></td>'; - echo '<td><img class="linea3 lined3" src="' . e(asset('css/images/hline.png')) . '"></td><td>'; - // wife’s father - if ($wfam->husband() instanceof Individual) { - echo '<table cellspacing="0" cellpadding="0" border="0"><tr>'; - if ($sosa > 0) { - self::printSosaNumber($sosa * 4 + 2, $wfam->husband()->xref(), 'icons/arrow-down'); - } - if (!empty($gparid) && $wfam->husband()->xref() === $gparid) { - self::printDabovilleNumber(trim(substr($daboville, 0, -3), '.') . '.', '', 'icons/arrow-up'); - } - echo '<td>'; - echo view('chart-box', ['individual' => $wfam->husband()]); - echo '</td></tr></table>'; - } else { - // Empty box for grandfather - echo '<table cellspacing="0" cellpadding="0" border="0"><tr>'; - echo '<td>'; - echo view('chart-box', ['individual' => null]); - echo '</td></tr></table>'; - } - echo '</td>'; - if ($sosa !== -1) { - echo '<td rowspan="2">'; - echo '<a href="' . ($sosa === 0 ? $wfam->url() : '#' . $wfam->xref()) . '">' . view('icons/arrow-right') . '</a>'; - echo '</td>'; - } - // wife’s mother - echo '</tr><tr><td><img class="linea4 lined4" src="' . e(asset('css/images/hline.png')) . '"></td><td>'; - if ($wfam->wife() instanceof Individual) { - echo '<table cellspacing="0" cellpadding="0" border="0"><tr>'; - if ($sosa > 0) { - self::printSosaNumber($sosa * 4 + 3, $wfam->wife()->xref(), 'icons/arrow-down'); - } - if (!empty($gparid) && $wfam->wife()->xref() === $gparid) { - self::printDabovilleNumber(trim(substr($daboville, 0, -3), '.') . '.', '', 'icons/arrow-up'); - } - echo '<td>'; - echo view('chart-box', ['individual' => $wfam->wife()]); - echo '</td></tr></table>'; - } else { - // Empty box for grandmother - echo '<table cellspacing="0" cellpadding="0" border="0"><tr>'; - echo '<td>'; - echo view('chart-box', ['individual' => null]); - echo '</td></tr></table>'; - } - echo '</td>'; - } - echo '</tr></table>'; - } - - /** - * print the children table for a family - * - * @param Family $family family - * @param string $childid child ID - * @param int $sosa child sosa number - * @param string $label indi label (descendancy booklet) - * @param bool $show_cousins display cousins on chart - * - * @return void - */ - public static function printFamilyChildren( - Family $family, - string $childid = '', - int $sosa = 0, - string $label = '', - bool $show_cousins = false - ): void { - $bheight = app(ModuleThemeInterface::class)->parameter('chart-box-y'); - $pbheight = $bheight + 14; - $children = $family->children(); - $numchil = $children->count(); - - echo '<table border="0" cellpadding="0" cellspacing="0"><tr>'; - if ($sosa > 0) { - echo '<td></td>'; - } - echo '<td><span class="subheaders">'; - if ($numchil === 0) { - echo I18N::translate('No children'); - } else { - echo I18N::plural('%s child', '%s children', $numchil, I18N::number($numchil)); - } - echo '</span>'; - - if ($sosa === 0 && Auth::isEditor($family->tree())) { - echo '<br>'; - echo '<a href="' . e(route('add-child-to-family', [ - 'gender' => 'U', - 'ged' => $family->tree()->name(), - 'xref' => $family->xref(), - ])) . '">' . I18N::translate('Add a child to this family') . '</a>'; - echo ' <a class="icon-sex_m_15x15" href="' . e(route('add-child-to-family', [ - 'gender' => 'M', - 'ged' => $family->tree()->name(), - 'xref' => $family->xref(), - ])) . '" title="', I18N::translate('son'), '"></a>'; - echo ' <a class="icon-sex_f_15x15" href="' . e(route('add-child-to-family', [ - 'gender' => 'F', - 'ged' => $family->tree()->name(), - 'xref' => $family->xref(), - ])) . '" title="', I18N::translate('daughter'), '"></a>'; - echo '<br><br>'; - } - echo '</td>'; - if ($sosa > 0) { - echo '<td></td><td></td>'; - } - echo '</tr>'; - - $nchi = 1; - - if ($children->isNotEmpty()) { - foreach ($children as $child) { - echo '<tr>'; - if ($sosa !== 0) { - if ($child->xref() === $childid) { - self::printSosaNumber($sosa, $childid, 'icons/arrow-up'); - } elseif (empty($label)) { - self::printDabovilleNumber('', '', 'icons/arrow-up'); - } else { - self::printDabovilleNumber($label . ($nchi++) . '.', '', 'icons/arrow-up'); - } - } - if ($child->isPendingAddition()) { - echo '<td class="new">'; - } elseif ($child->isPendingDeletion()) { - echo '<td class="old">'; - } else { - echo '<td>'; - } - echo view('chart-box', ['individual' => $child]); - echo '</td>'; - if ($sosa !== 0) { - // loop for all families where current child is a spouse - $famids = $child->spouseFamilies(); - $maxfam = count($famids) - 1; - for ($f = 0; $f <= $maxfam; $f++) { - // multiple marriages - if ($f > 0) { - echo '</tr><tr><td></td>'; - echo '<td style="text-align:end; vertical-align: top;">'; - //find out how many cousins there are to establish vertical line on second families - $kids = $famids[$f]->children()->count(); - - if ($show_cousins) { - if ($kids > 0) { - echo '<img height="' . ($kids * 80 / 2) . 'px"'; - } else { - echo '<img height="' . ($pbheight - 14) / 2 . 'px"'; - } - } elseif ($f === $maxfam) { - echo '<img height="' . ($bheight / 2) . 'px"'; - } else { - echo '<img height="' . $pbheight . 'px"'; - } - echo ' width="3" src="' . e(asset('css/images/vline.png')) . '">'; - echo '</td>'; - } - echo '<td class="details1" style="text-align:center;">'; - $spouse = $famids[$f]->spouse($child); - - $marr = $famids[$f]->facts(['MARR'])->first(); - $div = $famids[$f]->facts(['DIV'])->first(); - if ($marr) { - // marriage date - echo $marr->date()->minimumDate()->format('%Y'); - // divorce date - if ($div) { - echo '–', $div->date()->minimumDate()->format('%Y'); - } - echo '<img class="linea5 lined5 " width="100%" height="3" src="' . e(asset('css/images/hline.png')) . '">'; - } else { - echo '<img width="100%" height="3" src="' . e(asset('css/images/hline.png')) . '">'; - } - echo '</td>'; - // spouse information - echo '<td style="vertical-align: center;">'; - echo view('chart-box', ['individual' => $spouse]); - echo '</td>'; - // cousins - if ($show_cousins) { - self::printCousins($famids[$f]); - } - } - } - echo '</tr>'; - } - } elseif ($sosa < 1) { - // message 'no children' except for sosa - if (preg_match('/\n1 NCHI (\d+)/', $family->gedcom(), $match) && $match[1] === '0') { - echo '<tr><td><i class="icon-childless"></i> ' . I18N::translate('This family remained childless') . '</td></tr>'; - } - } - echo '</table><br>'; - } - - /** - * print a family with Sosa-Stradonitz numbering system - * ($rootid=1, father=2, mother=3 ...) - * - * @param Family $family family gedcom - * @param string $childid tree root ID - * @param int $sosa Sosa-Stradonitz number - * @param string $daboville d'Aboville number - * @param string $parid parent ID (descendancy booklet) - * @param string $gparid gd-parent ID (descendancy booklet) - * @param bool $show_cousins display cousins on chart - * - * @return void - */ - public static function printSosaFamily( - Family $family, - string $childid, - int $sosa, - string $daboville, - string $parid, - string $gparid, - bool $show_cousins - ): void { - echo '<hr>'; - echo '<p class="wt-family-break">'; - echo '<a name="', e($family->xref()), '"></a>'; - self::printFamilyParents($family, $sosa, $daboville, $parid, $gparid); - echo '<br>'; - echo '<table cellspacing="0" cellpadding="0" border="0"><tr><td>'; - self::printFamilyChildren($family, $childid, $sosa, $daboville, $show_cousins); - echo '</td></tr></table>'; - echo '<br>'; - } - - /** - * builds and returns sosa relationship name in the active language - * - * @param int $sosa Sosa number - * - * @return string - */ - public static function getSosaName(int $sosa): string - { - $path = ''; - - while ($sosa > 1) { - if ($sosa % 2 === 1) { - $path = 'mot' . $path; - } else { - $path = 'fat' . $path; - } - $sosa = intdiv($sosa, 2); - } - - return Functions::getRelationshipNameFromPath($path, null, null); - } - - /** - * print cousins list - * - * @param Family $family - * - * @return void - */ - private static function printCousins(Family $family): void - { - $bheight = app(ModuleThemeInterface::class)->parameter('chart-box-y'); - $fchildren = $family->children(); - $kids = $fchildren->count(); - - echo '<td>'; - if ($fchildren->isNotEmpty()) { - echo '<table cellspacing="0" cellpadding="0" border="0" ><tr>'; - if ($fchildren->count() > 1) { - echo '<td rowspan="', $kids, '"><img width="3px" height="', ($bheight * ($kids - 1)), 'px" src="', e(asset('css/images/vline.png')), '"></td>'; - } - $ctkids = $fchildren->count(); - $i = 1; - foreach ($fchildren as $fchil) { - if ($i === 1) { - echo '<td><img class="linea1" width="10px" height="3px" style="vertical-align:middle"'; - } else { - echo '<td><img class="linea1" width="10px" height="3px"'; - } - if (I18N::direction() === 'ltr') { - echo ' style="padding-right: 2px;"'; - } else { - echo ' style="padding-left: 2px;"'; - } - echo ' src="', e(asset('css/images/hline.png')), '"></td><td>'; - echo view('chart-box', ['individual' => $fchil]); - echo '</td></tr>'; - if ($i < $ctkids) { - echo '<tr>'; - $i++; - } - } - echo '</table>'; - } elseif (preg_match('/\n1 NCHI (\d+)/', $family->gedcom(), $match) && $match[1] === '0') { - // If there is known that there are no children (as opposed to no known children) - echo ' <i class="icon-childless" title="', I18N::translate('This family remained childless'), '"></i>'; - } - echo '</td>'; - } -} diff --git a/app/Functions/FunctionsRtl.php b/app/Functions/FunctionsRtl.php index ec77cc7c2b..1cd391be58 100644 --- a/app/Functions/FunctionsRtl.php +++ b/app/Functions/FunctionsRtl.php @@ -334,7 +334,7 @@ class FunctionsRtl } if ($newState != self::$currentState) { // A direction change has occurred - self::finishCurrentSpan($result, false); + self::finishCurrentSpan($result); self::$previousState = self::$currentState; self::$currentState = $newState; self::beginCurrentSpan($result); @@ -1116,7 +1116,7 @@ class FunctionsRtl } } else { $newLength = strlen($textSpan) + $countTrailingSpaces; - $textSpan = str_pad($textSpan, $newLength, ' ', STR_PAD_RIGHT); + $textSpan = str_pad($textSpan, $newLength, ' '); } } diff --git a/app/Module/AncestorsChartModule.php b/app/Module/AncestorsChartModule.php index 3fa337ff9b..31bd07b9ad 100644 --- a/app/Module/AncestorsChartModule.php +++ b/app/Module/AncestorsChartModule.php @@ -19,9 +19,6 @@ namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Contracts\UserInterface; -use Fisharebest\Webtrees\Functions\FunctionsCharts; -use Fisharebest\Webtrees\Functions\FunctionsPrint; -use Fisharebest\Webtrees\Gedcom; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Menu; @@ -41,12 +38,10 @@ class AncestorsChartModule extends AbstractModule implements ModuleChartInterfac // Chart styles protected const CHART_STYLE_TREE = 'tree'; - protected const CHART_STYLE_BOOKLET = 'booklet'; protected const CHART_STYLE_INDIVIDUALS = 'individuals'; protected const CHART_STYLE_FAMILIES = 'families'; // Defaults - protected const DEFAULT_COUSINS = false; protected const DEFAULT_STYLE = self::CHART_STYLE_TREE; protected const DEFAULT_GENERATIONS = '4'; @@ -130,7 +125,6 @@ class AncestorsChartModule extends AbstractModule implements ModuleChartInterfac Auth::checkIndividualAccess($individual); Auth::checkComponentAccess($this, 'chart', $tree, $user); - $show_cousins = (bool) $request->get('show_cousins', self::DEFAULT_COUSINS); $chart_style = $request->get('chart_style', self::DEFAULT_STYLE); $generations = (int) $request->get('generations', self::DEFAULT_GENERATIONS); @@ -145,9 +139,6 @@ class AncestorsChartModule extends AbstractModule implements ModuleChartInterfac case self::CHART_STYLE_TREE: return response(view('modules/ancestors-chart/tree', ['individual' => $individual, 'parents' => $individual->primaryChildFamily(), 'generations' => $generations, 'sosa' => 1])); - case self::CHART_STYLE_BOOKLET: - return $this->ancestorsBooklet($ancestors, $show_cousins); - case self::CHART_STYLE_INDIVIDUALS: return $this->ancestorsIndividuals($tree, $ancestors); @@ -159,7 +150,6 @@ class AncestorsChartModule extends AbstractModule implements ModuleChartInterfac $ajax_url = $this->chartUrl($individual, [ 'generations' => $generations, 'chart_style' => $chart_style, - 'show_cousins' => $show_cousins, 'ajax' => true, ]); @@ -173,7 +163,6 @@ class AncestorsChartModule extends AbstractModule implements ModuleChartInterfac 'maximum_generations' => self::MAXIMUM_GENERATIONS, 'minimum_generations' => self::MINIMUM_GENERATIONS, 'module_name' => $this->name(), - 'show_cousins' => $show_cousins, 'title' => $this->chartTitle($individual), ]); } @@ -223,32 +212,6 @@ class AncestorsChartModule extends AbstractModule implements ModuleChartInterfac } /** - * Show a booklet view of ancestors - * - * @TODO replace ob_start() with views. - * - * @param Collection $ancestors - * @param bool $show_cousins - * - * @return ResponseInterface - */ - protected function ancestorsBooklet(Collection $ancestors, bool $show_cousins): ResponseInterface - { - ob_start(); - - echo view('chart-box', ['individual' => $ancestors[1]]); - foreach ($ancestors as $sosa => $individual) { - foreach ($individual->childFamilies() as $family) { - FunctionsCharts::printSosaFamily($family, $individual->xref(), $sosa, '', '', '', $show_cousins); - } - } - - $html = ob_get_clean(); - - return response($html); - } - - /** * This chart can display its output in a number of styles * * @return array @@ -257,7 +220,6 @@ class AncestorsChartModule extends AbstractModule implements ModuleChartInterfac { return [ self::CHART_STYLE_TREE => I18N::translate('Tree'), - self::CHART_STYLE_BOOKLET => I18N::translate('Booklet'), self::CHART_STYLE_INDIVIDUALS => I18N::translate('Individuals'), self::CHART_STYLE_FAMILIES => I18N::translate('Families'), ]; diff --git a/app/Module/DescendancyChartModule.php b/app/Module/DescendancyChartModule.php index d3efdee47d..9b7a9ef330 100644 --- a/app/Module/DescendancyChartModule.php +++ b/app/Module/DescendancyChartModule.php @@ -19,11 +19,6 @@ namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Contracts\UserInterface; -use Fisharebest\Webtrees\Family; -use Fisharebest\Webtrees\Functions\FunctionsCharts; -use Fisharebest\Webtrees\Functions\FunctionsPrint; -use Fisharebest\Webtrees\Gedcom; -use Fisharebest\Webtrees\GedcomTag; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Menu; @@ -32,7 +27,6 @@ use Fisharebest\Webtrees\Tree; use Illuminate\Support\Collection; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Ramsey\Uuid\Uuid; /** * Class DescendancyChartModule @@ -42,10 +36,9 @@ class DescendancyChartModule extends AbstractModule implements ModuleChartInterf use ModuleChartTrait; // Chart styles - public const CHART_STYLE_TREE = 0; - public const CHART_STYLE_BOOKLET = 1; - public const CHART_STYLE_INDIVIDUALS = 2; - public const CHART_STYLE_FAMILIES = 3; + public const CHART_STYLE_TREE = 'tree'; + public const CHART_STYLE_INDIVIDUALS = 'individuals'; + public const CHART_STYLE_FAMILIES = 'families'; // Defaults public const DEFAULT_STYLE = self::CHART_STYLE_TREE; @@ -137,7 +130,7 @@ class DescendancyChartModule extends AbstractModule implements ModuleChartInterf Auth::checkIndividualAccess($individual); Auth::checkComponentAccess($this, 'chart', $tree, $user); - $chart_style = (int) ($request->getQueryParams()['chart_style'] ?? self::DEFAULT_STYLE); + $chart_style = $request->getQueryParams()['chart_style'] ?? self::DEFAULT_STYLE; $generations = (int) ($request->getQueryParams()['generations'] ?? self::DEFAULT_GENERATIONS); $generations = min($generations, self::MAXIMUM_GENERATIONS); @@ -183,7 +176,7 @@ class DescendancyChartModule extends AbstractModule implements ModuleChartInterf Auth::checkIndividualAccess($individual); - $chart_style = (int) $request->getQueryParams()['chart_style']; + $chart_style = $request->getQueryParams()['chart_style']; $generations = (int) $request->getQueryParams()['generations']; $generations = min($generations, self::MAXIMUM_GENERATIONS); @@ -194,9 +187,6 @@ class DescendancyChartModule extends AbstractModule implements ModuleChartInterf default: return response(view('modules/descendancy_chart/tree', ['individual' => $individual, 'generations' => $generations, 'daboville' => '1'])); - case self::CHART_STYLE_BOOKLET: - return $this->descendantsBooklet($individual, $generations); - case self::CHART_STYLE_INDIVIDUALS: $individuals = $chart_service->descendants($individual, $generations - 1); @@ -247,53 +237,6 @@ class DescendancyChartModule extends AbstractModule implements ModuleChartInterf } /** - * Show a booklet view of descendants - * - * @TODO replace ob_start() with views. - * - * @param Individual $individual - * @param int $generations - * - * @return ResponseInterface - */ - private function descendantsBooklet(Individual $individual, int $generations): ResponseInterface - { - ob_start(); - - $this->printChildFamily($individual, $generations); - - $html = ob_get_clean(); - - return response($html); - } - - /** - * Print a child family - * - * @param Individual $individual - * @param int $depth - the descendancy depth to show - * @param string $daboville - d'Aboville number - * @param string $gpid - * - * @return void - */ - private function printChildFamily(Individual $individual, $depth, $daboville = '1.', $gpid = ''): void - { - if ($depth < 2) { - return; - } - - $i = 1; - - foreach ($individual->spouseFamilies() as $family) { - FunctionsCharts::printSosaFamily($family, '', -1, $daboville, $individual->xref(), $gpid, false); - foreach ($family->children() as $child) { - $this->printChildFamily($child, $depth - 1, $daboville . ($i++) . '.', $individual->xref()); - } - } - } - - /** * This chart can display its output in a number of styles * * @return string[] @@ -302,7 +245,6 @@ class DescendancyChartModule extends AbstractModule implements ModuleChartInterf { return [ self::CHART_STYLE_TREE => I18N::translate('Tree'), - self::CHART_STYLE_BOOKLET => I18N::translate('Booklet'), self::CHART_STYLE_INDIVIDUALS => I18N::translate('Individuals'), self::CHART_STYLE_FAMILIES => I18N::translate('Families'), ]; diff --git a/app/Module/PedigreeMapModule.php b/app/Module/PedigreeMapModule.php index 24c35a8550..13d3927b1f 100644 --- a/app/Module/PedigreeMapModule.php +++ b/app/Module/PedigreeMapModule.php @@ -23,7 +23,7 @@ use Fisharebest\Webtrees\Exceptions\IndividualAccessDeniedException; use Fisharebest\Webtrees\Exceptions\IndividualNotFoundException; use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Family; -use Fisharebest\Webtrees\Functions\FunctionsCharts; +use Fisharebest\Webtrees\Functions\Functions; use Fisharebest\Webtrees\GedcomTag; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; @@ -32,6 +32,7 @@ use Fisharebest\Webtrees\Menu; use Fisharebest\Webtrees\Services\ChartService; use Fisharebest\Webtrees\Tree; use Fisharebest\Webtrees\Webtrees; +use function intdiv; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -282,7 +283,7 @@ class PedigreeMapModule extends AbstractModule implements ModuleChartInterface if ($sosa > 1) { $addbirthtag = true; - $tag = ucfirst(FunctionsCharts::getSosaName($sosa)); + $tag = ucfirst($this->getSosaName($sosa)); } return [ @@ -427,4 +428,27 @@ class PedigreeMapModule extends AbstractModule implements ModuleChartInterface ), ]); } + + /** + * builds and returns sosa relationship name in the active language + * + * @param int $sosa Sosa number + * + * @return string + */ + private function getSosaName(int $sosa): string + { + $path = ''; + + while ($sosa > 1) { + if ($sosa % 2 === 1) { + $path = 'mot' . $path; + } else { + $path = 'fat' . $path; + } + $sosa = intdiv($sosa, 2); + } + + return Functions::getRelationshipNameFromPath($path); + } } diff --git a/resources/views/modules/ancestors-chart/page.phtml b/resources/views/modules/ancestors-chart/page.phtml index 420f1f2a39..28d54e54a7 100644 --- a/resources/views/modules/ancestors-chart/page.phtml +++ b/resources/views/modules/ancestors-chart/page.phtml @@ -36,7 +36,6 @@ </legend> <div class="col-sm-9 wt-page-options-value"> <?= view('components/radios-inline', ['name' => 'chart_style', 'options' => $chart_styles, 'selected' => $chart_style]) ?> - <?= view('components/checkbox', ['label' => I18N::translate('Show cousins'), 'name' => 'show_cousins', 'disabled' => $chart_style !== 'booklet', 'checked' => $show_cousins]) ?> </div> </div> </fieldset> @@ -50,12 +49,3 @@ </form> <div class="wt-ajax-load wt-page-content wt-chart wt-chart-ancestors" data-ajax-url="<?= e($ajax_url) ?>"></div> - -<?php View::push('javascript') ?> -<script> - // The "show cousins" option is only available for the "booklet" style. - $("input[name=chart_style]").change(function () { - $("input[name=show_cousins]").prop("disabled", $(this).val() !== "booklet"); - }); -</script> -<?php View::endpush() ?> diff --git a/tests/app/Functions/FunctionsChartsTest.php b/tests/app/Functions/FunctionsChartsTest.php deleted file mode 100644 index 92168d0078..0000000000 --- a/tests/app/Functions/FunctionsChartsTest.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php -/** - * webtrees: online genealogy - * Copyright (C) 2019 webtrees development team - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -declare(strict_types=1); - -namespace Fisharebest\Webtrees\Functions; - -/** - * Unit tests for the global functions in the file includes/functions/functions_charts.php - */ -class FunctionsChartsTest extends \Fisharebest\Webtrees\TestCase -{ - /** - * Test that the class exists - * - * @return void - */ - public function testClassExists(): void - { - $this->assertTrue(class_exists('\Fisharebest\Webtrees\Functions\FunctionsCharts')); - } -} |
