diff --git a/app/Module/ChartsBlockModule.php b/app/Module/ChartsBlockModule.php index 95120068922..3396a26f784 100644 --- a/app/Module/ChartsBlockModule.php +++ b/app/Module/ChartsBlockModule.php @@ -112,8 +112,18 @@ public function getBlock(Tree $tree, int $block_id, string $context, array $conf $title = $module->chartTitle($individual); $chart_url = $module->chartUrl($individual, [ 'ajax' => true, - 'generations' => 3, - 'layout' => PedigreeChartModule::STYLE_RIGHT, + 'generations' => $this->getBlockSetting($block_id, 'pedigree_generations', '3'), + 'layout' => $this->getBlockSetting( + $block_id, + 'pedigree_style', + PedigreeChartModule::DEFAULT_STYLE + ), + 'style' => $this->getBlockSetting( + $block_id, + 'pedigree_style', + PedigreeChartModule::DEFAULT_STYLE + ), + // Note: some modules use 'layout', others 'style' ]); $content = view('modules/charts/chart', [ 'block_id' => $block_id, @@ -132,7 +142,7 @@ public function getBlock(Tree $tree, int $block_id, string $context, array $conf $title = $module->chartTitle($individual); $chart_url = $module->chartUrl($individual, [ 'ajax' => true, - 'generations' => 2, + 'generations' => $this->getBlockSetting($block_id, 'descendants_generations', '2'), 'chart_style' => DescendancyChartModule::CHART_STYLE_TREE, ]); $content = view('modules/charts/chart', [ @@ -153,7 +163,7 @@ public function getBlock(Tree $tree, int $block_id, string $context, array $conf $title = $module->chartTitle($individual); $chart_url = $module->chartUrl($individual, [ 'ajax' => true, - 'generations' => 2, + 'generations' => $this->getBlockSetting($block_id, 'hourglass_generations', '2'), ]); $content = view('modules/charts/chart', [ 'block_id' => $block_id, @@ -231,9 +241,17 @@ public function saveBlockConfiguration(ServerRequestInterface $request, int $blo { $type = Validator::parsedBody($request)->string('type'); $xref = Validator::parsedBody($request)->isXref()->string('xref'); + $pedigree_generations = Validator::parsedBody($request)->integer('pedigree_generations'); + $pedigree_style = Validator::parsedBody($request)->string('pedigree_style'); + $descendants_generations = Validator::parsedBody($request)->integer('descendants_generations'); + $hourglass_generations = Validator::parsedBody($request)->integer('hourglass_generations'); $this->setBlockSetting($block_id, 'type', $type); $this->setBlockSetting($block_id, 'pid', $xref); + $this->setBlockSetting($block_id, 'pedigree_generations', (string) $pedigree_generations); + $this->setBlockSetting($block_id, 'pedigree_style', $pedigree_style); + $this->setBlockSetting($block_id, 'descendants_generations', (string) $descendants_generations); + $this->setBlockSetting($block_id, 'hourglass_generations', (string) $hourglass_generations); } /** @@ -253,21 +271,56 @@ public function editBlockConfiguration(Tree $tree, int $block_id): string $type = $this->getBlockSetting($block_id, 'type', 'pedigree'); $xref = $this->getBlockSetting($block_id, 'pid', $default_xref); - $charts = [ - 'pedigree' => I18N::translate('Pedigree'), - 'descendants' => I18N::translate('Descendants'), - 'hourglass' => I18N::translate('Hourglass chart'), - 'treenav' => I18N::translate('Interactive tree'), - ]; + $charts = []; + // Only add charts that are available + $pedigreeModule = $this->module_service->findByInterface(PedigreeChartModule::class)->first(); + if ($pedigreeModule instanceof PedigreeChartModule) { + $charts['pedigree'] = I18N::translate('Pedigree'); + $pedigree_max_generations = $pedigreeModule::MAXIMUM_GENERATIONS; + $pedigree_min_generations = $pedigreeModule::MINIMUM_GENERATIONS; + $pedigree_styles = $pedigreeModule->styles(I18N::direction()); + } + $descendantsModule = $this->module_service->findByInterface(DescendancyChartModule::class)->first(); + if ($descendantsModule instanceof DescendancyChartModule) { + $charts['descendants'] = I18N::translate('Descendants'); + $descendants_max_generations = $descendantsModule::MAXIMUM_GENERATIONS; + $descendants_min_generations = $descendantsModule::MINIMUM_GENERATIONS; + } + $hourglassModule = $this->module_service->findByInterface(HourglassChartModule::class)->first(); + if ($hourglassModule instanceof HourglassChartModule) { + $charts['hourglass'] = I18N::translate('Hourglass chart'); + $hourglass_max_generations = $hourglassModule::MAXIMUM_GENERATIONS; + $hourglass_min_generations = $hourglassModule::MINIMUM_GENERATIONS; + } + $treeModule = $this->module_service->findByInterface(InteractiveTreeModule::class)->first(); + if ($treeModule instanceof InteractiveTreeModule) { + $charts['treenav'] = I18N::translate('Interactive tree'); + } uasort($charts, I18N::comparator()); + $pedigree_generations = $this->getBlockSetting($block_id, 'pedigree_generations', '3'); + $pedigree_style = $this->getBlockSetting($block_id, 'pedigree_style', $pedigreeModule::DEFAULT_STYLE); + $descendants_generations = $this->getBlockSetting($block_id, 'descendants_generations', '2'); + $hourglass_generations = $this->getBlockSetting($block_id, 'hourglass_generations', '2'); + $individual = Registry::individualFactory()->make($xref, $tree); return view('modules/charts/config', [ - 'charts' => $charts, - 'individual' => $individual, - 'tree' => $tree, - 'type' => $type, + 'charts' => $charts, + 'individual' => $individual, + 'tree' => $tree, + 'type' => $type, + 'pedigree_generations' => $pedigree_generations ?? null, + 'pedigree_max_generations' => $pedigree_max_generations ?? null, + 'pedigree_min_generations' => $pedigree_min_generations ?? null, + 'pedigree_style' => $pedigree_style ?? null, + 'pedigree_styles' => $pedigree_styles ?? null, + 'descendants_generations' => $descendants_generations ?? null, + 'descendants_max_generations' => $descendants_max_generations ?? null, + 'descendants_min_generations' => $descendants_min_generations ?? null, + 'hourglass_generations' => $hourglass_generations ?? null, + 'hourglass_max_generations' => $hourglass_max_generations ?? null, + 'hourglass_min_generations' => $hourglass_min_generations ?? null, ]); } } diff --git a/app/Module/DescendancyChartModule.php b/app/Module/DescendancyChartModule.php index 67c5965039c..8eadc46faf9 100644 --- a/app/Module/DescendancyChartModule.php +++ b/app/Module/DescendancyChartModule.php @@ -56,8 +56,8 @@ class DescendancyChartModule extends AbstractModule implements ModuleChartInterf ]; // Limits - protected const MINIMUM_GENERATIONS = 2; - protected const MAXIMUM_GENERATIONS = 10; + public const MINIMUM_GENERATIONS = 2; + public const MAXIMUM_GENERATIONS = 10; private ChartService $chart_service; diff --git a/app/Module/HourglassChartModule.php b/app/Module/HourglassChartModule.php index 1c9a2943002..633c533ca39 100644 --- a/app/Module/HourglassChartModule.php +++ b/app/Module/HourglassChartModule.php @@ -53,8 +53,8 @@ class HourglassChartModule extends AbstractModule implements ModuleChartInterfac ]; // Limits - protected const MINIMUM_GENERATIONS = 2; - protected const MAXIMUM_GENERATIONS = 10; + public const MINIMUM_GENERATIONS = 2; + public const MAXIMUM_GENERATIONS = 10; /** * Initialization. diff --git a/app/Module/PedigreeChartModule.php b/app/Module/PedigreeChartModule.php index da96380c936..7ec62f2af16 100644 --- a/app/Module/PedigreeChartModule.php +++ b/app/Module/PedigreeChartModule.php @@ -58,8 +58,8 @@ class PedigreeChartModule extends AbstractModule implements ModuleChartInterface ]; // Limits - protected const MINIMUM_GENERATIONS = 2; - protected const MAXIMUM_GENERATIONS = 12; + public const MINIMUM_GENERATIONS = 2; + public const MAXIMUM_GENERATIONS = 12; // For RTL languages protected const MIRROR_STYLE = [ @@ -356,7 +356,7 @@ protected function individualLink(Individual $individual, string $style, int $ge * * @return array */ - protected function styles(string $direction): array + public function styles(string $direction): array { // On right-to-left pages, the CSS will mirror the chart, so we need to mirror the label. if ($direction === 'rtl') { diff --git a/resources/views/modules/charts/config.phtml b/resources/views/modules/charts/config.phtml index dc0946c0001..f1a6d25eac4 100644 --- a/resources/views/modules/charts/config.phtml +++ b/resources/views/modules/charts/config.phtml @@ -8,7 +8,18 @@ use Fisharebest\Webtrees\Tree; /** * @var array $charts - * @var Individual|null $individual + * @var Individual $individual + * @var int $pedigree_generations + * @var int $pedigree_max_generations + * @var int $pedigree_min_generations + * @var string $pedigree_style + * @var array $pedigree_styles + * @var int $descendants_generations + * @var int $descendants_max_generations + * @var int $descendants_min_generations + * @var int $hourglass_generations + * @var int $hourglass_max_generations + * @var int $hourglass_min_generations * @var Tree $tree * @var string $type */ @@ -34,3 +45,69 @@ use Fisharebest\Webtrees\Tree; 'xref', 'individual' => $individual, 'tree' => $tree]) ?> + + + + + + + + \ No newline at end of file