| Conditions | 13 |
| Paths | 45 |
| Total Lines | 87 |
| Code Lines | 64 |
| 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 |
||
| 116 | public function translationInfo($table, $uid, $languageUid = 0, array $row = null, $selFieldList = '') |
||
| 117 | { |
||
| 118 | if (!$GLOBALS['TCA'][$table] || !$uid) { |
||
| 119 | return 'No table "' . $table . '" or no UID value'; |
||
| 120 | } |
||
| 121 | if ($row === null) { |
||
| 122 | $row = BackendUtility::getRecordWSOL($table, $uid); |
||
| 123 | } |
||
| 124 | if (!is_array($row)) { |
||
|
|
|||
| 125 | return 'Record "' . $table . '_' . $uid . '" was not found'; |
||
| 126 | } |
||
| 127 | if (!BackendUtility::isTableLocalizable($table)) { |
||
| 128 | return 'Translation is not supported for this table!'; |
||
| 129 | } |
||
| 130 | if ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) { |
||
| 131 | return 'Record "' . $table . '_' . $uid . '" seems to be a translation already (has a language value "' . $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] . '", relation to record "' . $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] . '")'; |
||
| 132 | } |
||
| 133 | if ($row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0) { |
||
| 134 | return 'Record "' . $table . '_' . $uid . '" seems to be a translation already (has a relation to record "' . $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] . '")'; |
||
| 135 | } |
||
| 136 | // Look for translations of this record, index by language field value: |
||
| 137 | if (!empty($selFieldList)) { |
||
| 138 | if (is_array($selFieldList)) { |
||
| 139 | $selectFields = $selFieldList; |
||
| 140 | } else { |
||
| 141 | $selectFields = GeneralUtility::trimExplode(',', $selFieldList); |
||
| 142 | } |
||
| 143 | } else { |
||
| 144 | $selectFields = ['uid', $GLOBALS['TCA'][$table]['ctrl']['languageField']]; |
||
| 145 | } |
||
| 146 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); |
||
| 147 | $queryBuilder->getRestrictions() |
||
| 148 | ->removeAll() |
||
| 149 | ->add(GeneralUtility::makeInstance(DeletedRestriction::class)) |
||
| 150 | ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUserAuthentication()->workspace)); |
||
| 151 | $queryBuilder |
||
| 152 | ->select(...$selectFields) |
||
| 153 | ->from($table) |
||
| 154 | ->where( |
||
| 155 | $queryBuilder->expr()->eq( |
||
| 156 | $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'], |
||
| 157 | $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT) |
||
| 158 | ), |
||
| 159 | $queryBuilder->expr()->eq( |
||
| 160 | 'pid', |
||
| 161 | $queryBuilder->createNamedParameter( |
||
| 162 | $row['pid'], |
||
| 163 | \PDO::PARAM_INT |
||
| 164 | ) |
||
| 165 | ) |
||
| 166 | ); |
||
| 167 | if (!$languageUid) { |
||
| 168 | $queryBuilder->andWhere( |
||
| 169 | $queryBuilder->expr()->gt( |
||
| 170 | $GLOBALS['TCA'][$table]['ctrl']['languageField'], |
||
| 171 | $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT) |
||
| 172 | ) |
||
| 173 | ); |
||
| 174 | } else { |
||
| 175 | $queryBuilder |
||
| 176 | ->andWhere( |
||
| 177 | $queryBuilder->expr()->eq( |
||
| 178 | $GLOBALS['TCA'][$table]['ctrl']['languageField'], |
||
| 179 | $queryBuilder->createNamedParameter($languageUid, \PDO::PARAM_INT) |
||
| 180 | ) |
||
| 181 | ); |
||
| 182 | } |
||
| 183 | $translationRecords = $queryBuilder |
||
| 184 | ->execute() |
||
| 185 | ->fetchAll(); |
||
| 186 | |||
| 187 | $translations = []; |
||
| 188 | $translationsErrors = []; |
||
| 189 | foreach ($translationRecords as $translationRecord) { |
||
| 190 | if (!isset($translations[$translationRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']]])) { |
||
| 191 | $translations[$translationRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']]] = $translationRecord; |
||
| 192 | } else { |
||
| 193 | $translationsErrors[$translationRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']]][] = $translationRecord; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | return [ |
||
| 197 | 'table' => $table, |
||
| 198 | 'uid' => $uid, |
||
| 199 | 'CType' => $row['CType'] ?? '', |
||
| 200 | 'sys_language_uid' => $row[$GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? null] ?? null, |
||
| 201 | 'translations' => $translations, |
||
| 202 | 'excessive_translations' => $translationsErrors |
||
| 203 | ]; |
||
| 211 |