Passed
Branch main (f9aaf7)
by Jonathan
14:43
created

IsSourcedStatusHook   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A recordNamePrepend() 0 3 1
A __construct() 0 4 1
A recordNameAppend() 0 21 4
A module() 0 3 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) 2011-2021, 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\IsSourced\Hooks;
16
17
use Fisharebest\Webtrees\GedcomRecord;
18
use Fisharebest\Webtrees\Individual;
19
use Fisharebest\Webtrees\Module\ModuleInterface;
20
use MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface;
21
use MyArtJaub\Webtrees\Module\IsSourced\Services\SourceStatusService;
22
23
/**
24
 * Hook for displaying the source status for a record next to its name.
25
 */
26
class IsSourcedStatusHook implements RecordNameTextExtenderInterface
27
{
28
    private ModuleInterface $module;
29
    private SourceStatusService $source_status_service;
30
31
    /**
32
     * Constructor for IsSourcedStatusHook
33
     *
34
     * @param ModuleInterface $module
35
     * @param SourceStatusService $source_status_service
36
     */
37
    public function __construct(ModuleInterface $module, SourceStatusService $source_status_service)
38
    {
39
        $this->module = $module;
40
        $this->source_status_service = $source_status_service;
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module()
46
     */
47
    public function module(): ModuleInterface
48
    {
49
        return $this->module;
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend()
55
     */
56
    public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
57
    {
58
        return '';
59
    }
60
61
    /**
62
     * {@inheritDoc}
63
     * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend()
64
     */
65
    public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
66
    {
67
        if ($use_long && $record instanceof Individual) {
68
            return
69
                view($this->module()->name() . '::icons/source-status', [
70
                    'module_name' => $this->module()->name(),
71
                    'source_status' => $this->source_status_service->sourceStatusForRecord($record),
72
                    'context'  => 'INDI',
73
                    'size_style' => $size ]) .
74
                view($this->module()->name() . '::icons/source-status', [
75
                    'module_name' => $this->module()->name(),
76
                    'source_status' => $this->source_status_service->sourceStatusForBirth($record),
77
                    'context'  => 'INDI:BIRT',
78
                    'size_style' => $size ]) .
79
                ($record->isDead() ? view($this->module()->name() . '::icons/source-status', [
80
                    'module_name' => $this->module()->name(),
81
                    'source_status' => $this->source_status_service->sourceStatusForDeath($record),
82
                    'context'  => 'INDI:DEAT',
83
                    'size_style' => $size ]) : '') ;
84
        }
85
        return '';
86
    }
87
}
88