Completed
Push — master ( b746e6...94717f )
by Jonathan
06:37
created

SosaListFamView::renderContent()   F

Complexity

Conditions 44
Paths > 20000

Size

Total Lines 333
Code Lines 202

Duplication

Lines 76
Ratio 22.82 %

Importance

Changes 0
Metric Value
dl 76
loc 333
rs 2
c 0
b 0
f 0
cc 44
eloc 202
nc 51840003
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * webtrees-lib: MyArtJaub library for webtrees
4
 *
5
 * @package MyArtJaub\Webtrees
6
 * @subpackage Sosa
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\Sosa\Views;
12
13
use Fisharebest\Webtrees\Date;
14
use Fisharebest\Webtrees\Filter;
15
use Fisharebest\Webtrees\GedcomTag;
16
use Fisharebest\Webtrees\I18N;
17
use Fisharebest\Webtrees\Individual;
18
use Fisharebest\Webtrees\Place;
19
use MyArtJaub\Webtrees\Constants;
20
use MyArtJaub\Webtrees\Family;
21
use MyArtJaub\Webtrees\Functions\FunctionsPrint;
22
use MyArtJaub\Webtrees\Functions\FunctionsPrintLists;
23
use MyArtJaub\Webtrees\Module\ModuleManager;
24
use MyArtJaub\Webtrees\Mvc\View\AbstractView;
25
26
/**
27
 * View for SosaList@sosalist@fam
28
 */
