We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 21 |
| Paths | 4374 |
| Total Lines | 124 |
| Code Lines | 91 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 223 | protected function showSingleCollection($id) { |
||
| 224 | $additionalWhere = ''; |
||
| 225 | // Should user-defined collections be shown? |
||
| 226 | if (empty($this->conf['show_userdefined'])) { |
||
| 227 | $additionalWhere = ' AND tx_dlf_collections.fe_cruser_id=0'; |
||
| 228 | } elseif ($this->conf['show_userdefined'] > 0) { |
||
| 229 | $additionalWhere = ' AND NOT tx_dlf_collections.fe_cruser_id=0'; |
||
| 230 | } |
||
| 231 | // Get collection information from DB |
||
| 232 | $collection = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 233 | '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', |
||
| 234 | 'tx_dlf_collections', |
||
| 235 | 'tx_dlf_collections.pid='.intval($this->conf['pages']) |
||
| 236 | .' AND tx_dlf_collections.uid='.intval($id) |
||
| 237 | .$additionalWhere |
||
| 238 | .Helper::whereClause('tx_dlf_collections'), |
||
| 239 | '', |
||
| 240 | '', |
||
| 241 | '1' |
||
| 242 | ); |
||
| 243 | // Fetch corresponding document UIDs from Solr. |
||
| 244 | $solr_query = ''; |
||
| 245 | $collectionData = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($collection); |
||
| 246 | if ($collectionData['index_query'] != '') { |
||
| 247 | $solr_query .= '('.$collectionData['index_query'].')'; |
||
| 248 | } else { |
||
| 249 | $solr_query .= 'collection:("'.$collectionData['index_name'].'")'; |
||
| 250 | } |
||
| 251 | $solr = Solr::getInstance($this->conf['solrcore']); |
||
| 252 | if (!$solr->ready) { |
||
| 253 | Helper::devLog('Apache Solr not available', DEVLOG_SEVERITY_ERROR); |
||
| 254 | return; |
||
| 255 | } |
||
| 256 | $params['fields'] = 'uid'; |
||
|
1 ignored issue
–
show
|
|||
| 257 | $params['sort'] = ['uid' => 'asc']; |
||
| 258 | $solrResult = $solr->search_raw($solr_query, $params); |
||
| 259 | // Initialize array |
||
| 260 | $documentSet = []; |
||
| 261 | foreach ($solrResult as $doc) { |
||
| 262 | $documentSet[] = $doc->uid; |
||
| 263 | } |
||
| 264 | $documentSet = array_unique($documentSet); |
||
| 265 | // Fetch document info for UIDs in $documentSet from DB |
||
| 266 | $documents = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 267 | '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', |
||
| 268 | 'tx_dlf_documents', |
||
| 269 | 'tx_dlf_documents.pid='.intval($this->conf['pages']) |
||
| 270 | .' AND tx_dlf_documents.uid IN ('.implode(',', $documentSet).')' |
||
| 271 | .Helper::whereClause('tx_dlf_documents'), |
||
| 272 | '', |
||
| 273 | '', |
||
| 274 | '' |
||
| 275 | ); |
||
| 276 | $toplevel = []; |
||
| 277 | $subparts = []; |
||
| 278 | $listMetadata = []; |
||
| 279 | // Process results. |
||
| 280 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($documents)) { |
||
| 281 | if (empty($l10nOverlay)) { |
||
| 282 | $l10nOverlay = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dlf_collections', $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
| 283 | } |
||
| 284 | if (empty($listMetadata)) { |
||
| 285 | $listMetadata = [ |
||
| 286 | 'label' => !empty($l10nOverlay['label']) ? htmlspecialchars($l10nOverlay['label']) : htmlspecialchars($collectionData['collLabel']), |
||
| 287 | 'description' => !empty($l10nOverlay['description']) ? $this->pi_RTEcssText($l10nOverlay['description']) : $this->pi_RTEcssText($collectionData['collDesc']), |
||
| 288 | 'thumbnail' => htmlspecialchars($collectionData['collThumb']), |
||
| 289 | 'options' => [ |
||
| 290 | 'source' => 'collection', |
||
| 291 | 'select' => $id, |
||
| 292 | 'userid' => $collectionData['userid'], |
||
| 293 | 'params' => ['filterquery' => [['query' => 'collection_faceting:("'.$collectionData['index_name'].'")']]], |
||
| 294 | 'core' => '', |
||
| 295 | 'pid' => $this->conf['pages'], |
||
| 296 | 'order' => 'title', |
||
| 297 | 'order.asc' => TRUE |
||
| 298 | ] |
||
| 299 | ]; |
||
| 300 | } |
||
| 301 | // Split toplevel documents from volumes. |
||
| 302 | if ($resArray['partof'] == 0) { |
||
| 303 | // Prepare document's metadata for sorting. |
||
| 304 | $sorting = unserialize($resArray['metadata_sorting']); |
||
| 305 | if (!empty($sorting['type']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['type'])) { |
||
| 306 | $sorting['type'] = Helper::getIndexNameFromUid($sorting['type'], 'tx_dlf_structures', $this->conf['pages']); |
||
| 307 | } |
||
| 308 | if (!empty($sorting['owner']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['owner'])) { |
||
| 309 | $sorting['owner'] = Helper::getIndexNameFromUid($sorting['owner'], 'tx_dlf_libraries', $this->conf['pages']); |
||
| 310 | } |
||
| 311 | if (!empty($sorting['collection']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sorting['collection'])) { |
||
| 312 | $sorting['collection'] = Helper::getIndexNameFromUid($sorting['collection'], 'tx_dlf_collections', $this->conf['pages']); |
||
| 313 | } |
||
| 314 | $toplevel[$resArray['uid']] = [ |
||
| 315 | 'u' => $resArray['uid'], |
||
| 316 | 'h' => '', |
||
| 317 | 's' => $sorting, |
||
| 318 | 'p' => [] |
||
| 319 | ]; |
||
| 320 | } else { |
||
| 321 | $subparts[$resArray['partof']][$resArray['volume_sorting']] = $resArray['uid']; |
||
| 322 | } |
||
| 323 | } |
||
| 324 | // Add volumes to the corresponding toplevel documents. |
||
| 325 | foreach ($subparts as $partof => $parts) { |
||
| 326 | if (!empty($toplevel[$partof])) { |
||
| 327 | ksort($parts); |
||
| 328 | foreach ($parts as $part) { |
||
| 329 | $toplevel[$partof]['p'][] = ['u' => $part]; |
||
| 330 | } |
||
| 331 | } |
||
| 332 | } |
||
| 333 | // Save list of documents. |
||
| 334 | $list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(DocumentList::class); |
||
| 335 | $list->reset(); |
||
| 336 | $list->add(array_values($toplevel)); |
||
| 337 | $listMetadata['options']['numberOfToplevelHits'] = count($list); |
||
| 338 | $list->metadata = $listMetadata; |
||
| 339 | $list->save(); |
||
| 340 | // Clean output buffer. |
||
| 341 | \TYPO3\CMS\Core\Utility\GeneralUtility::cleanOutputBuffers(); |
||
| 342 | // Send headers. |
||
| 343 | header('Location: '.\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($this->cObj->typoLink_URL(['parameter' => $this->conf['targetPid']]))); |
||
| 344 | // Flush output buffer and end script processing. |
||
| 345 | ob_end_flush(); |
||
| 346 | exit; |
||
| 347 | } |
||
| 349 |