We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 22 |
| Paths | 4380 |
| Total Lines | 194 |
| Code Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 14 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 337 | protected function showSingleCollection($id) { |
||
| 338 | |||
| 339 | $additionalWhere = ''; |
||
| 340 | |||
| 341 | // Should user-defined collections be shown? |
||
| 342 | if (empty($this->conf['show_userdefined'])) { |
||
| 343 | |||
| 344 | $additionalWhere = ' AND tx_dlf_collections.fe_cruser_id=0'; |
||
| 345 | |||
| 346 | } elseif ($this->conf['show_userdefined'] > 0) { |
||
| 347 | |||
| 348 | $additionalWhere = ' AND NOT tx_dlf_collections.fe_cruser_id=0'; |
||
| 349 | |||
| 350 | } |
||
| 351 | |||
| 352 | // Get collection information from DB |
||
| 353 | $collection = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 354 | 'tx_dlf_collections.index_name AS index_name, tx_dlf_collections.index_search as index_query, tx_dlf_collections.label AS collLabel, tx_dlf_collections.description AS collDesc, tx_dlf_collections.thumbnail AS collThumb, tx_dlf_collections.fe_cruser_id', |
||
| 355 | 'tx_dlf_collections', |
||
| 356 | 'tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_collections.uid='.intval($id).$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_collections'), |
||
| 357 | '', |
||
| 358 | '', |
||
| 359 | '1' |
||
| 360 | ); |
||
| 361 | |||
| 362 | // Fetch corresponding document UIDs from Solr. |
||
| 363 | $solr_query = ''; |
||
| 364 | |||
| 365 | $collectionData = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($collection); |
||
| 366 | |||
| 367 | if ($collectionData['index_query'] != '') { |
||
| 368 | |||
| 369 | $solr_query .= '('.$collectionData['index_query'].')'; |
||
| 370 | |||
| 371 | } else { |
||
| 372 | |||
| 373 | $solr_query .= 'collection:("'.$collectionData['index_name'].'")'; |
||
| 374 | |||
| 375 | } |
||
| 376 | |||
| 377 | $solr = tx_dlf_solr::getInstance($this->conf['solrcore']); |
||
| 378 | |||
| 379 | if (!$solr->ready) { |
||
| 380 | |||
| 381 | if (TYPO3_DLOG) { |
||
| 382 | |||
| 383 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_collection->showSingleCollection('.intval($id).')] Apache Solr not available', $this->extKey, SYSLOG_SEVERITY_ERROR); |
||
| 384 | |||
| 385 | } |
||
| 386 | |||
| 387 | return; |
||
| 388 | |||
| 389 | } |
||
| 390 | |||
| 391 | $params['fields'] = 'uid'; |
||
|
1 ignored issue
–
show
|
|||
| 392 | $params['sort'] = array ('uid' => 'asc'); |
||
| 393 | |||
| 394 | $solrResult = $solr->search_raw($solr_query, $params); |
||
| 395 | |||
| 396 | // initialize array |
||
| 397 | $documentSet = []; |
||
| 398 | |||
| 399 | foreach ($solrResult as $doc) { |
||
| 400 | |||
| 401 | $documentSet[] = $doc->uid; |
||
| 402 | |||
| 403 | } |
||
| 404 | |||
| 405 | $documentSet = array_unique($documentSet); |
||
| 406 | |||
| 407 | //Fetch document info for UIDs in $documentSet from DB |
||
| 408 | $documents = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 409 | 'tx_dlf_documents.uid AS uid, tx_dlf_documents.metadata_sorting AS metadata_sorting, tx_dlf_documents.volume_sorting AS volume_sorting, tx_dlf_documents.partof AS partof', |
||
| 410 | 'tx_dlf_documents', |
||
| 411 | 'tx_dlf_documents.pid='.intval($this->conf['pages']).' AND tx_dlf_documents.uid IN ('.implode(',', $documentSet).')'.tx_dlf_helper::whereClause('tx_dlf_documents'), |
||
| 412 | '', |
||
| 413 | '', |
||
| 414 | '' |
||
| 415 | ); |
||
| 416 | |||
| 417 | $toplevel = array (); |
||
| 418 | |||
| 419 | $subparts = array (); |
||
| 420 | |||
| 421 | $listMetadata = array (); |
||
| 422 | |||
| 423 | // Process results. |
||
| 424 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($documents)) { |
||
| 425 | |||
| 426 | if (empty($l10nOverlay)) { |
||
| 427 | |||
| 428 | $l10nOverlay = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dlf_collections', $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
| 429 | |||
| 430 | } |
||
| 431 | |||
| 432 | if (empty($listMetadata)) { |
||
| 433 | |||
| 434 | $listMetadata = array ( |
||
| 435 | 'label' => !empty($l10nOverlay['label']) ? htmlspecialchars($l10nOverlay['label']) : htmlspecialchars($collectionData['collLabel']), |
||
| 436 | 'description' => !empty($l10nOverlay['description']) ? $this->pi_RTEcssText($l10nOverlay['description']) : $this->pi_RTEcssText($collectionData['collDesc']), |
||
| 437 | 'thumbnail' => htmlspecialchars($collectionData['collThumb']), |
||
| 438 | 'options' => array ( |
||
| 439 | 'source' => 'collection', |
||
| 440 | 'select' => $id, |
||
| 441 | 'userid' => $collectionData['userid'], |
||
| 442 | 'params' => array ('filterquery' => array (array ('query' => 'collection_faceting:("'.$collectionData['index_name'].'")'))), |
||
| 443 | 'core' => '', |
||
| 444 | 'pid' => $this->conf['pages'], |
||
| 445 | 'order' => 'title', |
||
| 446 | 'order.asc' => TRUE |
||
| 447 | ) |
||
| 448 | ); |
||
| 449 | |||
| 450 | } |
||
| 451 | |||
| 452 | // Split toplevel documents from volumes. |
||
| 453 | if ($resArray['partof'] == 0) { |
||
| 454 | |||
| 455 | // Prepare document's metadata for sorting. |
||
| 456 | $sorting = unserialize($resArray['metadata_sorting']); |
||
| 457 | |||
| 458 | if (!empty($sorting['type']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['type'])) { |
||
| 459 | |||
| 460 | $sorting['type'] = tx_dlf_helper::getIndexName($sorting['type'], 'tx_dlf_structures', $this->conf['pages']); |
||
| 461 | |||
| 462 | } |
||
| 463 | |||
| 464 | if (!empty($sorting['owner']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['owner'])) { |
||
| 465 | |||
| 466 | $sorting['owner'] = tx_dlf_helper::getIndexName($sorting['owner'], 'tx_dlf_libraries', $this->conf['pages']); |
||
| 467 | |||
| 468 | } |
||
| 469 | |||
| 470 | if (!empty($sorting['collection']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['collection'])) { |
||
| 471 | |||
| 472 | $sorting['collection'] = tx_dlf_helper::getIndexName($sorting['collection'], 'tx_dlf_collections', $this->conf['pages']); |
||
| 473 | |||
| 474 | } |
||
| 475 | |||
| 476 | $toplevel[$resArray['uid']] = array ( |
||
| 477 | 'u' => $resArray['uid'], |
||
| 478 | 'h' => '', |
||
| 479 | 's' => $sorting, |
||
| 480 | 'p' => array () |
||
| 481 | ); |
||
| 482 | |||
| 483 | } else { |
||
| 484 | |||
| 485 | $subparts[$resArray['partof']][$resArray['volume_sorting']] = $resArray['uid']; |
||
| 486 | |||
| 487 | } |
||
| 488 | |||
| 489 | } |
||
| 490 | |||
| 491 | // Add volumes to the corresponding toplevel documents. |
||
| 492 | foreach ($subparts as $partof => $parts) { |
||
| 493 | |||
| 494 | if (!empty($toplevel[$partof])) { |
||
| 495 | |||
| 496 | ksort($parts); |
||
| 497 | |||
| 498 | foreach ($parts as $part) { |
||
| 499 | |||
| 500 | $toplevel[$partof]['p'][] = array ('u' => $part); |
||
| 501 | |||
| 502 | } |
||
| 503 | |||
| 504 | } |
||
| 505 | |||
| 506 | } |
||
| 507 | |||
| 508 | // Save list of documents. |
||
| 509 | $list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_dlf_list'); |
||
| 510 | |||
| 511 | $list->reset(); |
||
| 512 | |||
| 513 | $list->add(array_values($toplevel)); |
||
| 514 | |||
| 515 | $listMetadata['options']['numberOfToplevelHits'] = count($list); |
||
| 516 | |||
| 517 | $list->metadata = $listMetadata; |
||
| 518 | |||
| 519 | $list->save(); |
||
| 520 | |||
| 521 | // Clean output buffer. |
||
| 522 | \TYPO3\CMS\Core\Utility\GeneralUtility::cleanOutputBuffers(); |
||
| 523 | |||
| 524 | // Send headers. |
||
| 525 | header('Location: '.\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($this->cObj->typoLink_URL(array ('parameter' => $this->conf['targetPid'])))); |
||
| 526 | |||
| 527 | // Flush output buffer and end script processing. |
||
| 528 | ob_end_flush(); |
||
| 529 | |||
| 530 | exit; |
||
| 531 | |||
| 535 |