diff options
| -rw-r--r-- | app/Module/ModuleConfigInterface.php | 1 | ||||
| -rw-r--r-- | app/Module/RelationshipsChartModule.php | 99 | ||||
| -rw-r--r-- | relationship.php | 6 |
3 files changed, 104 insertions, 2 deletions
diff --git a/app/Module/ModuleConfigInterface.php b/app/Module/ModuleConfigInterface.php index 5bbdcc6782..81625844e8 100644 --- a/app/Module/ModuleConfigInterface.php +++ b/app/Module/ModuleConfigInterface.php @@ -21,7 +21,6 @@ namespace Fisharebest\Webtrees\Module; interface ModuleConfigInterface { /** * The URL to a page where the user can modify the configuration of this module. - * These links are displayed in the admin page menu. * * @return string */ diff --git a/app/Module/RelationshipsChartModule.php b/app/Module/RelationshipsChartModule.php index 590aef19ac..bf2992e216 100644 --- a/app/Module/RelationshipsChartModule.php +++ b/app/Module/RelationshipsChartModule.php @@ -16,14 +16,21 @@ namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Auth; +use Fisharebest\Webtrees\Controller\PageController; +use Fisharebest\Webtrees\Filter; +use Fisharebest\Webtrees\FlashMessages; +use Fisharebest\Webtrees\Functions\FunctionsEdit; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Menu; use Fisharebest\Webtrees\Individual; +use Fisharebest\Webtrees\Tree; /** * Class RelationshipsChartModule */ -class RelationshipsChartModule extends AbstractModule implements ModuleChartInterface { +class RelationshipsChartModule extends AbstractModule implements ModuleConfigInterface, ModuleChartInterface { + const DEFAULT_FIND_ALL_PATHS = '1'; + /** * How should this module be labelled on tabs, menus, etc.? * @@ -87,4 +94,94 @@ class RelationshipsChartModule extends AbstractModule implements ModuleChartInte public function getBoxChartMenu(Individual $individual) { return $this->getChartMenu($individual); } + + /** + * This is a general purpose hook, allowing modules to respond to routes + * of the form module.php?mod=FOO&mod_action=BAR + * + * @param string $mod_action + */ + public function modAction($mod_action) { + switch ($mod_action) { + case 'admin': + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $this->saveConfig(); + } else { + $this->editConfig(); + } + break; + default: + http_response_code(404); + } + } + + /** + * Display a form to edit configuration settings. + */ + private function editConfig() { + $controller = new PageController; + $controller + ->restrictAccess(Auth::isAdmin()) + ->setPageTitle(I18N::translate('Chart preferences') . ' ā ' . $this->getTitle()) + ->pageHeader(); + + ?> + <ol class="breadcrumb small"> + <li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li> + <li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li> + <li class="active"><?php echo $controller->getPageTitle(); ?></li> + </ol> + <h1><?php echo $controller->getPageTitle(); ?></h1> + + <form method="post"> + <?php foreach (Tree::getAll() as $tree): ?> + <h2><?php echo $tree->getTitleHtml() ?></h2> + <fieldset class="form-group"> + <legend class="control-label col-sm-3"> + <?php echo I18N::translate('Option to find all relationships'); ?> + </legend> + <div class="col-sm-9"> + <?php echo FunctionsEdit::radioButtons('find-all-paths-' . $tree->getTreeId(), array(0 => I18N::translate('hide'), 1 => I18N::translate('show')), $tree->getPreference('FIND_ALL_PATHS', self::DEFAULT_FIND_ALL_PATHS), 'class="radio-inline"'); ?> + <p class="small text-muted"> + <?php echo I18N::translate('Searching for all possible relationships can take a lot of time in complex trees.') ?> + </p> + </div> + </fieldset> + <?php endforeach; ?> + + <div class="form-group"> + <div class="col-sm-offset-3 col-sm-9"> + <button type="submit" class="btn btn-primary"> + <i class="fa fa-check"></i> + <?php echo I18N::translate('save'); ?> + </button> + </div> + </div> + </form> + <?php + } + + /** + * Save updated configuration settings. + */ + private function saveConfig() { + if (Auth::isAdmin()) { + foreach (Tree::getAll() as $tree) { + $tree->setPreference('FIND_ALL_PATHS', Filter::post('find-all-paths-' . $tree->getTreeId())); + } + + FlashMessages::addMessage(I18N::translate('The preferences for the chart ā%sā have been updated.', $this->getTitle()), 'success'); + } + + header('Location: ' . WT_BASE_URL . 'module.php?mod=' . $this->getName() . '&mod_action=admin'); + } + + /** + * The URL to a page where the user can modify the configuration of this module. + * + * @return string + */ + public function getConfigLink() { + return 'module.php?mod=' . $this->getName() . '&mod_action=admin'; + } } diff --git a/relationship.php b/relationship.php index 762b2ed691..3a4477b824 100644 --- a/relationship.php +++ b/relationship.php @@ -26,6 +26,7 @@ use Fisharebest\Webtrees\Controller\RelationshipController; use Fisharebest\Webtrees\Functions\Functions; use Fisharebest\Webtrees\Functions\FunctionsEdit; use Fisharebest\Webtrees\Functions\FunctionsPrint; +use Fisharebest\Webtrees\Module\RelationshipsChartModule; define('WT_SCRIPT_NAME', 'relationship.php'); require './includes/session.php'; @@ -91,6 +92,7 @@ if ($person1 && $person2) { <a href="#" onclick="var x = jQuery('#pid1').val(); jQuery('#pid1').val(jQuery('#pid2').val()); jQuery('#pid2').val(x); return false;"><?php echo /* I18N: Reverse the order of two individuals */ I18N::translate('Swap individuals') ?></a> </td> <td class="optionbox"> + <?php if ($WT_TREE->getPreference('FIND_ALL_PATHS', RelationshipsChartModule::DEFAULT_FIND_ALL_PATHS)): ?> <label> <input type="radio" name="find_all" value="0" <?php echo $find_all ? '' : 'checked' ?>> <?php echo I18N::translate('Find the closest relationships') ?> @@ -100,6 +102,10 @@ if ($person1 && $person2) { <input type="radio" name="find_all" value="1"<?php echo $find_all ? 'checked' : '' ?>> <?php echo I18N::translate('Find all possible relationships') ?> </label> + <?php else: ?> + <?php echo I18N::translate('Find the closest relationships') ?> + <input type="hidden" name="find_all" value="0"> + <?php endif; ?> </td> </tr> </tbody> |