29
class SosaListFamView extends AbstractView {
30
        
31
	/**
32
	 * {@inhericDoc}
33
	 * @see \MyArtJaub\Webtrees\Mvc\View\AbstractView::renderContent()
34
	 */
35
    protected function renderContent() { 
36
        
37
        if($this->data->get('has_sosa', false)) {
38
            $table_id = $this->data->get('table_id');            
39
        ?>   
40
        
41
		<div id="sosa-fam-list" class="sosa-list">
42
			<table id="<?php echo $table_id; ?>">
43
				<thead>
44
					<tr>
45
						<th colspan="14">
46
							<div class="btn-toolbar">
47
								<div class="btn-group">
48
									<button
49
										type="button"
50
										data-filter-column="12"
51
										data-filter-value="N"
52
										class="ui-state-default"
53
										title="<?php echo I18N::translate('Show individuals who are alive or couples where both partners are alive.'); ?>"
54
									>
55
									<?php echo I18N::translate('Both alive');?>
56
									</button>
57
									<button
58
										type="button"
59
										data-filter-column="12"
60
										data-filter-value="W"
61
										class="ui-state-default"
62
										title="<?php echo I18N::translate('Show couples where only the female partner is dead.'); ?>"
63
									>
64
									<?php echo I18N::translate('Widower');?>
65
									</button>
66
									<button
67
										type="button"
68
										data-filter-column="12"
69
										data-filter-value="H"
70
										class="ui-state-default"
71
										title="<?php echo I18N::translate('Show couples where only the male partner is dead.'); ?>"
72
									>
73
									<?php echo I18N::translate('Widow'); ?>
74
									</button>
75
									<button
76
										type="button"
77
										data-filter-column="12"
78
										data-filter-value="Y"
79
										class="ui-state-default"
80
										title="<?php echo I18N::translate('Show individuals who are dead or couples where both partners are dead.'); ?>"
81
									>
82
									<?php echo I18N::translate('Both dead'); ?>
83
									</button>
84
								</div>
85
								<div class="btn-group">
86
									<button
87
										type="button"
88
										data-filter-column="13"
89
										data-filter-value="R"
90
										class="ui-state-default"
91
										title="<?php echo I18N::translate('Show “roots” couples or individuals. These individuals may also be called “patriarchs”. They are individuals who have no parents recorded in the database.'); ?>"
92
									>
93
									<?php echo I18N::translate('Roots'); ?>
94
									</button>
95
									<button
96
										type="button"
97
										data-filter-column="13"
98
										data-filter-value="L"
99
										class="ui-state-default"
100
										title="<?php echo I18N::translate('Show “leaves” couples or individuals. These are individuals who are alive but have no children recorded in the database.'); ?>"
101
									>
102
									<?php echo I18N::translate('Leaves'); ?>
103
									</button>
104
								</div>
105
								<div class="btn-group">
106
									<button
107
										type="button"
108
										data-filter-column="11"
109
										data-filter-value="U"
110
										class="ui-state-default"
111
										title="<?php echo I18N::translate('Show couples with an unknown marriage date.'); ?>"
112
									>
113
									<?php echo GedcomTag::getLabel('MARR'); ?>
114
									</button>
115
									<button
116
										type="button"
117
										data-filter-column="11"
118
										data-filter-value="YES"
119
										class="ui-state-default"
120
										title="<?php echo I18N::translate('Show couples who married more than 100 years ago.'); ?>"
121
									>
122
									<?php echo GedcomTag::getLabel('MARR'); ?>&gt;100
123
									</button>
124
									<button
125
										type="button"
126
										data-filter-column="11"
127
										data-filter-value="Y100"
128
										class="ui-state-default"
129
										title="<?php echo I18N::translate('Show couples who married within the last 100 years.'); ?>"
130
									>
131
									<?php echo GedcomTag::getLabel('MARR'); ?>&lt;=100
132
									</button>
133
									<button
134
										type="button"
135
										data-filter-column="11"
136
										data-filter-value="D"
137
										class="ui-state-default"
138
										title="<?php echo I18N::translate('Show divorced couples.'); ?>"
139
									>
140
									<?php echo GedcomTag::getLabel('DIV'); ?>
141
									</button>
142
									<button
143
										type="button"
144
										data-filter-column="11"
145
										data-filter-value="M"
146
										class="ui-state-default"
147
										title="<?php echo I18N::translate('Show couples where either partner married more than once.'); ?>"
148
									>
149
									<?php echo I18N::translate('Multiple marriages'); ?>
150
									</button>
151
								</div>
152
							</div>
153
						</th>
154
					</tr>
155
					<tr>
156
						<th><?php echo I18N::translate('Sosa'); ?></th>
157
						<th><?php echo GedcomTag::getLabel('GIVN'); ?></th>
158
						<th><?php echo GedcomTag::getLabel('SURN'); ?></th>
159
						<th><?php echo GedcomTag::getLabel('AGE'); ?></th>
160
						<th><?php echo GedcomTag::getLabel('GIVN'); ?></th>
161
						<th><?php echo GedcomTag::getLabel('SURN'); ?></th>
162
						<th><?php echo GedcomTag::getLabel('AGE'); ?></th>
163
						<th><?php echo GedcomTag::getLabel('MARR'); ?></th>
164
						<th><?php echo GedcomTag::getLabel('PLAC'); ?></th>';
165
						<?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) { ?>
166
						<th><i class="icon-source" title="<?php echo I18N::translate('Sourced marriage'); ?>" border="0"></i></th>
167
						<?php } else { ?>
168
						<th>&nbsp;</th>
169
						<?php } ?>
170
						<th><i class="icon-children" title="<?php echo I18N::translate('Children'); ?>"></i></th>
171
						<th hidden>MARR</th>
172
						<th hidden>DEAT</th>
173
						<th hidden>TREE</th>
174
					</tr>
175
				</thead>
176
				<tbody>
177
			
178
			<?php foreach($this->data->get('sosa_list') as $sosa => $family) {
179
			    /** @var \Fisharebest\Webtrees\Family $person */
180
181
			    //PERSO Create decorator for Family
182
			    $dfamily = new Family($family);
183
			    
184
			    $husb = $family->getHusband();
185
			    if (is_null($husb)) {
186
			        $husb = new Individual('H', '0 @H@ INDI', null, $family->getTree());
187
			    }
188
			    $wife = $family->getWife();
189
			    if (is_null($wife)) {
190
			        $wife = new Individual('W', '0 @W@ INDI', null, $family->getTree());
191
			    }
192
			    
193
			    $mdate=$family->getMarriageDate();
194
			    
195
			    if ($family->isPendingAddtion()) {
196
			        $class = ' class="new"';
197
			    } elseif ($family->isPendingDeletion()) {
198
			        $class = ' class="old"';
199
			    } else {
200
			        $class = '';
201
			    }
202
			    ?>			
203
        		<tr <?= $class ?>>
204
        			<td class="transparent" data-sort="<?= $sosa ?>"><?= I18N::translate('%1$d/%2$d', $sosa, ($sosa + 1) % 10) ?></td>
205
        			<!--  HUSBAND -->
206
        			<?php list($surn_givn, $givn_surn) = FunctionsPrintLists::sortableNames($husb); ?>
207
        			<td colspan="2" data-sort="<?= Filter::escapeHtml($givn_surn) ?>">        			
208 View Code Duplication
        			<?php foreach ($husb->getAllNames() as $num=>$name) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209
        				if ($name['type']=='NAME') {
210
        					$title='';
211
        				} else {
212
        					$title='title="'.strip_tags(GedcomTag::getLabel($name['type'], $husb)).'"';
213
        				}
214
        				if ($num==$husb->getPrimaryName()) {
215
        					$class=' class="name2"';
216
        					$sex_image=$husb->getSexImage();
217
        				} else {
218
        					$class='';
219
        					$sex_image='';
220
        				} ?>
221
        				<a <?php echo $title.' '.$class; ?> href="<?php echo $husb->getHtmlUrl(); ?>">
222
        					<?php echo \Fisharebest\Webtrees\Functions\FunctionsPrint::highlightSearchHits($name['full']); ?>
223
        				</a>
224
        				<?php echo $sex_image;
225
        				echo implode('&nbsp;',
226
        				    \MyArtJaub\Webtrees\Hook\HookProvider::getInstance()
227
        				    ->get('hRecordNameAppend')
228
        				    ->executeOnlyFor(array(Constants::MODULE_MAJ_SOSA_NAME),  $husb, 'smaller')); 
229
        				?>
230
        				<br/>
231
            		<?php }
232
            		echo $husb->getPrimaryParentsNames('parents details1', 'none');
233
            		?>
234
            		</td>
235
            		<td hidden data-sort="<?= Filter::escapeHtml($surn_givn) ?>"></td>
236
            		<?php $hdate=$husb->getBirthDate(); ?>
237
            		<td class="center" data-sort="<?= Date::getAge($hdate, $mdate, 1) ?>"><?= Date::getAge($hdate, $mdate, 2) ?></td>
238
            		<!--  WIFE -->            		
239
        			<?php list($surn_givn, $givn_surn) = FunctionsPrintLists::sortableNames($wife); ?>
240
        			<td colspan="2">
241 View Code Duplication
        			<?php foreach ($wife->getAllNames() as $num=>$name) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
242
        				if ($name['type']=='NAME') {
243
        					$title='';
244
        				} else {
245
        					$title='title="'.strip_tags(GedcomTag::getLabel($name['type'], $wife)).'"';
246
        				}
247
        				if ($num==$wife->getPrimaryName()) {
248
        					$class=' class="name2"';
249
        					$sex_image=$wife->getSexImage();
250
        				} else {
251
        					$class='';
252
        					$sex_image='';
253
        				} ?>
254
        				<a <?= $title.' '.$class ?> href="<?= $wife->getHtmlUrl() ?>">
255
        					<?= \Fisharebest\Webtrees\Functions\FunctionsPrint::highlightSearchHits($name['full']) ?>
256
        				</a>
257
        				<?= $sex_image;
258
        				echo implode('&nbsp;',
259
        				    \MyArtJaub\Webtrees\Hook\HookProvider::getInstance()
260
        				    ->get('hRecordNameAppend')
261
        				    ->executeOnlyFor(array(Constants::MODULE_MAJ_SOSA_NAME),  $wife, 'smaller'));
262
        				?>
263
        				<br/>
264
            		<?php }
265
            		echo $wife->getPrimaryParentsNames('parents details1', 'none');
266
            		?>
267
            		</td>
268
            		<td hidden data-sort="<?= Filter::escapeHtml($surn_givn) ?>"></td>
269
            		<?php $wdate=$wife->getBirthDate(); ?>
270
            		<td class="center" data-sort="<?= Date::getAge($wdate, $mdate, 1) ?>"><?= Date::getAge($wdate, $mdate, 2) ?></td>
271
            		<td data-sort="<?= $mdate->julianDay() ?>"><?php 
272
            		if ($marriage_dates = $family->getAllMarriageDates()) {
273
        				foreach ($marriage_dates as $n => $marriage_date) {
274
        					if ($n) { echo '<br>'; } ?>
275
        					<div><?= $marriage_date->display(true) ?></div>
276
        				<?php }
277
            		} elseif ($family->getFacts('_NMR')) {
278
            		    echo I18N::translate('no');
279
            		} elseif ($family->getFacts('MARR')) {
280
            		    echo I18N::translate('yes');
281
            		} else {
282
            		    echo '&nbsp;';
283
            		} ?>
284
            		</td>
285
            		<td><?php 
286 View Code Duplication
            		foreach ($family->getAllMarriagePlaces() as $n => $marriage_place) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
287
				        $tmp = new Place($marriage_place, $family->getTree());
288
        				if ($n) { ?><br><?php } ?>
289
        				<a href="'<?= $tmp->getURL() ?>" title="<?= strip_tags($tmp->getFullName()) ?>">
290
        					<?= \Fisharebest\Webtrees\Functions\FunctionsPrint::highlightSearchHits($tmp->getShortName()) ?>
291
        				</a>
292
        			<?php  } ?>
