We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 28 |
| Paths | > 20000 |
| Total Lines | 164 |
| Code Lines | 112 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 78 | protected function showCollectionList() { |
||
| 79 | /** @var QueryBuilder $queryBuilder */ |
||
| 80 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 81 | ->getQueryBuilderForTable('tx_dlf_collections'); |
||
| 82 | |||
| 83 | $selectedCollections = $queryBuilder->expr()->neq('tx_dlf_collections.uid', 0); |
||
| 84 | $orderBy = 'tx_dlf_collections.label'; |
||
| 85 | $showUserDefinedColls = ''; |
||
| 86 | // Handle collections set by configuration. |
||
| 87 | if ($this->conf['collections']) { |
||
| 88 | if (count(explode(',', $this->conf['collections'])) == 1 |
||
| 89 | && empty($this->conf['dont_show_single'])) { |
||
| 90 | $this->showSingleCollection(intval(trim($this->conf['collections'], ' ,'))); |
||
| 91 | } |
||
| 92 | $selectedCollections = $queryBuilder->expr()->in('tx_dlf_collections.uid', implode(',', GeneralUtility::intExplode(',', $this->conf['collections']))); |
||
| 93 | } |
||
| 94 | // Should user-defined collections be shown? |
||
| 95 | if (empty($this->conf['show_userdefined'])) { |
||
| 96 | $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0); |
||
| 97 | } elseif ($this->conf['show_userdefined'] > 0) { |
||
| 98 | if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) { |
||
| 99 | $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', intval($GLOBALS['TSFE']->fe_user->user['uid'])); |
||
| 100 | } else { |
||
| 101 | $showUserDefinedColls = $queryBuilder->expr()->neq('tx_dlf_collections.fe_cruser_id', 0); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | // Get collections. |
||
| 106 | $queryBuilder |
||
| 107 | ->select( |
||
| 108 | 'tx_dlf_collections.index_name AS index_name', |
||
| 109 | 'tx_dlf_collections.index_search as index_query', |
||
| 110 | 'tx_dlf_collections.uid AS uid', |
||
| 111 | 'tx_dlf_collections.sys_language_uid AS sys_language_uid', |
||
| 112 | 'tx_dlf_collections.label AS label', |
||
| 113 | 'tx_dlf_collections.thumbnail AS thumbnail', |
||
| 114 | 'tx_dlf_collections.description AS description', |
||
| 115 | 'tx_dlf_collections.priority AS priority' |
||
| 116 | ) |
||
| 117 | ->from('tx_dlf_collections') |
||
| 118 | ->where( |
||
| 119 | $selectedCollections, |
||
| 120 | $showUserDefinedColls, |
||
| 121 | $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($this->conf['pages'])), |
||
| 122 | $queryBuilder->expr()->andX( |
||
| 123 | $queryBuilder->expr()->orX( |
||
| 124 | $queryBuilder->expr()->in('tx_dlf_collections.sys_language_uid', array(-1, 0)), |
||
| 125 | $queryBuilder->expr()->eq('tx_dlf_collections.sys_language_uid', $GLOBALS['TSFE']->sys_language_uid) |
||
| 126 | ), |
||
| 127 | $queryBuilder->expr()->eq('tx_dlf_collections.l18n_parent', 0) |
||
| 128 | ), |
||
| 129 | Helper::whereExpression('tx_dlf_collections') |
||
| 130 | ) |
||
| 131 | ->orderBy($orderBy); |
||
| 132 | |||
| 133 | $result = $queryBuilder->execute(); |
||
| 134 | $count = $queryBuilder->count('uid')->execute()->fetchColumn(0); |
||
| 135 | $content = ''; |
||
| 136 | if ($count == 1 && empty($this->conf['dont_show_single'])) { |
||
| 137 | $resArray = $result->fetch(); |
||
| 138 | $this->showSingleCollection(intval($resArray['uid'])); |
||
| 139 | } |
||
| 140 | $solr = Solr::getInstance($this->conf['solrcore']); |
||
| 141 | // We only care about the UID and partOf in the results and want them sorted |
||
| 142 | $params['fields'] = 'uid,partof'; |
||
|
1 ignored issue
–
show
|
|||
| 143 | $params['sort'] = ['uid' => 'asc']; |
||
| 144 | $collections = []; |
||
| 145 | while ($collectionData = $result->fetch()) { |
||
| 146 | if ($collectionData['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content && $GLOBALS['TSFE']->sys_language_contentOL) { |
||
| 147 | $collections[$collectionData['uid']] = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dlf_collections', $collectionData, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
| 148 | } else { |
||
| 149 | $collections[$collectionData['uid']] = $collectionData; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | // Sort collections according to flexform configuration |
||
| 153 | if ($this->conf['collections']) { |
||
| 154 | $sortedCollections = []; |
||
| 155 | foreach (GeneralUtility::intExplode(',', $this->conf['collections']) as $uid) { |
||
| 156 | $sortedCollections[$uid] = $collections[$uid]; |
||
| 157 | } |
||
| 158 | $collections = $sortedCollections; |
||
| 159 | } |
||
| 160 | $markerArray = []; |
||
| 161 | // Process results. |
||
| 162 | foreach ($collections as $collection) { |
||
| 163 | $solr_query = ''; |
||
| 164 | if ($collection['index_query'] != '') { |
||
| 165 | $solr_query .= '('.$collection['index_query'].')'; |
||
| 166 | } else { |
||
| 167 | $solr_query .= 'collection:("'.$collection['index_name'].'")'; |
||
| 168 | } |
||
| 169 | $partOfNothing = $solr->search_raw($solr_query.' AND partof:0', $params); |
||
| 170 | $partOfSomething = $solr->search_raw($solr_query.' AND NOT partof:0', $params); |
||
| 171 | // Titles are all documents that are "root" elements i.e. partof == 0 |
||
| 172 | $collection['titles'] = []; |
||
| 173 | foreach ($partOfNothing as $doc) { |
||
| 174 | $collection['titles'][$doc->uid] = $doc->uid; |
||
| 175 | } |
||
| 176 | // Volumes are documents that are both |
||
| 177 | // a) "leaf" elements i.e. partof != 0 |
||
| 178 | // b) "root" elements that are not referenced by other documents ("root" elements that have no descendants) |
||
| 179 | $collection['volumes'] = $collection['titles']; |
||
| 180 | foreach ($partOfSomething as $doc) { |
||
| 181 | $collection['volumes'][$doc->uid] = $doc->uid; |
||
| 182 | // If a document is referenced via partof, it’s not a volume anymore. |
||
| 183 | unset($collection['volumes'][$doc->partof]); |
||
| 184 | } |
||
| 185 | // Generate random but unique array key taking priority into account. |
||
| 186 | do { |
||
| 187 | $_key = ($collection['priority'] * 1000) + mt_rand(0, 1000); |
||
| 188 | } while (!empty($markerArray[$_key])); |
||
| 189 | // Merge plugin variables with new set of values. |
||
| 190 | $additionalParams = ['collection' => $collection['uid']]; |
||
| 191 | if (is_array($this->piVars)) { |
||
| 192 | $piVars = $this->piVars; |
||
| 193 | unset($piVars['DATA']); |
||
| 194 | $additionalParams = Helper::mergeRecursiveWithOverrule($piVars, $additionalParams); |
||
| 195 | } |
||
| 196 | // Build typolink configuration array. |
||
| 197 | $conf = [ |
||
| 198 | 'useCacheHash' => 1, |
||
| 199 | 'parameter' => $GLOBALS['TSFE']->id, |
||
| 200 | 'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE) |
||
| 201 | ]; |
||
| 202 | // Link collection's title to list view. |
||
| 203 | $markerArray[$_key]['###TITLE###'] = $this->cObj->typoLink(htmlspecialchars($collection['label']), $conf); |
||
| 204 | // Add feed link if applicable. |
||
| 205 | if (!empty($this->conf['targetFeed'])) { |
||
| 206 | $img = '<img src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'Resources/Public/Icons/txdlffeeds.png" alt="'.$this->pi_getLL('feedAlt', '', TRUE).'" title="'.$this->pi_getLL('feedTitle', '', TRUE).'" />'; |
||
| 207 | $markerArray[$_key]['###FEED###'] = $this->pi_linkTP($img, [$this->prefixId => ['collection' => $collection['uid']]], FALSE, $this->conf['targetFeed']); |
||
| 208 | } else { |
||
| 209 | $markerArray[$_key]['###FEED###'] = ''; |
||
| 210 | } |
||
| 211 | // Add thumbnail. |
||
| 212 | if (!empty($collection['thumbnail'])) { |
||
| 213 | $markerArray[$_key]['###THUMBNAIL###'] = '<img alt="" title="'.htmlspecialchars($collection['label']).'" src="'.$collection['thumbnail'].'" />'; |
||
| 214 | } else { |
||
| 215 | $markerArray[$_key]['###THUMBNAIL###'] = ''; |
||
| 216 | } |
||
| 217 | // Add description. |
||
| 218 | $markerArray[$_key]['###DESCRIPTION###'] = $this->pi_RTEcssText($collection['description']); |
||
| 219 | // Build statistic's output. |
||
| 220 | $labelTitles = $this->pi_getLL((count($collection['titles']) > 1 ? 'titles' : 'title'), '', FALSE); |
||
| 221 | $markerArray[$_key]['###COUNT_TITLES###'] = htmlspecialchars(count($collection['titles']).$labelTitles); |
||
| 222 | $labelVolumes = $this->pi_getLL((count($collection['volumes']) > 1 ? 'volumes' : 'volume'), '', FALSE); |
||
| 223 | $markerArray[$_key]['###COUNT_VOLUMES###'] = htmlspecialchars(count($collection['volumes']).$labelVolumes); |
||
| 224 | } |
||
| 225 | // Randomize sorting? |
||
| 226 | if (!empty($this->conf['randomize'])) { |
||
| 227 | ksort($markerArray, SORT_NUMERIC); |
||
| 228 | // Don't cache the output. |
||
| 229 | $this->setCache(FALSE); |
||
| 230 | } |
||
| 231 | $entry = $this->templateService->getSubpart($this->template, '###ENTRY###'); |
||
| 232 | foreach ($markerArray as $marker) { |
||
| 233 | $content .= $this->templateService->substituteMarkerArray($entry, $marker); |
||
| 234 | } |
||
| 235 | // Hook for getting custom collection hierarchies/subentries (requested by SBB). |
||
| 236 | foreach ($this->hookObjects as $hookObj) { |
||
| 237 | if (method_exists($hookObj, 'showCollectionList_getCustomCollectionList')) { |
||
| 238 | $hookObj->showCollectionList_getCustomCollectionList($this, $this->conf['templateFile'], $content, $markerArray); |
||
| 239 | } |
||
| 240 | } |
||
| 241 | return $this->templateService->substituteSubpart($this->template, '###ENTRY###', $content, TRUE); |
||
| 242 | } |
||
| 400 |