forked from fisharebest/webtrees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_trees_unconnected.php
102 lines (86 loc) · 3.31 KB
/
admin_trees_unconnected.php
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
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2017 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;
use Fisharebest\Algorithm\ConnectedComponent;
use Fisharebest\Webtrees\Controller\PageController;
/** @global Tree $WT_TREE */
global $WT_TREE;
require 'includes/session.php';
$controller = new PageController;
$controller
->restrictAccess(Auth::isManager($WT_TREE))
->setPageTitle(I18N::translate('Find unrelated individuals') . ' — ' . $WT_TREE->getTitleHtml())
->pageHeader();
$associates = Filter::getBool('associates');
if ($associates) {
$sql = "SELECT l_from, l_to FROM `##link` WHERE l_file = :tree_id AND l_type IN ('FAMS', 'FAMC', 'ASSO', '_ASSO')";
} else {
$sql = "SELECT l_from, l_to FROM `##link` WHERE l_file = :tree_id AND l_type IN ('FAMS', 'FAMC')";
}
$rows = Database::prepare($sql)->execute([
'tree_id' => $WT_TREE->getTreeId(),
])->fetchAll();
$graph = [];
foreach ($rows as $row) {
$graph[$row->l_from][$row->l_to] = 1;
$graph[$row->l_to][$row->l_from] = 1;
}
$algorithm = new ConnectedComponent($graph);
$components = $algorithm->findConnectedComponents();
$root = $controller->getSignificantIndividual();
$root_id = $root->getXref();
/** @var Individual[][] */
$individual_groups = [];
$group_number = 1;
foreach ($components as $key => $component) {
if (!in_array($root_id, $component)) {
$individuals = [];
foreach ($component as $xref) {
$individual = Individual::getInstance($xref, $WT_TREE);
if ($individual instanceof Individual) {
$individuals[] = $individual;
}
}
$individual_groups[$group_number++] = $individuals;
}
}
echo Bootstrap4::breadcrumbs([
'admin.php' => I18N::translate('Control panel'),
'admin_trees_manage.php' => I18N::translate('Manage family trees'),
], $controller->getPageTitle());
?>
<h1><?= $controller->getPageTitle() ?></h1>
<form class="form-inline">
<div class="row form-group">
<input type="hidden" name="ged" value="<?= $WT_TREE->getNameHtml() ?>">
<label for="associates"><?= I18N::translate('Include associates') ?></label>
<input type="checkbox" value="1" id="associates" name="associates" <?= $associates ? 'checked' : '' ?>>
</div>
<button type="submit">
<?= I18N::translate('update') ?>
</button>
</form>
<p><?= I18N::translate('These groups of individuals are not related to %s.', $root->getFullName()) ?></p>
<?php foreach ($individual_groups as $group): ?>
<h2><?= I18N::plural('%s individual', '%s individuals', count($group), I18N::number(count($group))) ?></h2>
<ul>
<?php foreach ($group as $individual): ?>
<li>
<a href="<?= $individual->getHtmlUrl() ?>"><?= $individual->getFullName() ?></a>
</li>
<?php endforeach ?>
</ul>
<?php endforeach ?>