293
        			</td>
294 View Code Duplication
        			<?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
295
				        $isMSourced = $dfamily->isMarriageSourced(); ?>
296
				   	<td data-sort=<?= $isMSourced ?>><?= FunctionsPrint::formatIsSourcedIcon('E', $isMSourced, 'MARR', 1, 'medium') ?></td>
0 ignored issues
show
Bug introduced by
It seems like $isMSourced defined by $dfamily->isMarriageSourced() on line 295 can also be of type boolean; however, MyArtJaub\Webtrees\Funct...::formatIsSourcedIcon() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
297
					<?php } else { ?>
298
					<td>&nbsp;</td>
299
					<?php } ?>
300
					<td class="center" data-sort="<?= $family->getNumberOfChildren() ?>">
301
						<?= I18N::number($family->getNumberOfChildren()) ?>
302
					</td>
303
					<td hidden><?php 
304 View Code Duplication
					if (!$mdate->isOK()) { echo 'U'; }
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
305
					else {
306
					    if (Date::compare($mdate, new Date(date('Y') - 100)) > 0) { echo 'Y100'; }
307
					    else { echo 'YES'; }
308
					}
309
					if ($family->getFacts(WT_EVENTS_DIV)) { echo 'D'; }
310
					if (count($husb->getSpouseFamilies()) > 1 || count($wife->getSpouseFamilies()) > 1) {
311
					    echo 'M';
312
					} ?>
