summaryrefslogtreecommitdiff
path: root/app/Module/RelationshipsChartModule.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@gmail.com>2016-04-11 21:23:23 +0100
committerGreg Roach <fisharebest@gmail.com>2016-04-11 21:31:51 +0100
commit45ac604b8c1c4ff96484102219e1708ef5863994 (patch)
tree8a98546b84a27e023e17d681a71f74f84ca8cf8a /app/Module/RelationshipsChartModule.php
parent4eb71cfaf9604652cd62536a0b3b56c6dfd715ad (diff)
downloadwebtrees-45ac604b8c1c4ff96484102219e1708ef5863994.tar.gz
webtrees-45ac604b8c1c4ff96484102219e1708ef5863994.tar.bz2
webtrees-45ac604b8c1c4ff96484102219e1708ef5863994.zip
Add configuration option to relationship chart
Diffstat (limited to 'app/Module/RelationshipsChartModule.php')
-rw-r--r--app/Module/RelationshipsChartModule.php99
1 files changed, 98 insertions, 1 deletions
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() . '&amp;mod_action=admin';
+ }
}