Skip to content

Commit

Permalink
Add configuration option to relationship chart
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed Apr 11, 2016
1 parent 4eb71cf commit 12f9f0a
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 2 deletions.
1 change: 0 additions & 1 deletion app/Module/ModuleConfigInterface.php
Expand Up @@ -21,7 +21,6 @@
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
*/
Expand Down
99 changes: 98 additions & 1 deletion app/Module/RelationshipsChartModule.php
Expand Up @@ -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.?
*
Expand Down Expand Up @@ -87,4 +94,94 @@ public function getChartMenu(Individual $individual) {
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';
}
}
6 changes: 6 additions & 0 deletions relationship.php
Expand Up @@ -26,6 +26,7 @@
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';
Expand Down Expand Up @@ -91,6 +92,7 @@
<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') ?>
Expand All @@ -100,6 +102,10 @@
<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>
Expand Down

0 comments on commit 12f9f0a

Please sign in to comment.