Completed
Pull Request — master (#1)
by
unknown
03:00
created

mpedigree.php ➔ pedigree_main()   F

Complexity

Conditions 35
Paths > 20000

Size

Total Lines 284
Code Lines 126

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 35
eloc 126
nc 4294967295
nop 1
dl 0
loc 284
rs 2
c 0
b 0
f 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 318 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
// -------------------------------------------------------------------------
3
4
require_once dirname(dirname(__DIR__)) . '/mainfile.php';
5
6
$moduleDirName = basename(__DIR__);
7
xoops_loadLanguage('main', $moduleDirName);
8
9
// Include any common code for this module.
10
require_once(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php');
11
xoops_load('XoopsRequest');
12
13
$xoopsOption['template_main'] = 'pedigree_mpedigree.tpl';
14
15
include $GLOBALS['xoops']->path('/header.php');
16
17
//get module configuration
18
$moduleHandler = xoops_getHandler('module');
19
$module        = $moduleHandler->getByDirname('pedigree');
20
$configHandler = xoops_getHandler('config');
21
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
22
23
//always start with Anika
24
$pedId = XoopsRequest::getInt('pedid', 0, 'GET');
25
//$pedId = $_GET['pedid'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26
//draw pedigree
27
28
$queryString = '
29
SELECT d.Id as d_id,
30
d.NAAM as d_naam,
31
d.roft as d_roft,
32
f.Id as f_id,
33
f.NAAM as f_naam,
34
m.Id as m_id,
35
m.NAAM as m_naam,
36
ff.Id as ff_id,
37
ff.NAAM as ff_naam,
38
mf.Id as mf_id,
39
mf.NAAM as mf_naam,
40
fm.Id as fm_id,
41
fm.NAAM as fm_naam,
42
mm.Id as mm_id,
43
mm.NAAM as mm_naam,
44
fff.Id as fff_id,
45
fff.NAAM as fff_naam,
46
ffm.Id as ffm_id,
47
ffm.NAAM as ffm_naam,
48
fmf.Id as fmf_id,
49
fmf.NAAM as fmf_naam,
50
fmm.Id as fmm_id,
51
fmm.NAAM as fmm_naam,
52
mmf.Id as mmf_id,
53
mmf.NAAM as mmf_naam,
54
mff.Id as mff_id,
55
mff.NAAM as mff_naam,
56
mfm.Id as mfm_id,
57
mfm.NAAM as mfm_naam,
58
mmm.Id as mmm_id,
59
mmm.NAAM as mmm_naam,
60
ffff.Id as ffff_id,
61
ffff.NAAM as ffff_naam,
62
ffmf.Id as ffmf_id,
63
ffmf.NAAM as ffmf_naam,
64
fmff.Id as fmff_id,
65
fmff.NAAM as fmff_naam,
66
fmmf.Id as fmmf_id,
67
fmmf.NAAM as fmmf_naam,
68
mmff.Id as mmff_id,
69
mmff.NAAM as mmff_naam,
70
mfff.Id as mfff_id,
71
mfff.NAAM as mfff_naam,
72
mfmf.Id as mfmf_id,
73
mfmf.NAAM as mfmf_naam,
74
mmmf.Id as mmmf_id,
75
mmmf.NAAM as mmmf_naam,
76
fffm.Id as fffm_id,
77
fffm.NAAM as fffm_naam,
78
ffmm.Id as ffmm_id,
79
ffmm.NAAM as ffmm_naam,
80
fmfm.Id as fmfm_id,
81
fmfm.NAAM as fmfm_naam,
82
fmmm.Id as fmmm_id,
83
fmmm.NAAM as fmmm_naam,
84
mmfm.Id as mmfm_id,
85
mmfm.NAAM as mmfm_naam,
86
mffm.Id as mffm_id,
87
mffm.NAAM as mffm_naam,
88
mfmm.Id as mfmm_id,
89
mfmm.NAAM as mfmm_naam,
90
mmmm.Id as mmmm_id,
91
mmmm.NAAM as mmmm_naam
92
FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d
93
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' f ON d.father = f.Id
94
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON d.mother = m.Id
95
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ff ON f.father = ff.Id
96
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fff ON ff.father = fff.Id
97
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffm ON ff.mother = ffm.Id
98
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mf ON m.father = mf.Id
99
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mff ON mf.father = mff.Id
100
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfm ON mf.mother = mfm.Id
101
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fm ON f.mother = fm.Id
102
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmf ON fm.father = fmf.Id
103
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmm ON fm.mother = fmm.Id
104
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mm ON m.mother = mm.Id
105
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmf ON mm.father = mmf.Id
106
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmm ON mm.mother = mmm.Id
107
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffff ON fff.father = ffff.Id
108
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffmf ON ffm.father = ffmf.Id
109
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmff ON fmf.father = fmff.Id
110
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmmf ON fmm.father = fmmf.Id
111
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmff ON mmf.father = mmff.Id
112
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfff ON mff.father = mfff.Id
113
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfmf ON mfm.father = mfmf.Id
114
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmmf ON mmm.father = mmmf.Id
115
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fffm ON fff.mother = fffm.Id
116
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffmm ON ffm.mother = ffmm.Id
117
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmfm ON fmf.mother = fmfm.Id
118
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmmm ON fmm.mother = fmmm.Id
119
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmfm ON mmf.mother = mmfm.Id
120
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mffm ON mff.mother = mffm.Id
121
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfmm ON mfm.mother = mfmm.Id
122
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmmm ON mmm.mother = mmmm.Id
123
WHERE d.Id=' . $pedId;
124
125
$result = $GLOBALS['xoopsDB']->query($queryString);
126
127
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
128
    //crete array to count frequency (to select colour)
129
    count_item($freq, $row['d_id']);
130
    count_item($freq, $row['f_id']);
131
    count_item($freq, $row['m_id']);
132
    count_item($freq, $row['ff_id']);
133
    count_item($freq, $row['fm_id']);
134
    count_item($freq, $row['mf_id']);
135
    count_item($freq, $row['mm_id']);
136
    count_item($freq, $row['fff_id']);
137
    count_item($freq, $row['ffm_id']);
138
    count_item($freq, $row['fmf_id']);
139
    count_item($freq, $row['fmm_id']);
140
    count_item($freq, $row['mff_id']);
141
    count_item($freq, $row['mfm_id']);
142
    count_item($freq, $row['mmf_id']);
143
    count_item($freq, $row['mmm_id']);
144
    count_item($freq, $row['ffff_id']);
145
    count_item($freq, $row['ffmf_id']);
146
    count_item($freq, $row['fmff_id']);
147
    count_item($freq, $row['fmmf_id']);
148
    count_item($freq, $row['mfff_id']);
149
    count_item($freq, $row['mfmf_id']);
150
    count_item($freq, $row['mmff_id']);
151
    count_item($freq, $row['mmmf_id']);
152
    count_item($freq, $row['fffm_id']);
153
    count_item($freq, $row['ffmm_id']);
154
    count_item($freq, $row['fmfm_id']);
155
    count_item($freq, $row['fmmm_id']);
156
    count_item($freq, $row['mffm_id']);
157
    count_item($freq, $row['mfmm_id']);
158
    count_item($freq, $row['mmfm_id']);
159
    count_item($freq, $row['mmmm_id']);
160
161
    //create array for dog (and all parents)
162
    //selected dog
163
    $d['d']['name'] = stripslashes($row['d_naam']);
164
    $d['d']['id']   = $row['d_id'];
165
    $d['d']['roft'] = $row['d_roft'];
166
    $d['d']['col']  = 'transparant';
167
    //father
168
    $d['f']['name'] = stripslashes($row['f_naam']);
169
    $d['f']['id']   = $row['f_id'];
170
    $d['f']['col']  = crcolour('f', $freq[$row['f_id']]);
171
    //mother
172
    $d['m']['name'] = stripslashes($row['m_naam']);
173
    $d['m']['id']   = $row['m_id'];
174
    $d['m']['col']  = crcolour('m', $freq[$row['m_id']]);
175
    //grandparents
176
    //father father
177
    $d['ff']['name'] = stripslashes($row['ff_naam']);
178
    $d['ff']['id']   = $row['ff_id'];
179
    $d['ff']['col']  = crcolour('f', $freq[$row['ff_id']]);
180
    //father mother
181
    $d['fm']['name'] = stripslashes($row['fm_naam']);
182
    $d['fm']['id']   = $row['fm_id'];
183
    $d['fm']['col']  = crcolour('m', $freq[$row['fm_id']]);
184
    //mother father
185
    $d['mf']['name'] = stripslashes($row['mf_naam']);
186
    $d['mf']['id']   = $row['mf_id'];
187
    $d['mf']['col']  = crcolour('f', $freq[$row['mf_id']]);
188
    //mother mother
189
    $d['mm']['name'] = stripslashes($row['mm_naam']);
190
    $d['mm']['id']   = $row['mm_id'];
191
    $d['mm']['col']  = crcolour('m', $freq[$row['mm_id']]);
192
    //great-grandparents
193
    //father father father
194
    $d['fff']['name'] = stripslashes($row['fff_naam']);
195
    $d['fff']['id']   = $row['fff_id'];
196
    $d['fff']['col']  = crcolour('f', $freq[$row['fff_id']]);
197
    //father father mother
198
    $d['ffm']['name'] = stripslashes($row['ffm_naam']);
199
    $d['ffm']['id']   = $row['ffm_id'];
200
    $d['ffm']['col']  = crcolour('m', $freq[$row['ffm_id']]);
201
    //father mother father
202
    $d['fmf']['name'] = stripslashes($row['fmf_naam']);
203
    $d['fmf']['id']   = $row['fmf_id'];
204
    $d['fmf']['col']  = crcolour('f', $freq[$row['fmf_id']]);
205
    //father mother mother
206
    $d['fmm']['name'] = stripslashes($row['fmm_naam']);
207
    $d['fmm']['id']   = $row['fmm_id'];
208
    $d['fmm']['col']  = crcolour('m', $freq[$row['fmm_id']]);
209
    //mother father father
210
    $d['mff']['name'] = stripslashes($row['mff_naam']);
211
    $d['mff']['id']   = $row['mff_id'];
212
    $d['mff']['col']  = crcolour('f', $freq[$row['mff_id']]);
213
    //mother father mother
214
    $d['mfm']['name'] = stripslashes($row['mfm_naam']);
215
    $d['mfm']['id']   = $row['mfm_id'];
216
    $d['mfm']['col']  = crcolour('m', $freq[$row['mfm_id']]);
217
    //mother mother father
218
    $d['mmf']['name'] = stripslashes($row['mmf_naam']);
219
    $d['mmf']['id']   = $row['mmf_id'];
220
    $d['mmf']['col']  = crcolour('f', $freq[$row['mmf_id']]);
221
    //mother mother mother
222
    $d['mmm']['name'] = stripslashes($row['mmm_naam']);
223
    $d['mmm']['id']   = $row['mmm_id'];
224
    $d['mmm']['col']  = crcolour('m', $freq[$row['mmm_id']]);
225
    //great-great-grandparents (fathers)
226
    //father father father
227
    $d['ffff']['name'] = stripslashes($row['ffff_naam']);
228
    $d['ffff']['id']   = $row['ffff_id'];
229
    $d['ffff']['col']  = crcolour('f', $freq[$row['ffff_id']]);
230
    //father father mother
231
    $d['ffmf']['name'] = stripslashes($row['ffmf_naam']);
232
    $d['ffmf']['id']   = $row['ffmf_id'];
233
    $d['ffmf']['col']  = crcolour('f', $freq[$row['ffmf_id']]);
234
    //father mother father
235
    $d['fmff']['name'] = stripslashes($row['fmff_naam']);
236
    $d['fmff']['id']   = $row['fmff_id'];
237
    $d['fmff']['col']  = crcolour('f', $freq[$row['fmff_id']]);
238
    //father mother mother
239
    $d['fmmf']['name'] = stripslashes($row['fmmf_naam']);
240
    $d['fmmf']['id']   = $row['fmmf_id'];
241
    $d['fmmf']['col']  = crcolour('f', $freq[$row['fmmf_id']]);
242
    //mother father father
243
    $d['mfff']['name'] = stripslashes($row['mfff_naam']);
244
    $d['mfff']['id']   = $row['mfff_id'];
245
    $d['mfff']['col']  = crcolour('f', $freq[$row['mfff_id']]);
246
    //mother father mother
247
    $d['mfmf']['name'] = stripslashes($row['mfmf_naam']);
248
    $d['mfmf']['id']   = $row['mfmf_id'];
249
    $d['mfmf']['col']  = crcolour('f', $freq[$row['mfmf_id']]);
250
    //mother mother father
251
    $d['mmff']['name'] = stripslashes($row['mmff_naam']);
252
    $d['mmff']['id']   = $row['mmff_id'];
253
    $d['mmff']['col']  = crcolour('f', $freq[$row['mmff_id']]);
254
    //mother mother mother
255
    $d['mmmf']['name'] = stripslashes($row['mmmf_naam']);
256
    $d['mmmf']['id']   = $row['mmmf_id'];
257
    $d['mmmf']['col']  = crcolour('f', $freq[$row['mmmf_id']]);
258
    //great-great-grandparents (mothers)
259
    //father father father
260
    $d['fffm']['name'] = stripslashes($row['fffm_naam']);
261
    $d['fffm']['id']   = $row['fffm_id'];
262
    $d['fffm']['col']  = crcolour('m', $freq[$row['fffm_id']]);
263
    //father father mother
264
    $d['ffmm']['name'] = stripslashes($row['ffmm_naam']);
265
    $d['ffmm']['id']   = $row['ffmm_id'];
266
    $d['ffmm']['col']  = crcolour('m', $freq[$row['ffmm_id']]);
267
    //father mother father
268
    $d['fmfm']['name'] = stripslashes($row['fmfm_naam']);
269
    $d['fmfm']['id']   = $row['fmfm_id'];
270
    $d['fmfm']['col']  = crcolour('m', $freq[$row['fmfm_id']]);
271
    //father mother mother
272
    $d['fmmm']['name'] = stripslashes($row['fmmm_naam']);
273
    $d['fmmm']['id']   = $row['fmmm_id'];
274
    $d['fmmm']['col']  = crcolour('m', $freq[$row['fmmm_id']]);
275
    //mother father father
276
    $d['mffm']['name'] = stripslashes($row['mffm_naam']);
277
    $d['mffm']['id']   = $row['mffm_id'];
278
    $d['mffm']['col']  = crcolour('m', $freq[$row['mffm_id']]);
279
    //mother father mother
280
    $d['mfmm']['name'] = stripslashes($row['mfmm_naam']);
281
    $d['mfmm']['id']   = $row['mfmm_id'];
282
    $d['mfmm']['col']  = crcolour('m', $freq[$row['mfmm_id']]);
283
    //mother mother father
284
    $d['mmfm']['name'] = stripslashes($row['mmfm_naam']);
285
    $d['mmfm']['id']   = $row['mmfm_id'];
286
    $d['mmfm']['col']  = crcolour('m', $freq[$row['mmfm_id']]);
287
    //mother mother mother
288
    $d['mmmm']['name'] = stripslashes($row['mmmm_naam']);
289
    $d['mmmm']['id']   = $row['mmmm_id'];
290
    $d['mmmm']['col']  = crcolour('m', $freq[$row['mmmm_id']]);
291
}
292
293
//add data to smarty template
294
$GLOBALS['xoopsTpl']->assign('xoops_pagetitle', $d['d']['name'] . ' -- mega pedigree');
295
//assign dog(s)
296
$GLOBALS['xoopsTpl']->assign('d', $d);
297
$GLOBALS['xoopsTpl']->assign('male', "<img src=\"assets/images/male.gif\" alt=\"" . ucfirst(_MA_PEDIGREE_MALE) . "\">");
298
$GLOBALS['xoopsTpl']->assign('female', "<img src=\"assets/images/female.gif\"> alt=\"" . ucfirst(_MA_PEDIGREE_FEMALE) . "\"");
299
//assign extra display options
300
$GLOBALS['xoopsTpl']->assign('unknown', _MA_PEDIGREE_UNKNOWN);
301
$GLOBALS['xoopsTpl']->assign('f2', strtr(_MA_PEDIGREE_MPED_F2, array('[animalType]' => $pedigree->getConfig('animalType'))));
302
$GLOBALS['xoopsTpl']->assign('f3', strtr(_MA_PEDIGREE_MPED_F3, array('[animalType]' => $pedigree->getConfig('animalType'))));
303
$GLOBALS['xoopsTpl']->assign('f4', strtr(_MA_PEDIGREE_MPED_F4, array('[animalType]' => $pedigree->getConfig('animalType'))));
304
$GLOBALS['xoopsTpl']->assign('m2', strtr(_MA_PEDIGREE_MPED_M2, array('[animalType]' => $pedigree->getConfig('animalType'))));
305
$GLOBALS['xoopsTpl']->assign('m3', strtr(_MA_PEDIGREE_MPED_M3, array('[animalType]' => $pedigree->getConfig('animalType'))));
306
$GLOBALS['xoopsTpl']->assign('m4', strtr(_MA_PEDIGREE_MPED_M4, array('[animalType]' => $pedigree->getConfig('animalType'))));
307
308
//comments and footer
309
include $GLOBALS['xoops']->path('/footer.php');
310
311
/**
312
 * @param $sex
313
 * @param $item
314
 *
315
 * @return string
316
 * @todo move this to ./include directory
317
 */
318
function crcolour($sex, $item)
319
{
320
    if ($item == '1') {
321
        $col = 'transparant';
322
    } elseif ($item == '2' && $sex === 'f') {
323
        $col = '#C8C8FF';
324
    } elseif ($item == 3 && $sex === 'f') {
325
        $col = '#6464FF';
326
    } elseif ($item == '4' && $sex === 'f') {
327
        $col = '#0000FF';
328
    } elseif ($item == '2' && $sex === 'm') {
329
        $col = '#FFC8C8';
330
    } elseif ($item == '3' && $sex === 'm') {
331
        $col = '#FF6464';
332
    } elseif ($item == '4' && $sex === 'm') {
333
        $col = '#FF0000';
334
    } else {
335
        $col = 'transparant';
336
    }
337
338
    return $col;
339
}
340
341
/**
342
 * @param     $freq
343
 * @param     $item
344
 * @param int $inc
345
 *
346
 * @return bool
347
 */
348
function count_item(&$freq, $item, $inc = 1)
349
{
350
    if (!is_array($freq)) {
351
        $freq = array();
352
    }
353
    $freq[$item] = (isset($freq[$item]) ? ($freq[$item] += $inc) : $inc);
354
355
    return true;
356
}
357