TYPO3 CMS  TYPO3_7-6
LocalizationRepository.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
23 {
32  public function fetchOriginLanguage($pageId, $colPos, $localizedLanguage)
33  {
34  $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
35  'tt_content_orig.sys_language_uid',
36  'tt_content,tt_content AS tt_content_orig,sys_language',
37  'tt_content.colPos = ' . (int)$colPos
38  . ' AND tt_content.pid = ' . (int)$pageId
39  . ' AND tt_content.sys_language_uid = ' . (int)$localizedLanguage
40  . ' AND tt_content.t3_origuid = tt_content_orig.uid'
41  // workaround, as t3_origuid might point to the source the translation was copied from, the language is identical then
42  . ' AND tt_content_orig.sys_language_uid <> tt_content.sys_language_uid'
43  . ' AND tt_content_orig.sys_language_uid = sys_language.uid'
44  . $this->getExcludeQueryPart()
46  'tt_content_orig.sys_language_uid'
47  );
48  if (empty($record)) {
49  return ['sys_language_uid' => 0];
50  }
51 
52  return $record;
53  }
54 
61  public function getLocalizedRecordCount($pageId, $colPos, $languageId)
62  {
63  // records in default language are never translated
64  if (!$languageId) {
65  return 0;
66  }
67  $rows = (int)$this->getDatabaseConnection()->exec_SELECTcountRows(
68  'uid',
69  'tt_content',
70  'tt_content.sys_language_uid=' . (int)$languageId
71  . ' AND tt_content.colPos = ' . (int)$colPos
72  . ' AND tt_content.pid=' . (int)$pageId
73  . ' AND tt_content.t3_origuid <> 0'
74  . $this->getExcludeQueryPart()
75  );
76 
77  return $rows;
78  }
79 
88  public function fetchAvailableLanguages($pageId, $colPos, $languageId)
89  {
90  $result = $this->getDatabaseConnection()->exec_SELECTgetRows(
91  'sys_language.uid',
92  'tt_content,sys_language',
93  'tt_content.sys_language_uid=sys_language.uid'
94  . ' AND tt_content.colPos = ' . (int)$colPos
95  . ' AND tt_content.pid = ' . (int)$pageId
96  . ' AND sys_language.uid <> ' . (int)$languageId
97  . $this->getExcludeQueryPart()
99  'sys_language.uid',
100  'sys_language.title'
101  );
102 
103  return $result;
104  }
105 
111  public function getExcludeQueryPart()
112  {
113  return BackendUtility::deleteClause('tt_content')
115  }
116 
124  {
125  $backendUser = $this->getBackendUser();
126  $additionalWhere = '';
127  if (!$backendUser->isAdmin()) {
128  $additionalWhere .= ' AND sys_language.hidden=0';
129 
130  if (!empty($backendUser->user['allowed_languages'])) {
131  $additionalWhere .= ' AND sys_language.uid IN(' . $this->getDatabaseConnection()->cleanIntList($backendUser->user['allowed_languages']) . ')';
132  }
133  }
134 
135  return $additionalWhere;
136  }
137 
148  public function getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, $fields = '*')
149  {
150  $db = $this->getDatabaseConnection();
151 
152  // Get original uid of existing elements triggered language / colpos
153  $originalUids = $db->exec_SELECTgetRows(
154  'tt_content.t3_origuid',
155  'tt_content,tt_content as orig',
156  'tt_content.sys_language_uid = ' . (int)$destLanguageId
157  . ' AND tt_content.colPos = ' . (int)$colPos
158  . ' AND tt_content.pid = ' . (int)$pageId
159  . ' AND orig.uid = tt_content.t3_origuid'
160  . ' AND orig.pid = ' . (int)$pageId
161  . $this->getExcludeQueryPart(),
162  '',
163  '',
164  '',
165  't3_origuid'
166  );
167  $originalUidList = $db->cleanIntList(implode(',', array_keys($originalUids)));
168 
169  $res = $db->exec_SELECTquery(
170  $fields,
171  'tt_content',
172  'tt_content.sys_language_uid=' . (int)$languageId
173  . ' AND tt_content.colPos = ' . (int)$colPos
174  . ' AND tt_content.pid=' . (int)$pageId
175  . ' AND tt_content.uid NOT IN (' . $originalUidList . ')'
176  . $this->getExcludeQueryPart(),
177  '',
178  'tt_content.sorting'
179  );
180 
181  return $res;
182  }
183 
196  public function getRecordLocalization($table, $uid, $language, $andWhereClause = '')
197  {
198  $recordLocalization = false;
199 
200  // Check if translations are stored in other table
201  if (isset($GLOBALS['TCA'][$table]['ctrl']['transForeignTable'])) {
202  $table = $GLOBALS['TCA'][$table]['ctrl']['transForeignTable'];
203  }
204 
206  $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
207 
208  if (isset($tcaCtrl['origUid'])) {
209  $recordLocalization = BackendUtility::getRecordsByField(
210  $table,
211  $tcaCtrl['origUid'],
212  $uid,
213  'AND ' . $tcaCtrl['languageField'] . '=' . (int)$language . ($andWhereClause ? ' ' . $andWhereClause : ''),
214  '',
215  '',
216  '1'
217  );
218  }
219  }
220  return $recordLocalization;
221  }
222 
239  public function getPreviousLocalizedRecordUid($table, $uid, $pid, $sourceLanguage, $destinationLanguage)
240  {
241  $previousLocalizedRecordUid = $uid;
242  if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['sortby']) {
243  $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
244  $select = $sortRow . ',pid,uid';
245  // For content elements, we also need the colPos
246  if ($table === 'tt_content') {
247  $select .= ',colPos';
248  }
249  // Get the sort value of the default language record
250  $row = BackendUtility::getRecord($table, $uid, $select);
251  if (is_array($row)) {
252  // Find the previous record in default language on the same page
253  $where = 'pid=' . (int)$pid . ' AND ' . 'sys_language_uid=' . (int)$sourceLanguage . ' AND ' . $sortRow . '<' . (int)$row[$sortRow];
254  // Respect the colPos for content elements
255  if ($table === 'tt_content') {
256  $where .= ' AND colPos=' . (int)$row['colPos'];
257  }
258  $res = $this->getDatabaseConnection()->exec_SELECTquery(
259  $select,
260  $table,
261  $where . BackendUtility::deleteClause($table),
262  '',
263  $sortRow . ' DESC',
264  '1'
265  );
266  // If there is an element, find its localized record in specified localization language
267  if ($previousRow = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
268  $previousLocalizedRecord = $this->getRecordLocalization($table, $previousRow['uid'], $destinationLanguage);
269  if (is_array($previousLocalizedRecord[0])) {
270  $previousLocalizedRecordUid = $previousLocalizedRecord[0]['uid'];
271  }
272  }
273  $this->getDatabaseConnection()->sql_free_result($res);
274  }
275  }
276  return $previousLocalizedRecordUid;
277  }
278 
284  protected function getBackendUser()
285  {
286  return $GLOBALS['BE_USER'];
287  }
288 
294  protected function getDatabaseConnection()
295  {
296  return $GLOBALS['TYPO3_DB'];
297  }
298 }
static getRecordsByField($theTable, $theField, $theValue, $whereClause='', $groupBy='', $orderBy='', $limit='', $useDeleteClause=true)
getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, $fields=' *')
getPreviousLocalizedRecordUid($table, $uid, $pid, $sourceLanguage, $destinationLanguage)
$uid
Definition: server.php:38
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static deleteClause($table, $tableAlias='')