Passed
Push — master ( eb013e...37f747 )
by Jonathan
04:35
created

MiscExtensionsModule::hPrintFooter()   A

Complexity

Conditions 6
Paths 9

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 9
nop 0
dl 0
loc 21
rs 9.2222
c 0
b 0
f 0
1
<?php
2
/**
3
 * webtrees-lib: MyArtJaub library for webtrees
4
 *
5
 * @package MyArtJaub\Webtrees
6
 * @subpackage MiscExtensions
7
 * @author Jonathan Jaubart <[email protected]>
8
 * @copyright Copyright (c) 2009-2016, Jonathan Jaubart
9
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
10
 */
11
namespace MyArtJaub\Webtrees\Module;
12
13
use Fisharebest\Webtrees\Auth;
14
use Fisharebest\Webtrees\Controller\IndividualController;
15
use Fisharebest\Webtrees\Filter;
16
use Fisharebest\Webtrees\I18N;
17
use Fisharebest\Webtrees\Module\AbstractModule;
18
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
19
use Fisharebest\Webtrees\Theme;
20
use Fisharebest\Webtrees\User;
21
use MyArtJaub\Webtrees\Functions\FunctionsPrint;
22
use MyArtJaub\Webtrees\Globals;
23
use MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface;
24
use MyArtJaub\Webtrees\Hook\HookInterfaces\PageFooterExtenderInterface;
25
use MyArtJaub\Webtrees\Hook\HookInterfaces\PageHeaderExtenderInterface;
26
use MyArtJaub\Webtrees\Hook\HookSubscriberInterface;
27
use MyArtJaub\Webtrees\Individual;
28
29
/**
30
 * MiscExtension Module
31
 */
32
class MiscExtensionsModule extends AbstractModule 
33
implements HookSubscriberInterface, IndividualHeaderExtenderInterface, PageHeaderExtenderInterface, PageFooterExtenderInterface, ModuleConfigInterface
34
{    
35
    /** @var string For custom modules - link for support, upgrades, etc. */
36
    const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib';
37
    
38
    /**
39
     * {@inheritDoc}
40
     * @see \Fisharebest\Webtrees\Module\AbstractModule::getTitle()
41
     */
42
    public function getTitle() {
43
        return I18N::translate('Miscellaneous extensions');
44
    }
45
    
46
   /**
47
    * {@inheritDoc}
48
    * @see \Fisharebest\Webtrees\Module\AbstractModule::getDescription()
49
    */
50
    public function getDescription() {
51
        return I18N::translate('Miscellaneous extensions for <strong>webtrees</strong>.');
52
    }
53
    
54
    /**
55
     * {@inhericDoc}
56
     */
57
    public function modAction($mod_action) {
58
        \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action);
59
    }
60
    
61
    /**
62
     * {@inhericDoc}
63
     * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
64
     */
65
    public function getConfigLink() {
66
        return 'module.php?mod=' . $this->getName() . '&amp;mod_action=AdminConfig';
67
    }
68
    
69
    /**
70
     * {@inheritDoc}
71
     * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks()
72
     */
73
	public function getSubscribedHooks() {
74
		return array(
75
		    'hExtendIndiHeaderLeft' => 20,
76
		    'hPrintHeader' => 20,
77
		    'hPrintFooter' => 20
78
		);
79
	}
80
	
81
	/**
82
	 * {@inheritDoc}
83
	 * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderIcons()
84
	 */
85
	public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) { }
86
	
87
	/**
88
	 * {@inheritDoc}
89
	 * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderLeft()
90
	 */
91
	public function hExtendIndiHeaderLeft(IndividualController $ctrlIndi) { 
92
	    $res = '';
93
	    $dindi = new Individual($ctrlIndi->getSignificantIndividual());
94
	    $titles = $dindi->getTitles();
95
	    if(count($titles)>0){
96
	        $res = '
97
	            <dl>
98
	               <dt class="label">'.I18N::translate('Titles').'</dt>';
99
            foreach($titles as $title=>$props){
100
                $res .= 
101
                    '<dd class="field">' . $title. ' ' .
102
                    FunctionsPrint::getListFromArray($props) .
103
                    '</dd>';
104
            }
105
            $res .=  '</dl>';
106
        }
107
	    return array( 'indi-header-titles' , $res);	    
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('indi-header-titles', $res) returns the type array<integer,string> which is incompatible with the return type mandated by MyArtJaub\Webtrees\Hook\...hExtendIndiHeaderLeft() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
108
	}
109
	
110
	/**
111
	 * {@inheritDoc}
112
	 * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderRight()
113
	 */
114
	public function hExtendIndiHeaderRight(IndividualController $ctrlIndi) { }
115
		
116
	/**
117
	 * {@inheritDoc}
118
	 * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\PageHeaderExtenderInterface::hPrintHeader()
119
	 */
120
	public function hPrintHeader() {
121
	    $html = '';
122
	    if($this->getSetting('MAJ_ADD_HTML_HEADER', 0) == 1){
123
	        if(Auth::accessLevel(Globals::getTree()) >= $this->getSetting('MAJ_SHOW_HTML_HEADER', Auth::PRIV_HIDE)  && !Filter::getBool('noheader')){
124
	            $html .= $this->getSetting('MAJ_HTML_HEADER', '');
125
	        }
126
	    }	
127
	    return $html;
128
	}
129
	
130
	/**
131
	 * {@inheritDoc}
132
	 * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\PageFooterExtenderInterface::hPrintFooter()
133
	 */
134
	public function hPrintFooter() {
135
	    $wt_tree = Globals::getTree();
136
	    $html = '';
137
	    if($this->getSetting('MAJ_DISPLAY_CNIL', 0) == 1){
138
	        $html .= '<br/>';
139
	        $html .= '<div class="center">';
140
	        $cnil_ref = $this->getSetting('MAJ_CNIL_REFERENCE', '');
141
	        if($cnil_ref != ''){
142
	            $html .= I18N::translate('This site has been notified to the French National Commission for Data protection (CNIL) and registered under number %s. ', $cnil_ref);
143
	        }
144
	        $html .= I18N::translate('In accordance with the French Data protection Act (<em>Loi Informatique et Libertés</em>) of January 6th, 1978, you have the right to access, modify, rectify and delete personal information that pertains to you. To exercice this right, please contact %s, and provide your name, address and a proof of your identity.',
145
	            Theme::theme()->contactLink(User::find($wt_tree->getPreference('WEBMASTER_USER_ID'))));
0 ignored issues
show
Bug introduced by
It seems like $wt_tree->getPreference('WEBMASTER_USER_ID') can also be of type string; however, parameter $user_id of Fisharebest\Webtrees\User::find() does only seem to accept integer|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

145
	            Theme::theme()->contactLink(User::find(/** @scrutinizer ignore-type */ $wt_tree->getPreference('WEBMASTER_USER_ID'))));
Loading history...
146
	        $html .= '</div>';
147
	    }
148
	    
149
	    if($this->getSetting('MAJ_ADD_HTML_FOOTER', 0) == 1){
150
	        if(Auth::accessLevel($wt_tree) >= $this->getSetting('MAJ_SHOW_HTML_FOOTER', Auth::PRIV_HIDE)  && !Filter::getBool('nofooter')){
151
	            $html .= $this->getSetting('MAJ_HTML_FOOTER', '');
152
	        }
153
	    }
154
	    return $html;
155
	}
156
	
157
}
158