| Total Complexity | 49 |
| Total Lines | 447 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like TranslationStatusController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TranslationStatusController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * @var IconFactory |
||
| 35 | */ |
||
| 36 | protected $iconFactory; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Construct for initialize class variables |
||
| 40 | */ |
||
| 41 | public function __construct() |
||
| 42 | { |
||
| 43 | $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Returns the menu array |
||
| 48 | * |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | public function modMenu() |
||
| 52 | { |
||
| 53 | $lang = $this->getLanguageService(); |
||
| 54 | $menuArray = [ |
||
| 55 | 'depth' => [ |
||
| 56 | 0 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_0'), |
||
| 57 | 1 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_1'), |
||
| 58 | 2 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_2'), |
||
| 59 | 3 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_3'), |
||
| 60 | 4 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_4'), |
||
| 61 | 999 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_infi') |
||
| 62 | ] |
||
| 63 | ]; |
||
| 64 | // Languages: |
||
| 65 | $lang = $this->getSystemLanguages(); |
||
| 66 | $menuArray['lang'] = [ |
||
| 67 | 0 => '[All]' |
||
| 68 | ]; |
||
| 69 | foreach ($lang as $langRec) { |
||
| 70 | $menuArray['lang'][$langRec['uid']] = $langRec['title']; |
||
| 71 | } |
||
| 72 | return $menuArray; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * MAIN function for page information of localization |
||
| 77 | * |
||
| 78 | * @return string Output HTML for the module. |
||
| 79 | */ |
||
| 80 | public function main() |
||
| 81 | { |
||
| 82 | $theOutput = '<h1>' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_title')) . '</h1>'; |
||
| 83 | if ($this->pObj->id) { |
||
| 84 | // Depth selector: |
||
| 85 | $theOutput .= '<div class="form-inline form-inline-spaced">'; |
||
| 86 | $h_func = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[depth]', $this->pObj->MOD_SETTINGS['depth'], $this->pObj->MOD_MENU['depth']); |
||
| 87 | $h_func .= BackendUtility::getDropdownMenu($this->pObj->id, 'SET[lang]', $this->pObj->MOD_SETTINGS['lang'], $this->pObj->MOD_MENU['lang']); |
||
| 88 | $theOutput .= $h_func; |
||
| 89 | // Add CSH: |
||
| 90 | $theOutput .= BackendUtility::cshItem('_MOD_web_info', 'lang', null, '<div class="form-group"><span class="btn btn-default btn-sm">|</span></div><br />'); |
||
| 91 | $theOutput .= '</div>'; |
||
| 92 | // Showing the tree: |
||
| 93 | // Initialize starting point of page tree: |
||
| 94 | $treeStartingPoint = (int)$this->pObj->id; |
||
| 95 | $treeStartingRecord = BackendUtility::getRecordWSOL('pages', $treeStartingPoint); |
||
| 96 | $depth = $this->pObj->MOD_SETTINGS['depth']; |
||
| 97 | // Initialize tree object: |
||
| 98 | $tree = GeneralUtility::makeInstance(PageTreeView::class); |
||
| 99 | $tree->init('AND ' . $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)); |
||
| 100 | $tree->addField('l18n_cfg'); |
||
| 101 | // Creating top icon; the current page |
||
| 102 | $HTML = $this->iconFactory->getIconForRecord('pages', $treeStartingRecord, Icon::SIZE_SMALL)->render(); |
||
| 103 | $tree->tree[] = [ |
||
| 104 | 'row' => $treeStartingRecord, |
||
| 105 | 'HTML' => $HTML |
||
| 106 | ]; |
||
| 107 | // Create the tree from starting point: |
||
| 108 | if ($depth) { |
||
| 109 | $tree->getTree($treeStartingPoint, $depth, ''); |
||
| 110 | } |
||
| 111 | // Render information table: |
||
| 112 | $theOutput .= $this->renderL10nTable($tree); |
||
|
|
|||
| 113 | } |
||
| 114 | return $theOutput; |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Rendering the localization information table. |
||
| 119 | * |
||
| 120 | * @param array $tree The Page tree data |
||
| 121 | * @return string HTML for the localization information table. |
||
| 122 | */ |
||
| 123 | public function renderL10nTable(&$tree) |
||
| 124 | { |
||
| 125 | $lang = $this->getLanguageService(); |
||
| 126 | // System languages retrieved: |
||
| 127 | $languages = $this->getSystemLanguages(); |
||
| 128 | // Title length: |
||
| 129 | $titleLen = $this->getBackendUser()->uc['titleLen']; |
||
| 130 | // Put together the TREE: |
||
| 131 | $output = ''; |
||
| 132 | $newOL_js = []; |
||
| 133 | $langRecUids = []; |
||
| 134 | /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ |
||
| 135 | $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); |
||
| 136 | foreach ($tree->tree as $data) { |
||
| 137 | $tCells = []; |
||
| 138 | $langRecUids[0][] = $data['row']['uid']; |
||
| 139 | // Page icons / titles etc. |
||
| 140 | $tCells[] = '<td' . ($data['row']['_CSSCLASS'] ? ' class="' . $data['row']['_CSSCLASS'] . '"' : '') . '>' . |
||
| 141 | ($data['depthData'] ?: '') . |
||
| 142 | BackendUtility::wrapClickMenuOnIcon($data['HTML'], 'pages', $data['row']['uid']) . |
||
| 143 | '<a href="#" onclick="' . htmlspecialchars( |
||
| 144 | 'top.loadEditId(' . (int)$data['row']['uid'] . ',"&SET[language]=0"); return false;' |
||
| 145 | ) . '" title="' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editPage') . '">' . |
||
| 146 | htmlspecialchars(GeneralUtility::fixed_lgd_cs($data['row']['title'], $titleLen)) . |
||
| 147 | '</a>' . |
||
| 148 | ((string)$data['row']['nav_title'] !== '' ? ' [Nav: <em>' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($data['row']['nav_title'], $titleLen)) . '</em>]' : '') . |
||
| 149 | '</td>'; |
||
| 150 | // DEFAULT language: |
||
| 151 | // "View page" link is created: |
||
| 152 | $viewPageLink = '<a href="#" onclick="' . htmlspecialchars( |
||
| 153 | BackendUtility::viewOnClick( |
||
| 154 | $data['row']['uid'], |
||
| 155 | '', |
||
| 156 | null, |
||
| 157 | '', |
||
| 158 | '', |
||
| 159 | '&L=###LANG_UID###' |
||
| 160 | ) |
||
| 161 | ) . '" class="btn btn-default" title="' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_viewPage') . '">' . |
||
| 162 | $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render() . '</a>'; |
||
| 163 | $status = GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? 'danger' : 'success'; |
||
| 164 | // Create links: |
||
| 165 | $editUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', [ |
||
| 166 | 'edit' => [ |
||
| 167 | 'pages' => [ |
||
| 168 | $data['row']['uid'] => 'edit' |
||
| 169 | ] |
||
| 170 | ], |
||
| 171 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
||
| 172 | ]); |
||
| 173 | $info = '<a href="#" onclick="' . htmlspecialchars( |
||
| 174 | BackendUtility::viewOnClick( |
||
| 175 | $data['row']['uid'], |
||
| 176 | '', |
||
| 177 | null, |
||
| 178 | '', |
||
| 179 | '', |
||
| 180 | '' |
||
| 181 | ) |
||
| 182 | ) . '" class="btn btn-default" title="' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_viewPage') . '">' . |
||
| 183 | $this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL)->render() . '</a>'; |
||
| 184 | $info .= '<a href="' . htmlspecialchars($editUrl) |
||
| 185 | . '" class="btn btn-default" title="' . $lang->sL( |
||
| 186 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editDefaultLanguagePage' |
||
| 187 | ) . '">' . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render() . '</a>'; |
||
| 188 | $info .= ' '; |
||
| 189 | $info .= GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? '<span title="' . htmlspecialchars($lang->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.l18n_cfg.I.1')) . '">D</span>' : ' '; |
||
| 190 | $info .= GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) ? '<span title="' . htmlspecialchars($lang->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.l18n_cfg.I.2')) . '">N</span>' : ' '; |
||
| 191 | // Put into cell: |
||
| 192 | $tCells[] = '<td class="' . $status . ' col-border-left"><div class="btn-group">' . $info . '</div></td>'; |
||
| 193 | $tCells[] = '<td class="' . $status . '" title="' . $lang->sL( |
||
| 194 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_CEcount' |
||
| 195 | ) . '" align="center">' . $this->getContentElementCount($data['row']['uid'], 0) . '</td>'; |
||
| 196 | $modSharedTSconfig = BackendUtility::getModTSconfig($data['row']['uid'], 'mod.SHARED'); |
||
| 197 | $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages']) ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], true) : []; |
||
| 198 | // Traverse system languages: |
||
| 199 | foreach ($languages as $langRow) { |
||
| 200 | if ($this->pObj->MOD_SETTINGS['lang'] == 0 || (int)$this->pObj->MOD_SETTINGS['lang'] === (int)$langRow['uid']) { |
||
| 201 | $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']); |
||
| 202 | $info = ''; |
||
| 203 | if (is_array($row)) { |
||
| 204 | $langRecUids[$langRow['uid']][] = $row['uid']; |
||
| 205 | $status = $row['_HIDDEN'] ? (GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) || GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? 'danger' : '') : 'success'; |
||
| 206 | $icon = $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL)->render(); |
||
| 207 | $info = $icon . htmlspecialchars( |
||
| 208 | GeneralUtility::fixed_lgd_cs($row['title'], $titleLen) |
||
| 209 | ) . ((string)$row['nav_title'] !== '' ? ' [Nav: <em>' . htmlspecialchars( |
||
| 210 | GeneralUtility::fixed_lgd_cs($row['nav_title'], $titleLen) |
||
| 211 | ) . '</em>]' : '') . ($row['_COUNT'] > 1 ? '<div>' . $lang->sL( |
||
| 212 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_badThingThereAre' |
||
| 213 | ) . '</div>' : ''); |
||
| 214 | $tCells[] = '<td class="' . $status . ' col-border-left">' . |
||
| 215 | '<a href="#" onclick="' . htmlspecialchars( |
||
| 216 | 'top.loadEditId(' . (int)$data['row']['uid'] . ',"&SET[language]=' . $langRow['uid'] . '"); return false;' |
||
| 217 | ) . '" title="' . $lang->sL( |
||
| 218 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editPageLang' |
||
| 219 | ) . '">' . $info . '</a></td>'; |
||
| 220 | // Edit whole record: |
||
| 221 | // Create links: |
||
| 222 | $editUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', [ |
||
| 223 | 'edit' => [ |
||
| 224 | 'pages' => [ |
||
| 225 | $row['uid'] => 'edit' |
||
| 226 | ] |
||
| 227 | ], |
||
| 228 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
||
| 229 | ]); |
||
| 230 | $info = str_replace('###LANG_UID###', $langRow['uid'], $viewPageLink); |
||
| 231 | $info .= '<a href="' . htmlspecialchars($editUrl) |
||
| 232 | . '" class="btn btn-default" title="' . $lang->sL( |
||
| 233 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editLanguageOverlayRecord' |
||
| 234 | ) . '">' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'; |
||
| 235 | $tCells[] = '<td class="' . $status . '"><div class="btn-group">' . $info . '</div></td>'; |
||
| 236 | $tCells[] = '<td class="' . $status . '" title="' . $lang->sL( |
||
| 237 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_CEcount' |
||
| 238 | ) . '" align="center">' . $this->getContentElementCount($data['row']['uid'], $langRow['uid']) . '</td>'; |
||
| 239 | } else { |
||
| 240 | if (in_array($langRow['uid'], $disableLanguages)) { |
||
| 241 | // Language has been disabled for this page |
||
| 242 | $status = 'danger'; |
||
| 243 | $info = ''; |
||
| 244 | } else { |
||
| 245 | $status = GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) || GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? 'danger' : ''; |
||
| 246 | $info = '<div class="btn-group"><label class="btn btn-default btn-checkbox">'; |
||
| 247 | $info .= '<input type="checkbox" name="newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']" value="1" />'; |
||
| 248 | $info .= '<span class="t3-icon fa"></span></label></div>'; |
||
| 249 | $newOL_js[$langRow['uid']] .= ' |
||
| 250 | +(document.webinfoForm[' |
||
| 251 | . GeneralUtility::quoteJSvalue('newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']') |
||
| 252 | . '].checked ? ' |
||
| 253 | . GeneralUtility::quoteJSvalue('&edit[pages][' . $data['row']['uid'] . ']=new') |
||
| 254 | . ' : \'\') |
||
| 255 | '; |
||
| 256 | } |
||
| 257 | $tCells[] = '<td class="' . $status . ' col-border-left"> </td>'; |
||
| 258 | $tCells[] = '<td class="' . $status . '"> </td>'; |
||
| 259 | $tCells[] = '<td class="' . $status . '">' . $info . '</td>'; |
||
| 260 | } |
||
| 261 | } |
||
| 262 | } |
||
| 263 | $output .= ' |
||
| 264 | <tr> |
||
| 265 | ' . implode(' |
||
| 266 | ', $tCells) . ' |
||
| 267 | </tr>'; |
||
| 268 | } |
||
| 269 | // Put together HEADER: |
||
| 270 | $tCells = []; |
||
| 271 | $tCells[] = '<td>' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_page') . ':</td>'; |
||
| 272 | if (is_array($langRecUids[0])) { |
||
| 273 | $editUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', [ |
||
| 274 | 'edit' => [ |
||
| 275 | 'pages' => [ |
||
| 276 | implode(',', $langRecUids[0]) => 'edit' |
||
| 277 | ] |
||
| 278 | ], |
||
| 279 | 'columnsOnly' => 'title,nav_title,l18n_cfg,hidden', |
||
| 280 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
||
| 281 | ]); |
||
| 282 | $editIco = '<a href="' . htmlspecialchars($editUrl) |
||
| 283 | . '" class="btn btn-default" title="' . $lang->sL( |
||
| 284 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editPageProperties' |
||
| 285 | ) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>'; |
||
| 286 | } else { |
||
| 287 | $editIco = ''; |
||
| 288 | } |
||
| 289 | $tCells[] = '<td class="col-border-left" colspan="2">' . $lang->sL( |
||
| 290 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_default' |
||
| 291 | ) . ':' . $editIco . '</td>'; |
||
| 292 | foreach ($languages as $langRow) { |
||
| 293 | if ($this->pObj->MOD_SETTINGS['lang'] == 0 || (int)$this->pObj->MOD_SETTINGS['lang'] === (int)$langRow['uid']) { |
||
| 294 | // Title: |
||
| 295 | $tCells[] = '<td class="col-border-left">' . htmlspecialchars($langRow['title']) . '</td>'; |
||
| 296 | // Edit language overlay records: |
||
| 297 | if (is_array($langRecUids[$langRow['uid']])) { |
||
| 298 | $editUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', [ |
||
| 299 | 'edit' => [ |
||
| 300 | 'pages' => [ |
||
| 301 | implode(',', $langRecUids[$langRow['uid']]) => 'edit' |
||
| 302 | ] |
||
| 303 | ], |
||
| 304 | 'columnsOnly' => 'title,nav_title,hidden', |
||
| 305 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
||
| 306 | ]); |
||
| 307 | $editButton = '<a href="' . htmlspecialchars($editUrl) |
||
| 308 | . '" class="btn btn-default" title="' . $lang->sL( |
||
| 309 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editLangOverlays' |
||
| 310 | ) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>'; |
||
| 311 | } else { |
||
| 312 | $editButton = ''; |
||
| 313 | } |
||
| 314 | // Create new overlay records: |
||
| 315 | $params = '&columnsOnly=title,hidden,sys_language_uid&overrideVals[pages][sys_language_uid]=' . $langRow['uid']; |
||
| 316 | $onClick = BackendUtility::editOnClick($params); |
||
| 317 | if (!empty($newOL_js[$langRow['uid']])) { |
||
| 318 | $onClickArray = explode('?', $onClick, 2); |
||
| 319 | $lastElement = array_pop($onClickArray); |
||
| 320 | $onClickArray[] = '\'' . $newOL_js[$langRow['uid']] . ' + \'&' . $lastElement; |
||
| 321 | $onClick = implode('?', $onClickArray); |
||
| 322 | } |
||
| 323 | $newButton = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onClick) |
||
| 324 | . '" title="' . $lang->sL( |
||
| 325 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_getlangsta_createNewTranslationHeaders' |
||
| 326 | ) . '">' . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render() . '</a>'; |
||
| 327 | |||
| 328 | $tCells[] = '<td class="btn-group">' . $editButton . $newButton . '</td>'; |
||
| 329 | $tCells[] = '<td> </td>'; |
||
| 330 | } |
||
| 331 | } |
||
| 332 | |||
| 333 | $output = |
||
| 334 | '<div class="table-fit">' . |
||
| 335 | '<table class="table table-striped table-hover" id="langTable">' . |
||
| 336 | '<thead>' . |
||
| 337 | '<tr>' . |
||
| 338 | implode('', $tCells) . |
||
| 339 | '</tr>' . |
||
| 340 | '</thead>' . |
||
| 341 | '<tbody>' . |
||
| 342 | $output . |
||
| 343 | '</tbody>' . |
||
| 344 | '</table>' . |
||
| 345 | '</div>'; |
||
| 346 | return $output; |
||
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Selects all system languages (from sys_language) |
||
| 351 | * |
||
| 352 | * @return array System language records in an array. |
||
| 353 | */ |
||
| 354 | public function getSystemLanguages() |
||
| 355 | { |
||
| 356 | if (!$this->getBackendUser()->isAdmin() && $this->getBackendUser()->groupData['allowed_languages'] !== '') { |
||
| 357 | $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages'])); |
||
| 358 | } |
||
| 359 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 360 | ->getQueryBuilderForTable('sys_language'); |
||
| 361 | $queryBuilder |
||
| 362 | ->getRestrictions() |
||
| 363 | ->removeAll(); |
||
| 364 | $queryBuilder |
||
| 365 | ->select('*') |
||
| 366 | ->from('sys_language') |
||
| 367 | ->orderBy('sorting'); |
||
| 368 | $res = $queryBuilder->execute(); |
||
| 369 | $outputArray = []; |
||
| 370 | if (is_array($allowed_languages) && !empty($allowed_languages)) { |
||
| 371 | while ($output = $res->fetch()) { |
||
| 372 | if (isset($allowed_languages[$output['uid']])) { |
||
| 373 | $outputArray[] = $output; |
||
| 374 | } |
||
| 375 | } |
||
| 376 | } else { |
||
| 377 | $outputArray = $res->fetchAll(); |
||
| 378 | } |
||
| 379 | return $outputArray; |
||
| 380 | } |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Get an alternative language record for a specific page / language |
||
| 384 | * |
||
| 385 | * @param int $pageId Page ID to look up for. |
||
| 386 | * @param int $langId Language UID to select for. |
||
| 387 | * @return array translated pages record |
||
| 388 | */ |
||
| 389 | public function getLangStatus($pageId, $langId) |
||
| 390 | { |
||
| 391 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 392 | ->getQueryBuilderForTable('pages'); |
||
| 393 | $queryBuilder |
||
| 394 | ->getRestrictions() |
||
| 395 | ->removeAll() |
||
| 396 | ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class)) |
||
| 397 | ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); |
||
| 398 | $result = $queryBuilder |
||
| 399 | ->select('*') |
||
| 400 | ->from('pages') |
||
| 401 | ->where( |
||
| 402 | $queryBuilder->expr()->eq( |
||
| 403 | $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'], |
||
| 404 | $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT) |
||
| 405 | ) |
||
| 406 | ) |
||
| 407 | ->andWhere( |
||
| 408 | $queryBuilder->expr()->eq( |
||
| 409 | $GLOBALS['TCA']['pages']['ctrl']['languageField'], |
||
| 410 | $queryBuilder->createNamedParameter($langId, \PDO::PARAM_INT) |
||
| 411 | ) |
||
| 412 | ) |
||
| 413 | ->execute(); |
||
| 414 | |||
| 415 | $row = $result->fetch(); |
||
| 416 | BackendUtility::workspaceOL('pages', $row); |
||
| 417 | if (is_array($row)) { |
||
| 418 | $row['_COUNT'] = $result->rowCount(); |
||
| 419 | $row['_HIDDEN'] = $row['hidden'] || (int)$row['endtime'] > 0 && (int)$row['endtime'] < $GLOBALS['EXEC_TIME'] || $GLOBALS['EXEC_TIME'] < (int)$row['starttime']; |
||
| 420 | } |
||
| 421 | $result->closeCursor(); |
||
| 422 | return $row; |
||
| 423 | } |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Counting content elements for a single language on a page. |
||
| 427 | * |
||
| 428 | * @param int $pageId Page id to select for. |
||
| 429 | * @param int $sysLang Sys language uid |
||
| 430 | * @return int Number of content elements from the PID where the language is set to a certain value. |
||
| 431 | */ |
||
| 432 | public function getContentElementCount($pageId, $sysLang) |
||
| 433 | { |
||
| 434 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 435 | ->getQueryBuilderForTable('pages'); |
||
| 436 | $queryBuilder->getRestrictions() |
||
| 437 | ->removeAll() |
||
| 438 | ->add(GeneralUtility::makeInstance(DeletedRestriction::class)) |
||
| 439 | ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class)); |
||
| 440 | $count = $queryBuilder |
||
| 441 | ->count('uid') |
||
| 442 | ->from('tt_content') |
||
| 443 | ->where( |
||
| 444 | $queryBuilder->expr()->eq( |
||
| 445 | 'pid', |
||
| 446 | $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT) |
||
| 447 | ) |
||
| 448 | ) |
||
| 449 | ->andWhere( |
||
| 450 | $queryBuilder->expr()->eq( |
||
| 451 | 'sys_language_uid', |
||
| 452 | $queryBuilder->createNamedParameter($sysLang, \PDO::PARAM_INT) |
||
| 453 | ) |
||
| 454 | ) |
||
| 455 | ->execute() |
||
| 456 | ->fetchColumn(0); |
||
| 457 | return $count ?: '-'; |
||
| 458 | } |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Returns LanguageService |
||
| 462 | * |
||
| 463 | * @return \TYPO3\CMS\Core\Localization\LanguageService |
||
| 464 | */ |
||
| 465 | protected function getLanguageService() |
||
| 468 | } |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Returns the current BE user. |
||
| 472 | * |
||
| 473 | * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
||
| 474 | */ |
||
| 475 | protected function getBackendUser() |
||
| 480 |