313
					</td>
314
					<td hidden><?php 
315
			         if ($husb->isDead() && $wife->isDead()) { echo 'Y'; }
316 View Code Duplication
			         if ($husb->isDead() && !$wife->isDead()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
317
        				if ($wife->getSex() == 'F') { echo 'H'; }
318
        				if ($wife->getSex() == 'M') { echo 'W'; } // male partners
319
        			}
320 View Code Duplication
        			if (!$husb->isDead() && $wife->isDead()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
321
        				if ($husb->getSex() == 'M') { echo 'W'; }
322
        				if ($husb->getSex() == 'F') { echo  'H'; }  // female partners
323
        			}
324
        			if (!$husb->isDead() && !$wife->isDead()) { echo 'N'; } ?>
325
        			</td>
326
        			<td hidden><?php 
327
			         if (!$husb->getChildFamilies() && !$wife->getChildFamilies()) { echo 'R'; }
328
			         elseif (!$husb->isDead() && !$wife->isDead() && $family->getNumberOfChildren() < 1) { echo 'L'; }
329
			         else { echo '&nbsp;'; } ?>
330
			         </td>
331
				</tr>
332
        	<?php } ?>
333
        	</tbody>
334
        	<tfoot>
335
				<tr>
336
					<th colspan="14">
337
						<div class="btn-toolbar">
338
							<div class="btn-group">
339
								<button type="button" class="ui-state-default btn-toggle-parents">
340
									<?= I18N::translate('Show parents') ?>
341
								</button>
342
								<button id="btn-toggle-statistics-<?= $table_id ?>" type="button" class="ui-state-default btn-toggle-statistics">
343
									<?= I18N::translate('Show statistics charts') ?>
344
								</button>
345
							</div>
346
						</div>
347
					</th>
348
				</tr>
349
			</tfoot>
350
        	</table>
351
				<div id="fam_list_table-charts_<?php echo $table_id ?>" style="display:none">
352
					<table class="list-charts">
353
						<tr>
354
							<td><?= $this->data->get('chart_births') ?></td>
355
							<td><?= $this->data->get('chart_marriages') ?></td>
356
						</tr>
357
						<tr>
358
							<td colspan="2"><?= $this->data->get('chart_ages') ?></td>
359
						</tr>
360
					</table>
361
				</div>
362
			</div>
363
		<?php } else { ?>
364
        <p class="warning"><?= I18N::translate('No family has been found for generation %d', $this->data->get('generation')) ?></p>
365
        <?php 
366
		}
367
    }
368
    
369
}
370