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