1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ApacheSolrForTypo3\Solr\System\Language; |
4
|
|
|
|
5
|
|
|
/*************************************************************** |
6
|
|
|
* Copyright notice |
7
|
|
|
* |
8
|
|
|
* (c) 2018 Timo Hund <[email protected]> |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
use ApacheSolrForTypo3\Solr\System\TCA\TCAService; |
29
|
|
|
use ApacheSolrForTypo3\Solr\Util; |
30
|
|
|
use Doctrine\DBAL\Driver\Statement; |
31
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
32
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
33
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Class FrontendOverlayService |
37
|
|
|
* @package ApacheSolrForTypo3\Solr\System\Language |
38
|
|
|
*/ |
39
|
|
|
class FrontendOverlayService { |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var TCAService |
43
|
|
|
*/ |
44
|
|
|
protected $tcaService = null; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var TypoScriptFrontendController |
48
|
|
|
*/ |
49
|
|
|
protected $tsfe = null; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Relation constructor. |
53
|
|
|
* @param TCAService|null $tcaService |
54
|
|
|
* @param TypoScriptFrontendController|null $tsfe |
55
|
|
|
*/ |
56
|
47 |
|
public function __construct(TCAService $tcaService = null, TypoScriptFrontendController $tsfe = null) |
57
|
|
|
{ |
58
|
47 |
|
$this->tcaService = $tcaService ?? GeneralUtility::makeInstance(TCAService::class); |
59
|
47 |
|
$this->tsfe = $tsfe ?? $GLOBALS['TSFE']; |
60
|
47 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Return the translated record |
64
|
|
|
* |
65
|
|
|
* @param string $tableName |
66
|
|
|
* @param array $record |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
5 |
|
public function getOverlay($tableName, $record) |
70
|
|
|
{ |
71
|
5 |
|
if ($tableName === 'pages') { |
72
|
2 |
|
return $this->tsfe->sys_page->getPageOverlay($record, $this->tsfe->sys_language_uid); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
4 |
|
return $this->tsfe->sys_page->getRecordOverlay($tableName, $record, $this->tsfe->sys_language_uid); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* When the record has an overlay we retrieve the uid of the translated record, |
80
|
|
|
* to resolve the relations from the translation. |
81
|
|
|
* |
82
|
|
|
* @param string $table |
83
|
|
|
* @param string $field |
84
|
|
|
* @param int $uid |
85
|
47 |
|
* @return int |
86
|
|
|
*/ |
87
|
|
|
public function getUidOfOverlay($table, $field, $uid) |
|
|
|
|
88
|
47 |
|
{ |
89
|
47 |
|
// when no language is set at all we do not need to overlay |
90
|
47 |
|
if (!isset($this->tsfe->sys_language_uid)) { |
|
|
|
|
91
|
47 |
|
return $uid; |
92
|
1 |
|
} |
93
|
|
|
// when no language is set we can return the passed recordUid |
94
|
|
|
if (!$this->tsfe->sys_language_uid > 0) { |
95
|
47 |
|
return $uid; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$record = $this->getRecord($table, $uid); |
99
|
|
|
|
100
|
|
|
// when the overlay is not an array, we return the localRecordUid |
101
|
|
|
if (!is_array($record)) { |
102
|
|
|
return $uid; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$overlayUid = $this->getLocalRecordUidFromOverlay($table, $record); |
106
|
|
|
$uid = ($overlayUid !== 0) ? $overlayUid : $uid; |
107
|
47 |
|
return $uid; |
108
|
|
|
} |
109
|
|
|
|
110
|
47 |
|
/** |
111
|
|
|
* This method retrieves the _PAGES_OVERLAY_UID or _LOCALIZED_UID from the localized record. |
112
|
|
|
* |
113
|
|
|
* @param string $localTableName |
114
|
47 |
|
* @param array $originalRecord |
115
|
45 |
|
* @return int |
116
|
|
|
*/ |
117
|
|
|
protected function getLocalRecordUidFromOverlay($localTableName, $originalRecord) |
118
|
|
|
{ |
119
|
5 |
|
$overlayRecord = $this->getOverlay($localTableName, $originalRecord); |
120
|
5 |
|
|
121
|
5 |
|
// when there is a _PAGES_OVERLAY_UID | _LOCALIZED_UID in the overlay, we return it |
122
|
2 |
|
if ($localTableName === 'pages' && isset($overlayRecord['_PAGES_OVERLAY_UID'])) { |
123
|
|
|
return (int)$overlayRecord['_PAGES_OVERLAY_UID']; |
124
|
|
|
} elseif (isset($overlayRecord['_LOCALIZED_UID'])) { |
125
|
3 |
|
return (int)$overlayRecord['_LOCALIZED_UID']; |
126
|
|
|
} |
127
|
|
|
|
128
|
3 |
|
return 0; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
3 |
|
* @param $localTableName |
133
|
3 |
|
* @param $localRecordUid |
134
|
3 |
|
* @return mixed |
135
|
|
|
*/ |
136
|
|
|
protected function getRecord($localTableName, $localRecordUid) |
137
|
|
|
{ |
138
|
|
|
/** @var QueryBuilder $queryBuilder */ |
139
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($localTableName); |
140
|
|
|
|
141
|
|
|
$record = $queryBuilder->select('*')->from($localTableName)->where($queryBuilder->expr()->eq('uid', $localRecordUid))->execute()->fetch(); |
142
|
|
|
return $record; |
143
|
|
|
} |
144
|
|
|
} |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.