-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgeneric.php
174 lines (143 loc) · 5.49 KB
/
generic.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
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
<?php
// This file contains generic code to create a tab module
declare(strict_types=1);
namespace JesseWebDotCom\Webtrees\Module\TimelineTab;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\View;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\FlashMessages;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleTabTrait;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\Module\ModuleConfigTrait;
use Fisharebest\Webtrees\Module\ModuleTabInterface;
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Localization\Translation;
require 'FactsHelper.php';
require 'TimelineHelper.php';
/**
* Class TimelineTabModule
*/
class TimelineTabModule extends AbstractModule implements ModuleTabInterface, ModuleCustomInterface, ModuleConfigInterface
{
use ModuleTabTrait;
use ModuleCustomTrait;
use ModuleConfigTrait;
/**
* list of const for module administration
*/
public const CUSTOM_TITLE = 'Timeline';
public const CUSTOM_MODULE = 'webtrees-tab-timeline';
public const CUSTOM_DESCRIPTION = 'A webtrees timeline tab for an individual (similar to Ancestry or FamilySearch)';
public const CUSTOM_AUTHOR = 'JesseWebDotCom';
public const CUSTOM_WEBSITE = 'https://github.com/JesseWebDotCom/' . self::CUSTOM_MODULE . '/';
public const CUSTOM_VERSION = '0.0.1';
public const CUSTOM_LAST = 'https://github.com/JesseWebDotCom/' .
self::CUSTOM_MODULE. '/releases';
private $linked_record_service;
public function getAdminAction(): ResponseInterface
{
$this->layout = 'layouts/administration';
return $this->viewResponse($this->name() . '::settings', [
'familyfacts' => $this->getPreference('familyfacts', '1'),
'associatefacts' => $this->getPreference('associatefacts', '1'),
'relativefacts' => $this->getPreference('relativefacts', '1'),
'historicfacts' => $this->getPreference('historicfacts', '0'),
'title' => $this->title()
]);
}
// Save the user preference.
public function postAdminAction(ServerRequestInterface $request): ResponseInterface
{
$params = (array) $request->getParsedBody();
if ($params['save'] === '1') {
// print_r($params);
$this->setPreference('familyfacts', $params['familyfacts'] ?? '0');
$this->setPreference('associatefacts', $params['associatefacts'] ?? '0');
$this->setPreference('relativefacts', $params['relativefacts'] ?? '0');
$this->setPreference('historicfacts', $params['historicfacts'] ?? '0');
$message = I18N::translate('The preferences for the module “%s” have been updated.', $this->title());
FlashMessages::addMessage($message, 'success');
}
return redirect($this->getConfigLink());
}
public function title(): string
{
return I18N::translate(self::CUSTOM_TITLE);
}
public function description(): string
{
return I18N::translate(self::CUSTOM_DESCRIPTION);
}
public function customModuleAuthorName(): string
{
return self::CUSTOM_AUTHOR;
}
public function customModuleVersion(): string
{
return self::CUSTOM_VERSION;
}
public function customModuleLatestVersionUrl(): string
{
return self::CUSTOM_LAST;
}
public function customModuleSupportUrl(): string
{
return self::CUSTOM_WEBSITE;
}
public function resourcesFolder(): string
{
return __DIR__ . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR;
}
public function defaultTabOrder(): int
{
return -1; // ensure tab is first
}
public function hasTabContent(Individual $individual): bool
{
return true;
}
public function isGrayedOut(Individual $individual): bool
{
return false;
}
/** {@inheritdoc} */
public function getTabContent(Individual $individual): string
{
$timelineHelper = new TimelineHelper();
return $timelineHelper->getTimelineContent($this, $individual);
}
/** {@inheritdoc} */
public function canLoadAjax(): bool
{
return false;
}
public function __construct()
{
// IMPORTANT - the constructor is called on *all* modules, even ones that are disabled.
// It is also called before the webtrees framework is initialised, and so other components will not yet exist.
}
public function boot(): void
{
// Here is also a good place to register any views (templates) used by the module.
// This command allows the module to use: view($this->name() . '::', 'fish')
// to access the file ./resources/views/fish.phtml
View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/');
}
public function customTranslations(string $language): array
{
$lang_dir = $this->resourcesFolder() . 'lang/';
$extensions = array('mo', 'po');
foreach ($extensions as &$extension) {
$file = $lang_dir . $language . '.' . $extension;
if (file_exists($file)) {
return (new Translation($file))->asArray();
}
}
return [];
}
}
return new TimelineTabModule;