We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 35 |
| Paths | 4705 |
| Total Lines | 180 |
| Code Lines | 136 |
| 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 |
||
| 52 | public function calendar($content, $conf) { |
||
| 53 | $this->init($conf); |
||
| 54 | // Load current document. |
||
| 55 | $this->loadDocument(); |
||
| 56 | if ($this->doc === NULL) { |
||
| 57 | // Quit without doing anything if required variables are not set. |
||
| 58 | return $content; |
||
| 59 | } |
||
| 60 | // Load template file. |
||
| 61 | $this->getTemplate('###TEMPLATECALENDAR###'); |
||
| 62 | // Get all children of year anchor. |
||
| 63 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 64 | 'tx_dlf_documents.uid AS uid, tx_dlf_documents.title AS title, tx_dlf_documents.year AS year', |
||
| 65 | 'tx_dlf_documents', |
||
| 66 | 'tx_dlf_documents.structure='.Helper::getUidFromIndexName('issue', 'tx_dlf_structures', $this->doc->pid) |
||
|
|
|||
| 67 | .' AND tx_dlf_documents.partof='.intval($this->doc->uid) |
||
| 68 | .Helper::whereClause('tx_dlf_documents'), |
||
| 69 | '', |
||
| 70 | 'title ASC', |
||
| 71 | '' |
||
| 72 | ); |
||
| 73 | // Process results. |
||
| 74 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
||
| 75 | $issues[] = [ |
||
| 76 | 'uid' => $resArray['uid'], |
||
| 77 | 'title' => $resArray['title'], |
||
| 78 | 'year' => $resArray['year'] |
||
| 79 | ]; |
||
| 80 | } |
||
| 81 | // We need an array of issues with month number as key. |
||
| 82 | $calendarIssues = []; |
||
| 83 | foreach ($issues as $issue) { |
||
| 84 | $calendarIssues[date('n', strtotime($issue['year']))][date('j', strtotime($issue['year']))][] = $issue; |
||
| 85 | } |
||
| 86 | $allIssues = []; |
||
| 87 | // Get subpart templates. |
||
| 88 | $subparts['list'] = $this->cObj->getSubpart($this->template, '###ISSUELIST###'); |
||
|
1 ignored issue
–
show
|
|||
| 89 | $subparts['month'] = $this->cObj->getSubpart($this->template, '###CALMONTH###'); |
||
| 90 | $subparts['week'] = $this->cObj->getSubpart($subparts['month'], '###CALWEEK###'); |
||
| 91 | $subparts['singleday'] = $this->cObj->getSubpart($subparts['list'], '###SINGLEDAY###'); |
||
| 92 | // Build calendar for given year. |
||
| 93 | $year = date('Y', strtotime($issues[0]['year'])); |
||
| 94 | $subPartContent = ''; |
||
| 95 | for ($i = 0; $i <= 11; $i++) { |
||
| 96 | $markerArray = [ |
||
| 97 | '###DAYMON_NAME###' => strftime('%a', strtotime('last Monday')), |
||
| 98 | '###DAYTUE_NAME###' => strftime('%a', strtotime('last Tuesday')), |
||
| 99 | '###DAYWED_NAME###' => strftime('%a', strtotime('last Wednesday')), |
||
| 100 | '###DAYTHU_NAME###' => strftime('%a', strtotime('last Thursday')), |
||
| 101 | '###DAYFRI_NAME###' => strftime('%a', strtotime('last Friday')), |
||
| 102 | '###DAYSAT_NAME###' => strftime('%a', strtotime('last Saturday')), |
||
| 103 | '###DAYSUN_NAME###' => strftime('%a', strtotime('last Sunday')), |
||
| 104 | '###MONTHNAME###' => strftime('%B', strtotime($year.'-'.($i + 1).'-1')) |
||
| 105 | ]; |
||
| 106 | // Reset week content of new month. |
||
| 107 | $subWeekPartContent = ''; |
||
| 108 | $firstOfMonth = strtotime($year.'-'.($i + 1).'-1'); |
||
| 109 | $lastOfMonth = strtotime('last day of', ($firstOfMonth)); |
||
| 110 | $firstOfMonthStart = strtotime('last Monday', $firstOfMonth); |
||
| 111 | // There are never more than 6 weeks in a month. |
||
| 112 | for ($j = 0; $j <= 5; $j++) { |
||
| 113 | $firstDayOfWeek = strtotime('+ '.$j.' Week', $firstOfMonthStart); |
||
| 114 | $weekArray = [ |
||
| 115 | '###DAYMON###' => ' ', |
||
| 116 | '###DAYTUE###' => ' ', |
||
| 117 | '###DAYWED###' => ' ', |
||
| 118 | '###DAYTHU###' => ' ', |
||
| 119 | '###DAYFRI###' => ' ', |
||
| 120 | '###DAYSAT###' => ' ', |
||
| 121 | '###DAYSUN###' => ' ', |
||
| 122 | ]; |
||
| 123 | // Every week has seven days. ;-) |
||
| 124 | for ($k = 0; $k <= 6; $k++) { |
||
| 125 | $currentDayTime = strtotime('+ '.$k.' Day', $firstDayOfWeek); |
||
| 126 | if ($currentDayTime >= $firstOfMonth |
||
| 127 | && $currentDayTime <= $lastOfMonth) { |
||
| 128 | $dayLinks = ''; |
||
| 129 | $dayLinksText = []; |
||
| 130 | $dayLinksList = ''; |
||
| 131 | $currentMonth = date('n', $currentDayTime); |
||
| 132 | if (is_array($calendarIssues[$currentMonth])) { |
||
| 133 | foreach ($calendarIssues[$currentMonth] as $id => $day) { |
||
| 134 | if ($id == date('j', $currentDayTime)) { |
||
| 135 | $dayLinks = $id; |
||
| 136 | foreach ($day as $issue) { |
||
| 137 | $dayLinkLabel = empty($issue['title']) ? strftime('%x', $currentDayTime) : $issue['title']; |
||
| 138 | $linkConf = [ |
||
| 139 | 'useCacheHash' => 1, |
||
| 140 | 'parameter' => $this->conf['targetPid'], |
||
| 141 | 'additionalParams' => '&'.$this->prefixId.'[id]='.urlencode($issue['uid']), |
||
| 142 | 'ATagParams' => ' class="title"', |
||
| 143 | ]; |
||
| 144 | $dayLinksText[] = $this->cObj->typoLink($dayLinkLabel, $linkConf); |
||
| 145 | // Save issues for list view. |
||
| 146 | $allIssues[$currentDayTime][] = $this->cObj->typoLink($dayLinkLabel, $linkConf); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | if (!empty($dayLinksText)) { |
||
| 151 | $dayLinksList = '<ul>'; |
||
| 152 | foreach ($dayLinksText as $link) { |
||
| 153 | $dayLinksList .= '<li>'.$link.'</li>'; |
||
| 154 | } |
||
| 155 | $dayLinksList .= '</ul>'; |
||
| 156 | } |
||
| 157 | $dayLinkDiv = '<div class="issues"><h4>'.strftime('%d', $currentDayTime).'</h4><div>'.$dayLinksList.'</div></div>'; |
||
| 158 | } |
||
| 159 | switch (strftime('%w', strtotime('+ '.$k.' Day', $firstDayOfWeek))) { |
||
| 160 | case '0': |
||
| 161 | $weekArray['###DAYSUN###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 162 | break; |
||
| 163 | case '1': |
||
| 164 | $weekArray['###DAYMON###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 165 | break; |
||
| 166 | case '2': |
||
| 167 | $weekArray['###DAYTUE###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 168 | break; |
||
| 169 | case '3': |
||
| 170 | $weekArray['###DAYWED###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 171 | break; |
||
| 172 | case '4': |
||
| 173 | $weekArray['###DAYTHU###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 174 | break; |
||
| 175 | case '5': |
||
| 176 | $weekArray['###DAYFRI###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 177 | break; |
||
| 178 | case '6': |
||
| 179 | $weekArray['###DAYSAT###'] = ((int) $dayLinks === (int) date('j', $currentDayTime)) ? $dayLinkDiv : strftime('%d', $currentDayTime); |
||
| 180 | break; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | } |
||
| 184 | // Fill the weeks. |
||
| 185 | $subWeekPartContent .= $this->cObj->substituteMarkerArray($subparts['week'], $weekArray); |
||
| 186 | } |
||
| 187 | // Fill the month markers. |
||
| 188 | $subPartContent .= $this->cObj->substituteMarkerArray($subparts['month'], $markerArray); |
||
| 189 | // Fill the week markers with the week entries. |
||
| 190 | $subPartContent = $this->cObj->substituteSubpart($subPartContent, '###CALWEEK###', $subWeekPartContent); |
||
| 191 | } |
||
| 192 | // Link to years overview |
||
| 193 | $linkConf = [ |
||
| 194 | 'useCacheHash' => 1, |
||
| 195 | 'parameter' => $this->conf['targetPid'], |
||
| 196 | 'additionalParams' => '&'.$this->prefixId.'[id]='.urlencode($this->doc->parentId), |
||
| 197 | ]; |
||
| 198 | $allYearsLink = $this->cObj->typoLink($this->pi_getLL('allYears', '', TRUE).' '.$this->doc->getTitle($this->doc->parentId), $linkConf); |
||
| 199 | // Link to current year. |
||
| 200 | $linkConf = [ |
||
| 201 | 'useCacheHash' => 1, |
||
| 202 | 'parameter' => $this->conf['targetPid'], |
||
| 203 | 'additionalParams' => '&'.$this->prefixId.'[id]='.urlencode($this->doc->uid), |
||
| 204 | ]; |
||
| 205 | $yearLink = $this->cObj->typoLink($year, $linkConf); |
||
| 206 | $subPartContentList = ''; |
||
| 207 | // Prepare list as alternative of the calendar view. |
||
| 208 | foreach ($allIssues as $dayTime => $issues) { |
||
| 209 | $markerArrayDay['###DATE_STRING###'] = strftime('%A, %x', $dayTime); |
||
| 210 | $markerArrayDay['###ITEMS###'] = ''; |
||
| 211 | foreach ($issues as $issue) { |
||
| 212 | $markerArrayDay['###ITEMS###'] .= $issue; |
||
| 213 | } |
||
| 214 | $subPartContentList .= $this->cObj->substituteMarkerArray($subparts['singleday'], $markerArrayDay); |
||
| 215 | } |
||
| 216 | $this->template = $this->cObj->substituteSubpart($this->template, '###SINGLEDAY###', $subPartContentList); |
||
| 217 | if (count($allIssues) < 6) { |
||
| 218 | $listViewActive = TRUE; |
||
| 219 | } else { |
||
| 220 | $listViewActive = FALSE; |
||
| 221 | } |
||
| 222 | $markerArray = [ |
||
| 223 | '###CALENDARVIEWACTIVE###' => $listViewActive ? '' : 'active', |
||
| 224 | '###LISTVIEWACTIVE###' => $listViewActive ? 'active' : '', |
||
| 225 | '###CALYEAR###' => $yearLink, |
||
| 226 | '###CALALLYEARS###' => $allYearsLink, |
||
| 227 | '###LABEL_CALENDAR###' => $this->pi_getLL('label.view_calendar'), |
||
| 228 | '###LABEL_LIST_VIEW###' => $this->pi_getLL('label.view_list'), |
||
| 229 | ]; |
||
| 230 | $this->template = $this->cObj->substituteMarkerArray($this->template, $markerArray); |
||
| 231 | return $this->cObj->substituteSubpart($this->template, '###CALMONTH###', $subPartContent); |
||
| 232 | } |
||
| 308 |