1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2016 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/>.
*/
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\Individual;
use Fisharebest\Webtrees\Menu;
use Fisharebest\Webtrees\Tree;
/**
* Class RelationshipsChartModule
*/
class RelationshipsChartModule extends AbstractModule implements ModuleConfigInterface, ModuleChartInterface {
/** It would be more correct to use PHP_INT_MAX, but this isn't friendly in URLs */
const UNLIMITED_RECURSION = 99;
/** By default new trees allow unlimited recursion */
const DEFAULT_RECURSION = self::UNLIMITED_RECURSION;
/**
* How should this module be labelled on tabs, menus, etc.?
*
* @return string
*/
public function getTitle() {
return /* I18N: Name of a module/chart */ I18N::translate('Relationships');
}
/**
* A sentence describing what this module does.
*
* @return string
*/
public function getDescription() {
return /* I18N: Description of the “RelationshipsChart” module */ I18N::translate('A chart displaying relationships between two individuals.');
}
/**
* What is the default access level for this module?
*
* Some modules are aimed at admins or managers, and are not generally shown to users.
*
* @return int
*/
public function defaultAccessLevel() {
return Auth::PRIV_PRIVATE;
}
/**
* Return a menu item for this chart.
*
* @param Individual $individual
*
* @return Menu|null
*/
public function getChartMenu(Individual $individual) {
$tree = $individual->getTree();
$gedcomid = $tree->getUserPreference(Auth::user(), 'gedcomid');
if ($gedcomid) {
return new Menu(
I18N::translate('Relationship to me'),
'relationship.php?pid1=' . $gedcomid . '&pid2=' . $individual->getXref() . '&ged=' . $tree->getNameUrl(),
'menu-chart-relationship',
array('rel' => 'nofollow')
);
} else {
return new Menu(
I18N::translate('Relationships'),
'relationship.php?pid1=' . $individual->getXref() . '&ged=' . $tree->getNameUrl(),
'menu-chart-relationship',
array('rel' => 'nofollow')
);
}
}
/**
* Return a menu item for this chart - for use in individual boxes.
*
* @param Individual $individual
*
* @return Menu|null
*/
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);
}
}
/**
* Possible options for the recursion option
*/
private function recursionOptions() {
return array(
0 => I18N::translate('none'),
1 => I18N::number(1),
2 => I18N::number(2),
3 => I18N::number(3),
PHP_INT_MAX => I18N::translate('unlimited'),
);
}
/**
* 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: Configuration option */I18N::translate('How much recursion to use when searching for relationships'); ?>
</legend>
<div class="col-sm-9">
<?php echo FunctionsEdit::radioButtons('relationship-recursion-' . $tree->getTreeId(), $this->recursionOptions(), $tree->getPreference('RELATIONSHIP_RECURSION', self::DEFAULT_RECURSION), '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('RELATIONSHIP_RECURSION', Filter::post('relationship-recursion-' . $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';
}
}
|