Completed
Push — 7LTS_compatible ( 930bf9...a06bdb )
by Tomas Norre
09:47
created

RecordElement::getElementDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace AOE\Languagevisibility;
4
5
/***************************************************************
6
 * Copyright notice
7
 *
8
 * (c) 2016 AOE GmbH <[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 2 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
/**
29
 * Class Recordelement
30
 * @package AOE\Languagevisibility
31
 */
32
class RecordElement extends Element {
33
34
	/**
35
	 * Returns a formal description of the record element.
36
	 *
37
	 * (non-PHPdoc)
38
	 * @see classes/tx_languagevisibility_element#getElementDescription()
39
	 * @return string
40
	 */
41
	public function getElementDescription() {
42
		return 'TYPO3-Record';
43
	}
44
45
	/**
46
	 * This method is the implementation of an abstract parent method.
47
	 * The method should return the overlay record for a certain language.
48
	 *
49
	 * (non-PHPdoc)
50
	 * @see classes/tx_languagevisibility_element#getOverLayRecordForCertainLanguageImplementation($languageId)
51
	 */
52
	protected function getOverLayRecordForCertainLanguageImplementation($languageId) {
53
		if (empty($this->table)) {
54
			return array();
55
		}
56
57
		$ctrl = $GLOBALS['TCA'][$this->table]['ctrl'];
58
59
			// we can't use the exclude fields here because we might loose (hidden) parent-records
60
		if (is_object($GLOBALS['TSFE']->sys_page)) {
61
			$excludeClause = $GLOBALS['TSFE']->sys_page->deleteClause($this->table);
62
		} else {
63
			$excludeClause = \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($this->table);
64
		}
65
66
67
		if (isset($ctrl['versioningWS']) && $ctrl['versioningWS'] > 0) {
68
			$workspaces = '0,' . $GLOBALS['BE_USER']->workspace;
69
			$workspaceCondition = 't3ver_wsid IN (' . rtrim($workspaces, ',') . ') AND ';
70
		} else {
71
			$workspaceCondition = '';
72
		}
73
74
			// Select overlay record (Live workspace, initial placeholders included):
75
		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
76
			'*',
77
			$this->table,
78
				// from the current pid and only records from the live workspace or initial placeholder
79
			'pid=' . intval($this->getPid()) . ' AND ' .
80
				$workspaceCondition .
81
				$ctrl['languageField'] . '=' . intval($languageId) .
82
					// With L=0 transOrigPointerField is not set, so uid should be used instead (see #31607)
83
				($languageId > 0 ? ' AND ' . $ctrl['transOrigPointerField'] . '=' . intval($this->getUid()) : ' AND uid=' . intval($this->getUid())) .
84
				$excludeClause,
85
			'',
86
			'',
87
			'1'
88
		);
89
90
		$olrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
91
		$olrow = $this->getContextIndependentWorkspaceOverlay($this->table, $olrow);
92
		$GLOBALS['TYPO3_DB']->sql_free_result($res);
93
94
		if (!$this->getEnableFieldResult($olrow)) {
95
			$olrow = array();
96
		}
97
98
		return $olrow;
99
	}
100
101
	/**
102
	 * This method is used to check if this element has any translation in any workspace.
103
	 *
104
	 * @return boolean
105
	 */
106
	public function hasOverLayRecordForAnyLanguageInAnyWorkspace() {
107
		$table = $this->table;
108
109
		if ($this->isOrigElement()) {
110
			$fields = 'count(*) as ANZ';
111
112
			$where = 'deleted = 0 AND ' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . '=' . $this->getUid();
113
			$res = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fields, $table, $where);
114
115
			return ($res[0]['ANZ'] > 0);
116
		} else {
117
				// if this is a translation is clear that an overlay must exist
118
			return TRUE;
119
		}
120
	}
121
122
	/**
123
	 * Returns the fallback order of an record element.
124
	 *
125
	 * (non-PHPdoc)
126
	 * @see classes/tx_languagevisibility_element#getFallbackOrder($language)
127
	 */
128
	public function getFallbackOrder(Language $language) {
129
		return $language->getFallbackOrderElement($this);
130
	}
131
}
132