|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
|
5
|
|
|
* |
|
6
|
|
|
* @package MyArtJaub\Webtrees |
|
7
|
|
|
* @subpackage Sosa |
|
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2009-2022, Jonathan Jaubart |
|
10
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace MyArtJaub\Webtrees\Module\Sosa\Http\RequestHandlers; |
|
16
|
|
|
|
|
17
|
|
|
use Fisharebest\Webtrees\Auth; |
|
18
|
|
|
use Fisharebest\Webtrees\DefaultUser; |
|
19
|
|
|
use Fisharebest\Webtrees\FlashMessages; |
|
20
|
|
|
use Fisharebest\Webtrees\I18N; |
|
21
|
|
|
use Fisharebest\Webtrees\Registry; |
|
22
|
|
|
use Fisharebest\Webtrees\Validator; |
|
23
|
|
|
use Fisharebest\Webtrees\Services\UserService; |
|
24
|
|
|
use MyArtJaub\Webtrees\Module\Sosa\Services\SosaRecordsService; |
|
25
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
26
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
27
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Request handler for updating the Sosa de-cujus |
|
31
|
|
|
*/ |
|
32
|
|
|
class SosaConfigAction implements RequestHandlerInterface |
|
33
|
|
|
{ |
|
34
|
|
|
private UserService $user_service; |
|
35
|
|
|
private SosaRecordsService $sosa_record_service; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Constructor for SosaConfigAction Request Handler |
|
39
|
|
|
* |
|
40
|
|
|
* @param UserService $user_service |
|
41
|
|
|
* @param SosaRecordsService $sosa_records_service |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(UserService $user_service, SosaRecordsService $sosa_records_service) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->user_service = $user_service; |
|
46
|
|
|
$this->sosa_record_service = $sosa_records_service; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritDoc} |
|
51
|
|
|
* @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52
|
|
|
*/ |
|
53
|
|
|
public function handle(ServerRequestInterface $request): ResponseInterface |
|
54
|
|
|
{ |
|
55
|
|
|
$tree = Validator::attributes($request)->tree(); |
|
56
|
|
|
|
|
57
|
|
|
$user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
|
58
|
|
|
$root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
|
59
|
|
|
$max_gen = Validator::parsedBody($request)->integer( |
|
60
|
|
|
'sosa-maxgen', |
|
61
|
|
|
$this->sosa_record_service->maxSystemGenerations() |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
if (Auth::id() === $user_id || ($user_id === -1 && Auth::isManager($tree))) { |
|
65
|
|
|
$user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
66
|
|
|
if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
67
|
|
|
$tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
68
|
|
|
$tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
69
|
|
|
FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
70
|
|
|
return Registry::responseFactory()->redirect(SosaConfig::class, [ |
|
71
|
|
|
'tree' => $tree->name(), |
|
72
|
|
|
'compute' => 'yes', |
|
73
|
|
|
'user_id' => $user_id |
|
74
|
|
|
]); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
79
|
|
|
return Registry::responseFactory()->redirect(SosaConfig::class, ['tree' => $tree->name()]); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|