Passed
Push — feature/code-analysis ( e964aa...4fe35d )
by Jonathan
14:33
created

IsSourcedModule   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 100
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A title() 0 3 1
A hasSidebarContent() 0 3 1
A customModuleVersion() 0 3 1
A listSubscribedHooks() 0 5 1
A bodyContent() 0 3 1
A description() 0 3 1
A headContent() 0 3 1
A getSidebarContent() 0 20 1
1
<?php
2
3
/**
4
 * webtrees-lib: MyArtJaub library for webtrees
5
 *
6
 * @package MyArtJaub\Webtrees
7
 * @subpackage IsSourced
8
 * @author Jonathan Jaubart <[email protected]>
9
 * @copyright Copyright (c) 2009-2022, Jonathan Jaubart
10
 * @license https://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\IsSourced;
16
17
use Fisharebest\Webtrees\Family;
18
use Fisharebest\Webtrees\I18N;
19
use Fisharebest\Webtrees\Individual;
20
use Fisharebest\Webtrees\Module\AbstractModule;
21
use Fisharebest\Webtrees\Module\ModuleGlobalInterface;
22
use Fisharebest\Webtrees\Module\ModuleGlobalTrait;
23
use Fisharebest\Webtrees\Module\ModuleSidebarInterface;
24
use Fisharebest\Webtrees\Module\ModuleSidebarTrait;
25
use MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface;
26
use MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface;
27
use MyArtJaub\Webtrees\Module\ModuleMyArtJaubTrait;
28
use MyArtJaub\Webtrees\Module\IsSourced\Hooks\IsSourcedStatusColumnsHook;
29
use MyArtJaub\Webtrees\Module\IsSourced\Hooks\IsSourcedStatusHook;
30
use MyArtJaub\Webtrees\Module\IsSourced\Services\SourceStatusService;
31
32
/**
33
 * IsSourced Module
34
 */
35
class IsSourcedModule extends AbstractModule implements
36
    ModuleMyArtJaubInterface,
37
    ModuleGlobalInterface,
38
    ModuleSidebarInterface,
39
    ModuleHookSubscriberInterface
40
{
41
    use ModuleMyArtJaubTrait;
42
    use ModuleGlobalTrait;
43
    use ModuleSidebarTrait;
44
45
    /**
46
     * {@inheritDoc}
47
     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
48
     */
49
    public function title(): string
50
    {
51
        return I18N::translate('Sourced events');
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
57
     */
58
    public function description(): string
59
    {
60
        return I18N::translate('Indicate if events related to an record are sourced.');
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
66
     */
67
    public function customModuleVersion(): string
68
    {
69
        return '2.1.1-v.1';
70
    }
71
72
    /**
73
     * {@inheritDoc}
74
     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
75
     */
76
    public function headContent(): string
77
    {
78
        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent()
84
     */
85
    public function bodyContent(): string
86
    {
87
        return '<script src="' . $this->assetUrl('js/issourced.min.js') . '"></script>';
88
    }
89
90
    /**
91
     * {@inheritDoc}
92
     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
93
     */
94
    public function hasSidebarContent(Individual $individual): bool
95
    {
96
        return true;
97
    }
98
99
    /**
100
     * {@inheritDoc}
101
     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent()
102
     */
103
    public function getSidebarContent(Individual $individual): string
104
    {
105
        /** @var SourceStatusService $source_status_service */
106
        $source_status_service = app(SourceStatusService::class);
107
108
        $spouse_families_status = $individual->spouseFamilies()->map(
109
            function (Family $sfamily) use ($source_status_service): array {
110
                return [ $sfamily, $source_status_service->sourceStatusForMarriage($sfamily)];
111
            }
112
        )->filter(function (array $item): bool {
113
            return $item[1]->isSet();
114
        });
115
116
        return view($this->name() . '::sidebar/content', [
117
            'module_name'               => $this->name(),
118
            'individual'                =>  $individual,
119
            'source_status_individual'  =>  $source_status_service->sourceStatusForRecord($individual),
120
            'source_status_birth'       =>  $source_status_service->sourceStatusForBirth($individual),
121
            'source_status_marriages'   =>  $spouse_families_status,
122
            'source_status_death'       =>  $source_status_service->sourceStatusForDeath($individual)
123
        ]);
124
    }
125
126
    /**
127
     * {@inheritDoc}
128
     * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
129
     */
130
    public function listSubscribedHooks(): array
131
    {
132
        return [
133
            app()->makeWith(IsSourcedStatusHook::class, [ 'module' => $this ]),
134
            app()->makeWith(IsSourcedStatusColumnsHook::class, [ 'module' => $this ])
135
        ];
136
    }
137
}
138