| Conditions | 22 |
| Paths | 12240 |
| Total Lines | 237 |
| Code Lines | 155 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 253 | |||
| 254 | $criteria = $helper->getHandler('Tree')->getActiveCriteria($roft); |
||
| 255 | //$criteria->setGroupby('UPPER(LEFT(' . $name . ',1))'); |
||
| 256 | |||
| 257 | $motherArray['letters'] = Pedigree\Utility::lettersChoice($helper, 'Tree', $criteria, $name, $link); |
||
| 258 | //$catarray['toolbar'] = pedigree_toolbar(); |
||
| 259 | $GLOBALS['xoopsTpl']->assign('motherArray', $motherArray); |
||
| 260 | break; |
||
| 261 | |||
| 262 | case 'check': |
||
| 263 | |||
| 264 | $selsire = Request::getInt('selsire', 0, 'GET'); |
||
| 265 | $seldam = Request::getInt('seldam', 0, 'GET'); |
||
| 266 | |||
| 267 | $treeHandler = $helper->getHandler('Tree'); |
||
| 268 | |||
| 269 | $GLOBALS['xoopsTpl']->assign([ |
||
| 270 | 'virtualtitle' => _MA_PEDIGREE_VIRUTALTIT, |
||
| 271 | 'virtualstory' => strtr(_MA_PEDIGREE_VIRUTALSTO, [ |
||
| 272 | '[mother]' => $helper->getConfig('mother'), |
||
| 273 | '[father]' => $helper->getConfig('father'), |
||
| 274 | '[children]' => $helper->getConfig('children') |
||
| 275 | ]), |
||
| 276 | 'virtualsiretitle' => strtr(_MA_PEDIGREE_VIRTUALSTIT, ['[father]' => $helper->getConfig('father')]), |
||
| 277 | 'virtualdamtitle' => strtr(_MA_PEDIGREE_VIRTUALDTIT, ['[mother]' => $helper->getConfig('mother')]), |
||
| 278 | 'form' => "<a href=\"" . $helper->url("coi.php?s={$selsire}&d={$seldam}&dogid=&detail=1") . "\">" . _MA_PEDIGREE_VIRTUALBUT . "</a>" |
||
| 279 | ]); |
||
| 280 | //Find Father |
||
| 281 | //@todo - this looks wrong, shouldn't this be looking at 'father' field, not 'id' |
||
| 282 | $sireArray = $treeHandler->get($selsire); |
||
| 283 | $vsire = $sireArray instanceof Pedigree\Tree ? $sireArray->getVar('naam') : ''; |
||
| 284 | /* |
||
| 285 | $query = 'SELECT id, naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE id=' . $selsire; |
||
| 286 | $result = $GLOBALS['xoopsDB']->query($query); |
||
| 287 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 288 | $vsire = stripslashes($row['naam']); |
||
| 289 | } |
||
| 290 | */ |
||
| 291 | $GLOBALS['xoopsTpl']->assign('virtualsire', $vsire); |
||
| 292 | |||
| 293 | //Find Mother |
||
| 294 | //@todo - this looks wrong, shouldn't this be looking at 'mother' field, not 'id' |
||
| 295 | $damArray = $treeHandler->get($seldam); |
||
| 296 | $vdam = $damArray instanceof Pedigree\Tree ? $damArray->getVar('naam') : ''; |
||
| 297 | /* |
||
| 298 | $query = 'SELECT id, naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE id=' . $seldam; |
||
| 299 | $result = $GLOBALS['xoopsDB']->query($query); |
||
| 300 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 301 | $vdam = stripslashes($row['naam']); |
||
| 302 | } |
||
| 303 | */ |
||
| 304 | $GLOBALS['xoopsTpl']->assign('virtualdam', $vdam); |
||
| 305 | break; |
||
| 306 | |||
| 307 | default: |
||
| 308 | $st = Request::getInt('st', 0, 'GET'); |
||
| 309 | $l = Request::getString('l', 'a', 'GET'); |
||
| 310 | |||
| 311 | $GLOBALS['xoopsTpl']->assign('sire', '1'); |
||
| 312 | //create list of males dog to select from |
||
| 313 | $perPage = $helper->getConfig('perpage'); |
||
| 314 | $perPage = (int)$perPage > 0 ? (int)$perPage : 10; // make sure $perPage is 'valid' |
||
| 315 | //count total number of dogs |
||
| 316 | $numDog = 'SELECT COUNT(d.id) FROM ' |
||
| 317 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 318 | . ' d LEFT JOIN ' |
||
| 319 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 320 | . ' m ON m.id = d.mother LEFT JOIN ' |
||
| 321 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 322 | //. " f ON f.id = d.father WHERE d.roft = '0' and d.mother != '0' and d.father != '0' and m.mother != '0' and m.father != '0' and f.mother != '0' and f.father != '0' and d.naam LIKE '" . $l . "%'"; |
||
| 323 | . " f ON f.id = d.father WHERE d.roft = '0' AND d.mother != '0' AND d.father != '0' AND m.mother != '0' AND m.father != '0' AND f.mother != '0' AND f.father != '0' AND d.naam LIKE '" |
||
| 324 | . $GLOBALS['xoopsDB']->escape($l) |
||
| 325 | . "%'"; |
||
| 326 | $numRes = $GLOBALS['xoopsDB']->query($numDog); |
||
| 327 | //total number of dogs the query will find |
||
| 328 | list($numResults) = $GLOBALS['xoopsDB']->fetchRow($numRes); |
||
| 329 | //total number of pages |
||
| 330 | $numPages = floor($numResults / $perPage) + 1; |
||
| 331 | if (($numPages * $perPage) == ($numResults + $perPage)) { |
||
| 332 | --$numPages; |
||
| 333 | } |
||
| 334 | //find current page |
||
| 335 | $currentPage = floor($st / $perPage) + 1; |
||
| 336 | //create alphabet |
||
| 337 | //@todo this needs to be refactored for non-English languages |
||
| 338 | $pages = ''; |
||
| 339 | for ($i = 65; $i <= 90; ++$i) { |
||
| 340 | if ($l == chr($i)) { |
||
| 341 | $pages .= "<span style=\"font-weight: bold;\"><a href=\"" . $helper->url("virtual.php?r=1&st=0&l=" . chr($i)) . "\">" . chr($i) . "</a></span> "; |
||
| 342 | } else { |
||
| 343 | $pages .= "<a href=\"" . $helper->url("virtual.php?r=1&st=0&l=" . chr($i)) . "\">" . chr($i) . "</a> "; |
||
| 344 | } |
||
| 345 | } |
||
| 346 | $pages .= '- '; |
||
| 347 | $pages .= "<a href=\"" . $helper->url("virtual.php?r=1&st=0&l=Ã…") . "\">Ã…</a> "; |
||
| 348 | $pages .= "<a href=\"" . $helper->url("virtual.php?r=1&st=0&l=Ö") . "\">Ö</a> "; |
||
| 349 | $pages .= "<br>\n"; |
||
| 350 | //create previous button |
||
| 351 | if (($numPages > 1) && ($currentPage > 1)) { |
||
| 352 | $pages .= "<a href=\"" . $helper->url("virtual.php?r=1&&l={$l}&st=" . ($st - $perPage)) . "\">" . _MA_PEDIGREE_PREVIOUS . "</a>  "; |
||
| 353 | } |
||
| 354 | //create numbers |
||
| 355 | $xLimit = $numPages + 1; |
||
| 356 | for ($x = 1; $x < $xLimit; ++$x) { |
||
| 357 | //create line break after 20 number |
||
| 358 | if (0 == ($x % 20)) { |
||
| 359 | $pages .= '<br>'; |
||
| 360 | } |
||
| 361 | if ($x != $currentPage) { |
||
| 362 | $pages .= "<a href=\"" . $helper->url("virtual.php?r=1&l={$l}&st=" . ($perPage * ($x - 1))) . "\">{$x}</a> "; |
||
| 363 | } else { |
||
| 364 | $pages .= $x . '  '; |
||
| 365 | } |
||
| 366 | } |
||
| 367 | //create next button |
||
| 368 | if ($numPages > 1) { |
||
| 369 | if ($currentPage < $numPages) { |
||
| 370 | $pages .= "<a href=\"" . $helper->url("virtual.php?r=1&l={$l}&st=" . ($st + $perPage)) . "\">" . _MA_PEDIGREE_NEXT . "</a>  "; |
||
| 371 | } |
||
| 372 | } |
||
| 373 | |||
| 374 | //query |
||
| 375 | $queryString = 'SELECT d.*, d.id AS d_id, d.naam AS d_naam FROM ' |
||
| 376 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 377 | . ' d LEFT JOIN ' |
||
| 378 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 379 | . ' m ON m.id = d.mother LEFT JOIN ' |
||
| 380 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
| 381 | . " f ON f.id = d.father WHERE d.roft = '0' AND d.mother != '0' AND d.father != '0' AND m.mother != '0' AND m.father != '0' AND f.mother != '0' AND f.father != '0' AND d.naam LIKE '" |
||
| 382 | . $l |
||
| 383 | . "%' ORDER BY d.naam LIMIT " |
||
| 384 | . $st |
||
| 385 | . ', ' |
||
| 386 | . $perPage; |
||
| 387 | $result = $GLOBALS['xoopsDB']->query($queryString); |
||
| 388 | $animal = new Pedigree\Animal(); |
||
| 389 | //test to find out how many user fields there are... |
||
| 390 | $fields = $animal->getNumOfFields(); |
||
| 391 | $animalConfig = $animal->getConfig(); |
||
| 392 | $numOfColumns = 1; |
||
| 393 | $columns[] = ['columnname' => 'Name']; |
||
| 394 | foreach ($fields as $i => $iValue) { |
||
| 395 | $userField = new Pedigree\Field($fields[$i], $animalConfig); |
||
| 396 | $fieldType = $userField->getSetting('FieldType'); |
||
| 397 | $fieldObject = new $fieldType($userField, $animal); |
||
| 398 | //create empty string |
||
| 399 | $lookupValues = ''; |
||
| 400 | if ($userField->isActive() && $userField->inList()) { |
||
| 401 | if ($userField->hasLookup()) { |
||
| 402 | $lookupValues = $userField->lookupField($fields[$i]); |
||
| 403 | //debug information |
||
| 404 | //print_r($lookupValues); |
||
| 405 | } |
||
| 406 | $columns[] = [ |
||
| 407 | 'columnname' => $fieldObject->fieldname, |
||
| 408 | 'columnnumber' => $userField->getId(), |
||
| 409 | 'lookupval' => $lookupValues, |
||
| 410 | ]; |
||
| 411 | ++$numOfColumns; |
||
| 412 | unset($lookupValues); |
||
| 413 | } |
||
| 414 | } |
||
| 415 | |||
| 416 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 417 | //create picture information |
||
| 418 | if ('' != $row['foto']) { |
||
| 419 | $camera = ' <img src="' . PEDIGREE_UPLOAD_URL . '/images/dog-icon25.png">'; |
||
| 420 | } else { |
||
| 421 | $camera = ''; |
||
| 422 | } |
||
| 423 | $name = stripslashes($row['d_naam']) . $camera; |
||
| 424 | //empty array |
||
| 425 | unset($columnvalue); |
||
| 426 | //fill array |
||
| 427 | for ($i = 1; $i < $numOfColumns; ++$i) { |
||
| 428 | $x = $columns[$i]['columnnumber']; |
||
| 429 | //echo $x."columnnumber"; |
||
| 430 | if (is_array($columns[$i]['lookupval'])) { |
||
| 431 | foreach ($columns[$i]['lookupval'] as $key => $keyValue) { |
||
| 432 | if ($keyValue['id'] == $row['user' . $x]) { |
||
| 433 | //echo "key:".$row['user5']."<br>"; |
||
| 434 | $value = $keyValue['value']; |
||
| 435 | } |
||
| 436 | } |
||
| 437 | //debug information |
||
| 438 | ///echo $columns[$i]['columnname']."is an array !"; |
||
| 439 | } //format value - cant use object because of query count |
||
| 440 | elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { //@todo need to make this so allows for https:// too |
||
| 441 | $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>'; |
||
| 442 | } else { |
||
| 443 | $value = $row['user' . $x]; |
||
| 444 | } |
||
| 445 | $columnvalue[] = ['value' => $value]; |
||
| 446 | unset($value); |
||
| 447 | } |
||
| 448 | $dogs[] = [ |
||
| 449 | 'id' => $row['d_id'], |
||
| 450 | 'name' => $name, |
||
| 451 | 'gender' => '<img src="assets/images/male.gif">', |
||
| 452 | 'link' => "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $row['d_id']) . "\">{$name}</a>", |
||
| 453 | 'colour' => '', |
||
| 454 | 'number' => '', |
||
| 455 | 'usercolumns' => isset($columnvalue) ? $columnvalue : 0, |
||
| 456 | ]; |
||
| 457 | } |
||
| 458 | |||
| 459 | //add data to smarty template |
||
| 460 | //assign dog |
||
| 461 | if (isset($dogs)) { |
||
| 462 | $GLOBALS['xoopsTpl']->assign('dogs', $dogs); |
||
| 463 | } |
||
| 464 | $GLOBALS['xoopsTpl']->assign([ |
||
| 465 | 'columns' => $columns, |
||
| 466 | 'numofcolumns' => $numOfColumns, |
||
| 467 | 'tsarray' => Pedigree\Utility::sortTable($numOfColumns), |
||
| 468 | 'nummatch' => strtr(_MA_PEDIGREE_ADD_SELSIRE, ['[father]' => $helper->getConfig('father')]), |
||
| 469 | 'pages' => $pages, |
||
| 470 | 'virtualtitle' => strtr(_MA_PEDIGREE_VIRUTALTIT, ['[mother]' => $helper->getConfig('mother')]), |
||
| 471 | 'virtualstory' => strtr(_MA_PEDIGREE_VIRUTALSTO, [ |
||
| 472 | '[mother]' => $helper->getConfig('mother'), |
||
| 473 | '[father]' => $helper->getConfig('father'), |
||
| 474 | '[children]' => $helper->getConfig('children')]), |
||
| 475 | 'nextaction' => '<span style="font-weight: bold;">' . strtr(_MA_PEDIGREE_VIRT_SIRE, ['[father]' => $helper->getConfig('father')]) . '</span>' |
||
| 476 | ]); |
||
| 477 | |||
| 478 | //mb =========== FATHER LETTERS ============================= |
||
| 479 | $roft = 0; |
||
| 480 | $name = 'naam'; |
||
| 481 | $link = "virtual.php?r=1&st=0&l="; |
||
| 482 | $link2 = ''; |
||
| 483 | |||
| 484 | $criteria = $helper->getHandler('Tree')->getActiveCriteria($roft); |
||
| 485 | //$criteria = $helper->getHandler('Tree')->getActiveCriteria($roft); |
||
| 486 | //$criteria->setGroupby('UPPER(LEFT(' . $name . ',1))'); |
||
| 487 | |||
| 488 | $fatherArray['letters'] = Pedigree\Utility::lettersChoice($helper, 'Tree', $criteria, $name, $link, $link2); |
||
| 489 | //$catarray['toolbar'] = pedigree_toolbar(); |
||
| 490 | $GLOBALS['xoopsTpl']->assign('fatherArray', $fatherArray); |
||
| 496 |