We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 25 |
| Paths | 4920 |
| Total Lines | 195 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 97 | protected function showCollectionList() { |
||
| 98 | |||
| 99 | $additionalWhere = ''; |
||
| 100 | |||
| 101 | $orderBy = 'tx_dlf_collections.label'; |
||
| 102 | |||
| 103 | // Handle collections set by configuration. |
||
| 104 | if ($this->conf['collections']) { |
||
| 105 | |||
| 106 | if (count(explode(',', $this->conf['collections'])) == 1 && empty($this->conf['dont_show_single'])) { |
||
| 107 | |||
| 108 | $this->showSingleCollection(intval(trim($this->conf['collections'], ' ,'))); |
||
| 109 | |||
| 110 | } |
||
| 111 | |||
| 112 | $additionalWhere .= ' AND tx_dlf_collections.uid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']).')'; |
||
| 113 | |||
| 114 | $orderBy = 'FIELD(tx_dlf_collections.uid, '.$GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']).')'; |
||
| 115 | |||
| 116 | } |
||
| 117 | |||
| 118 | // Should user-defined collections be shown? |
||
| 119 | if (empty($this->conf['show_userdefined'])) { |
||
| 120 | |||
| 121 | $additionalWhere .= ' AND tx_dlf_collections.fe_cruser_id=0'; |
||
| 122 | |||
| 123 | } elseif ($this->conf['show_userdefined'] > 0) { |
||
| 124 | |||
| 125 | if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) { |
||
| 126 | |||
| 127 | $additionalWhere .= ' AND tx_dlf_collections.fe_cruser_id='.intval($GLOBALS['TSFE']->fe_user->user['uid']); |
||
| 128 | |||
| 129 | } else { |
||
| 130 | |||
| 131 | $additionalWhere .= ' AND NOT tx_dlf_collections.fe_cruser_id=0'; |
||
| 132 | |||
| 133 | } |
||
| 134 | |||
| 135 | } |
||
| 136 | |||
| 137 | // Get collections. |
||
| 138 | $result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query( |
||
| 139 | 'tx_dlf_collections.uid AS uid,tx_dlf_collections.pid AS pid,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,COUNT(tx_dlf_documents.uid) AS titles', |
||
| 140 | 'tx_dlf_documents', |
||
| 141 | 'tx_dlf_relations', |
||
| 142 | 'tx_dlf_collections', |
||
| 143 | 'AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND tx_dlf_documents.partof=0 AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections').' 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))', |
||
| 144 | 'tx_dlf_collections.uid', |
||
| 145 | $orderBy, |
||
| 146 | '' |
||
| 147 | ); |
||
| 148 | |||
| 149 | $count = $GLOBALS['TYPO3_DB']->sql_num_rows($result); |
||
| 150 | |||
| 151 | $content = ''; |
||
| 152 | |||
| 153 | if ($count == 1 && empty($this->conf['dont_show_single'])) { |
||
| 154 | |||
| 155 | $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
||
| 156 | |||
| 157 | $this->showSingleCollection(intval($resArray['uid'])); |
||
| 158 | |||
| 159 | } elseif ($count > 0) { |
||
| 160 | |||
| 161 | // Get number of volumes per collection. |
||
| 162 | $resultVolumes = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query( |
||
| 163 | 'tx_dlf_collections.uid AS uid,COUNT(tx_dlf_documents.uid) AS volumes', |
||
| 164 | 'tx_dlf_documents', |
||
| 165 | 'tx_dlf_relations', |
||
| 166 | 'tx_dlf_collections', |
||
| 167 | 'AND tx_dlf_collections.pid='.intval($this->conf['pages']).' AND NOT tx_dlf_documents.uid IN (SELECT DISTINCT tx_dlf_documents.partof FROM tx_dlf_documents WHERE NOT tx_dlf_documents.partof=0'.tx_dlf_helper::whereClause('tx_dlf_documents').') AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations').$additionalWhere.tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'), |
||
| 168 | 'tx_dlf_collections.uid', |
||
| 169 | '', |
||
| 170 | '' |
||
| 171 | ); |
||
| 172 | |||
| 173 | $volumes = array (); |
||
| 174 | |||
| 175 | while ($resArrayVolumes = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resultVolumes)) { |
||
| 176 | |||
| 177 | $volumes[$resArrayVolumes['uid']] = $resArrayVolumes['volumes']; |
||
| 178 | |||
| 179 | } |
||
| 180 | |||
| 181 | // Process results. |
||
| 182 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
||
| 183 | |||
| 184 | if (is_array($resArray) && $resArray['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content && $GLOBALS['TSFE']->sys_language_contentOL) { |
||
| 185 | |||
| 186 | $resArray = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dlf_collections', $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
| 187 | |||
| 188 | } |
||
| 189 | |||
| 190 | // Generate random but unique array key taking priority into account. |
||
| 191 | do { |
||
| 192 | |||
| 193 | $_key = ($resArray['priority'] * 1000) + mt_rand(0, 1000); |
||
| 194 | |||
| 195 | } while (!empty($markerArray[$_key])); |
||
| 196 | |||
| 197 | // Merge plugin variables with new set of values. |
||
| 198 | $additionalParams = array ('collection' => $resArray['uid']); |
||
| 199 | |||
| 200 | if (is_array($this->piVars)) { |
||
| 201 | |||
| 202 | $piVars = $this->piVars; |
||
| 203 | |||
| 204 | unset($piVars['DATA']); |
||
| 205 | |||
| 206 | $additionalParams = tx_dlf_helper::array_merge_recursive_overrule($piVars, $additionalParams); |
||
| 207 | |||
| 208 | } |
||
| 209 | |||
| 210 | // Build typolink configuration array. |
||
| 211 | $conf = array ( |
||
| 212 | 'useCacheHash' => 1, |
||
| 213 | 'parameter' => $GLOBALS['TSFE']->id, |
||
| 214 | 'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE) |
||
| 215 | ); |
||
| 216 | |||
| 217 | // Link collection's title to list view. |
||
| 218 | $markerArray[$_key]['###TITLE###'] = $this->cObj->typoLink(htmlspecialchars($resArray['label']), $conf); |
||
| 219 | |||
| 220 | // Add feed link if applicable. |
||
| 221 | if (!empty($this->conf['targetFeed'])) { |
||
| 222 | |||
| 223 | $img = '<img src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/icons/txdlffeeds.png" alt="'.$this->pi_getLL('feedAlt', '', TRUE).'" title="'.$this->pi_getLL('feedTitle', '', TRUE).'" />'; |
||
| 224 | |||
| 225 | $markerArray[$_key]['###FEED###'] = $this->pi_linkTP($img, array ($this->prefixId => array ('collection' => $resArray['uid'])), FALSE, $this->conf['targetFeed']); |
||
| 226 | |||
| 227 | } else { |
||
| 228 | |||
| 229 | $markerArray[$_key]['###FEED###'] = ''; |
||
| 230 | |||
| 231 | } |
||
| 232 | |||
| 233 | // Add thumbnail. |
||
| 234 | if (!empty($resArray['thumbnail'])) { |
||
| 235 | |||
| 236 | $markerArray[$_key]['###THUMBNAIL###'] = '<img alt="" title="'.htmlspecialchars($resArray['label']).'" src="'.$resArray['thumbnail'].'" />'; |
||
| 237 | |||
| 238 | } else { |
||
| 239 | |||
| 240 | $markerArray[$_key]['###THUMBNAIL###'] = ''; |
||
| 241 | |||
| 242 | } |
||
| 243 | |||
| 244 | // Add description. |
||
| 245 | $markerArray[$_key]['###DESCRIPTION###'] = $this->pi_RTEcssText($resArray['description']); |
||
| 246 | |||
| 247 | // Build statistic's output. |
||
| 248 | $labelTitles = $this->pi_getLL(($resArray['titles'] > 1 ? 'titles' : 'title'), '', FALSE); |
||
| 249 | |||
| 250 | $markerArray[$_key]['###COUNT_TITLES###'] = htmlspecialchars($resArray['titles'].$labelTitles); |
||
| 251 | |||
| 252 | $labelVolumes = $this->pi_getLL(($volumes[$resArray['uid']] > 1 ? 'volumes' : 'volume'), '', FALSE); |
||
| 253 | |||
| 254 | $markerArray[$_key]['###COUNT_VOLUMES###'] = htmlspecialchars($volumes[$resArray['uid']].$labelVolumes); |
||
| 255 | |||
| 256 | } |
||
| 257 | |||
| 258 | // Randomize sorting? |
||
| 259 | if (!empty($this->conf['randomize'])) { |
||
| 260 | |||
| 261 | ksort($markerArray, SORT_NUMERIC); |
||
| 262 | |||
| 263 | // Don't cache the output. |
||
| 264 | $this->setCache(FALSE); |
||
| 265 | |||
| 266 | } |
||
| 267 | |||
| 268 | $entry = $this->cObj->getSubpart($this->template, '###ENTRY###'); |
||
| 269 | |||
| 270 | foreach ($markerArray as $marker) { |
||
| 271 | |||
| 272 | $content .= $this->cObj->substituteMarkerArray($entry, $marker); |
||
| 273 | |||
| 274 | } |
||
| 275 | |||
| 276 | // Hook for getting custom collection hierarchies/subentries (requested by SBB). |
||
| 277 | foreach ($this->hookObjects as $hookObj) { |
||
| 278 | |||
| 279 | if (method_exists($hookObj, 'showCollectionList_getCustomCollectionList')) { |
||
| 280 | |||
| 281 | $hookObj->showCollectionList_getCustomCollectionList($this, $this->conf['templateFile'], $content, $markerArray); |
||
| 282 | |||
| 283 | } |
||
| 284 | |||
| 285 | } |
||
| 286 | |||
| 287 | return $this->cObj->substituteSubpart($this->template, '###ENTRY###', $content, TRUE); |
||
| 288 | |||
| 289 | } |
||
| 290 | |||
| 291 | return $content; |
||
| 292 | |||
| 445 |