Completed
Push — 7LTS_compatible ( b51d35...40d99a )
by Tomas Norre
32:08
created

getOverLayRecordForCertainLanguageImplementation()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 3
eloc 3
nc 2
nop 2
1
<?php
2
3
namespace AOE\Languagevisibility;
4
5
/***************************************************************
6
 * Copyright notice
7
 *
8
 * (c) 2007 AOE media ([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
 *
30
 * @author	Daniel Poetzinger <[email protected]>
31
 * @coauthor Tolleiv Nietsch <[email protected]>
32
 * @coauthor Timo Schmidt <[email protected]>
33
 */
34
class FceElement extends RecordElement {
35
36
	private $langIsoCodeForFlexFormCallback = '';
37
	private $langChildren;
38
	private $langDisabled;
39
	private $langDatabaseOverlay;
40
	private $disabledIsVisible;
41
42
		// flags which are set during processings
43
	private $_callBackFoundOverlay = FALSE;
44
45
	public function __construct($row, $DS) {
46
		parent::__construct($row);
47
48
		$this->langChildren = $DS['meta']['langChildren'] ? 1 : 0;
49
		$this->langDisabled = $DS['meta']['langDisable'] ? 1 : 0;
50
		$this->langDatabaseOverlay = $DS['meta']['langDatabaseOverlay'] ? 1 : 0;
51
		$this->disabledIsVisible = $DS['meta']['disabledIsVisible'] ? 1 : 0;
52
	}
53
54
	public function getElementDescription() {
55
		return 'FCE';
56
	}
57
58
	public function getInformativeDescription() {
59
		if ($this->isLanguageSetToAll()) {
60
			return 'Language is set to all. Visible in every language';
61
		}
62
		if ($this->langDisabled == 1) {
63
			if ($this->disabledIsVisible == 1) {
64
				return 'FCE is in mode langDisabled, therefore cannot be translated. But it is configured to be handled as translated per Default.';
65
			} else {
66
				return 'FCE is in mode langDisabled, therefore cannot be translated.';
67
			}
68
		}
69
		if ($this->langChildren == 1) {
70
			return 'FCE is in mode inheritance';
71
		} else {
72
			return 'FCE is in mode seperate';
73
		}
74
	}
75
76
	public function _hasOverlayRecordForLanguage($id) {
77
		$languageRep = Languagerepository::makeInstance();
78
		$language = $languageRep->getLanguageById($id);
79
		$this->langIsoCodeForFlexFormCallback = strtoupper($language->getIsoCode());
80
		$this->_callBackFoundOverlay = FALSE;
81
82
			// Get data structure:
83
		if ($this->langDisabled == 1 && !$this->langDatabaseOverlay) {
84
				// the FCE has langDisabled: this means there is no overlay
85
			if ($this->disabledIsVisible == 1) {
86
				return TRUE;
87
			} else {
88
				return FALSE;
89
			}
90
		}
91
92
		if ($GLOBALS['TSFE']) {
93
			@$GLOBALS['TSFE']->includeTCA();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
94
		}
95
96
		if ($this->langChildren == 1) {
97
				// the FCE has real overlay record
98
			$flexObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools');
99
			if ($this->row['tx_templavoila_flex']) {
100
				$return = $flexObj->traverseFlexFormXMLData('tt_content', 'tx_templavoila_flex', $this->row, $this, '_hasOverlayRecordForLanguage_Inheritance_flexFormCallBack');
101
				if ($return !== TRUE && strlen($return) > 0) {
102
					debug('FCE: _hasOverlayRecordForLanguage has error:' . $return);
103
				}
104
				return $this->_callBackFoundOverlay;
105
			} else {
106
					// in case no xml yet (new created?)
107
				return FALSE;
108
			}
109
		} else {
110
				//	the FCE has no real overlay record
111
			$flexObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools');
112
			$flexObj->traverseFlexFormXMLData('tt_content', 'tx_templavoila_flex', $this->row, $this, '_hasOverlayRecordForLanguage_Seperate_flexFormCallBack');
113
			return $this->_callBackFoundOverlay;
114
		}
115
	}
116
117
	public function getOverLayRecordForCertainLanguageImplementation($languageId, $onlyUid = FALSE) {
118
		$useDefaultLang = $this->langDisabled == 1 && !$this->langDatabaseOverlay;
119
		return parent::getOverLayRecordForCertainLanguageImplementation($useDefaultLang ? 0 : $languageId, $onlyUid);
0 ignored issues
show
Unused Code introduced by
The call to Recordelement::getOverLa...anguageImplementation() has too many arguments starting with $onlyUid.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
120
	}
121
122
	/**
123
	 * FlexForm call back function, see _hasOverlayRecordForLanguage
124
	 *
125
	 * @param	array		Data Structure of current field
126
	 * @param	string		Data value of current field
127
	 * @param	array		Various stuff in an array
128
	 * @param	string		path to location in flexform for current field
129
	 * @param	object		Reference to parent object
130
	 * @return	void
131
	 */
132
	public function _hasOverlayRecordForLanguage_Inheritance_flexFormCallBack($dsArr, $dataValue, $PA, $structurePath, &$pObj) {
0 ignored issues
show
Unused Code introduced by
The parameter $dataValue is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $PA is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
133
		if ($this->langIsoCodeForFlexFormCallback == '') {
134
			return FALSE;
135
		}
136
137
			// Only take lead from default values (since this is "Inheritance" localization we parse for)
138
		if (substr($structurePath, -5) == '/vDEF') {
139
			$baseStructPath = substr($structurePath, 0, -3);
140
			$structurePath = $baseStructPath . $this->langIsoCodeForFlexFormCallback;
141
			$translValue = $pObj->getArrayValueByPath($structurePath, $pObj->traverseFlexFormXMLData_Data);
142
			if ($this->_isFlexFieldFilled($dsArr['TCEforms']['config'], $translValue)) {
143
				$this->_callBackFoundOverlay = TRUE;
144
			}
145
		}
146
	}
147
148
	protected function _isFlexFieldFilled($cfg, $translValue) {
149
		if (($cfg['type'] == 'check' && $translValue != 0) || ($cfg['type'] != 'check' && $translValue != '')) {
150
			return TRUE;
151
		} else {
152
			return FALSE;
153
		}
154
155
	}
156
157
	/**
158
	 * FlexForm call back function, see _hasOverlayRecordForLanguage
159
	 *
160
	 * @param	array		Data Structure of current field
161
	 * @param	string		Data value of current field
162
	 * @param	array		Various stuff in an array
163
	 * @param	string		path to location in flexform for current field
164
	 * @param	object		Reference to parent object
165
	 * @return	void
166
	 */
167
	public function _hasOverlayRecordForLanguage_Seperate_flexFormCallBack($dsArr, $dataValue, $PA, $structurePath, &$pObj) {
0 ignored issues
show
Unused Code introduced by
The parameter $dataValue is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $PA is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
168
		if ($this->langIsoCodeForFlexFormCallback == '') {
169
			return FALSE;
170
		}
171
			//path like: data/sDEF/lDEF/field_links/el/1/field_link/el/field_link_text/vDEF
172
		if (strpos($structurePath, '/lDEF/')) {
173
			$structurePath = str_replace('/lDEF/', '/l' . $this->langIsoCodeForFlexFormCallback . '/', $structurePath);
174
			$translValue = $pObj->getArrayValueByPath($structurePath, $pObj->traverseFlexFormXMLData_Data);
175
			if ($this->_isFlexFieldFilled($dsArr['TCEforms']['config'], $translValue)) {
176
				$this->_callBackFoundOverlay = TRUE;
177
			}
178
179
		}
180
	}
181
182
	public function hasOverLayRecordForAnyLanguageInAnyWorkspace() {
183
	}
184
}
185