@@ -1,5 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if (!defined('TYPO3')) die ('Access denied.'); |
|
2 | +if (!defined('TYPO3')) { |
|
3 | + die ('Access denied.'); |
|
4 | +} |
|
3 | 5 | |
4 | 6 | return [ |
5 | 7 | 'ctrl' => [ |
@@ -2,88 +2,88 @@ |
||
2 | 2 | if (!defined('TYPO3')) die ('Access denied.'); |
3 | 3 | |
4 | 4 | return [ |
5 | - 'ctrl' => [ |
|
6 | - 'title' => 'LLL:EXT:phpdisplay/Resources/Private/Language/locallang_db.xml:tx_phpdisplay_displays', |
|
7 | - 'label' => 'name', |
|
8 | - 'tstamp' => 'tstamp', |
|
9 | - 'crdate' => 'crdate', |
|
10 | - 'cruser_id' => 'cruser_id', |
|
11 | - 'hideTable' => true, |
|
12 | - 'delete' => 'deleted', |
|
13 | - 'enablecolumns' => [ |
|
14 | - 'disabled' => 'hidden', |
|
15 | - ], |
|
16 | - 'searchFields' => 'type,name,data_type', |
|
17 | - 'typeicon_classes' => [ |
|
18 | - 'default' => 'extensions-vidi-selection', |
|
19 | - ], |
|
20 | - ], |
|
21 | - 'types' => [ |
|
22 | - '1' => ['showitem' => 'hidden,--palette--;;1,type,name,data_type,query'], |
|
23 | - ], |
|
24 | - 'palettes' => [ |
|
25 | - '1' => ['showitem' => ''], |
|
26 | - ], |
|
27 | - 'columns' => [ |
|
5 | + 'ctrl' => [ |
|
6 | + 'title' => 'LLL:EXT:phpdisplay/Resources/Private/Language/locallang_db.xml:tx_phpdisplay_displays', |
|
7 | + 'label' => 'name', |
|
8 | + 'tstamp' => 'tstamp', |
|
9 | + 'crdate' => 'crdate', |
|
10 | + 'cruser_id' => 'cruser_id', |
|
11 | + 'hideTable' => true, |
|
12 | + 'delete' => 'deleted', |
|
13 | + 'enablecolumns' => [ |
|
14 | + 'disabled' => 'hidden', |
|
15 | + ], |
|
16 | + 'searchFields' => 'type,name,data_type', |
|
17 | + 'typeicon_classes' => [ |
|
18 | + 'default' => 'extensions-vidi-selection', |
|
19 | + ], |
|
20 | + ], |
|
21 | + 'types' => [ |
|
22 | + '1' => ['showitem' => 'hidden,--palette--;;1,type,name,data_type,query'], |
|
23 | + ], |
|
24 | + 'palettes' => [ |
|
25 | + '1' => ['showitem' => ''], |
|
26 | + ], |
|
27 | + 'columns' => [ |
|
28 | 28 | |
29 | - 'hidden' => [ |
|
30 | - 'exclude' => 1, |
|
31 | - 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.hidden', |
|
32 | - 'config' => [ |
|
33 | - 'type' => 'check', |
|
34 | - ], |
|
35 | - ], |
|
36 | - 'visibility' => [ |
|
37 | - 'exclude' => 0, |
|
38 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:visibility', |
|
39 | - 'config' => [ |
|
40 | - 'type' => 'select', |
|
41 | - 'renderType' => 'selectSingle', |
|
42 | - 'items' => [ |
|
43 | - ['LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:visibility.everyone', 0], |
|
44 | - ['LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:visibility.private', 1], |
|
45 | - ['LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:visibility.admin_only', 2], |
|
46 | - ], |
|
47 | - 'size' => 1, |
|
48 | - 'maxitems' => 1, |
|
49 | - 'minitems' => 1, |
|
50 | - ], |
|
51 | - ], |
|
52 | - 'name' => [ |
|
53 | - 'exclude' => 0, |
|
54 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:name', |
|
55 | - 'config' => [ |
|
56 | - 'type' => 'input', |
|
57 | - 'size' => 30, |
|
58 | - 'eval' => 'trim,required' |
|
59 | - ], |
|
60 | - ], |
|
61 | - 'data_type' => [ |
|
62 | - 'exclude' => 0, |
|
63 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:data_type', |
|
64 | - 'config' => [ |
|
65 | - 'type' => 'input', |
|
66 | - 'size' => 30, |
|
67 | - 'eval' => 'trim,required' |
|
68 | - ], |
|
69 | - ], |
|
70 | - 'query' => [ |
|
71 | - 'exclude' => 0, |
|
72 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:query', |
|
73 | - 'config' => [ |
|
74 | - 'type' => 'text', |
|
75 | - 'rows' => 5, |
|
76 | - 'cols' => 5, |
|
77 | - ], |
|
78 | - ], |
|
79 | - 'speaking_query' => [ |
|
80 | - 'exclude' => 0, |
|
81 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:speaking_query', |
|
82 | - 'config' => [ |
|
83 | - 'type' => 'text', |
|
84 | - 'rows' => 5, |
|
85 | - 'cols' => 5, |
|
86 | - ], |
|
87 | - ], |
|
88 | - ], |
|
29 | + 'hidden' => [ |
|
30 | + 'exclude' => 1, |
|
31 | + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.hidden', |
|
32 | + 'config' => [ |
|
33 | + 'type' => 'check', |
|
34 | + ], |
|
35 | + ], |
|
36 | + 'visibility' => [ |
|
37 | + 'exclude' => 0, |
|
38 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:visibility', |
|
39 | + 'config' => [ |
|
40 | + 'type' => 'select', |
|
41 | + 'renderType' => 'selectSingle', |
|
42 | + 'items' => [ |
|
43 | + ['LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:visibility.everyone', 0], |
|
44 | + ['LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:visibility.private', 1], |
|
45 | + ['LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:visibility.admin_only', 2], |
|
46 | + ], |
|
47 | + 'size' => 1, |
|
48 | + 'maxitems' => 1, |
|
49 | + 'minitems' => 1, |
|
50 | + ], |
|
51 | + ], |
|
52 | + 'name' => [ |
|
53 | + 'exclude' => 0, |
|
54 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:name', |
|
55 | + 'config' => [ |
|
56 | + 'type' => 'input', |
|
57 | + 'size' => 30, |
|
58 | + 'eval' => 'trim,required' |
|
59 | + ], |
|
60 | + ], |
|
61 | + 'data_type' => [ |
|
62 | + 'exclude' => 0, |
|
63 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:data_type', |
|
64 | + 'config' => [ |
|
65 | + 'type' => 'input', |
|
66 | + 'size' => 30, |
|
67 | + 'eval' => 'trim,required' |
|
68 | + ], |
|
69 | + ], |
|
70 | + 'query' => [ |
|
71 | + 'exclude' => 0, |
|
72 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:query', |
|
73 | + 'config' => [ |
|
74 | + 'type' => 'text', |
|
75 | + 'rows' => 5, |
|
76 | + 'cols' => 5, |
|
77 | + ], |
|
78 | + ], |
|
79 | + 'speaking_query' => [ |
|
80 | + 'exclude' => 0, |
|
81 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tx_vidi_selection.xlf:speaking_query', |
|
82 | + 'config' => [ |
|
83 | + 'type' => 'text', |
|
84 | + 'rows' => 5, |
|
85 | + 'cols' => 5, |
|
86 | + ], |
|
87 | + ], |
|
88 | + ], |
|
89 | 89 | ]; |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | { |
97 | 97 | $value = null; |
98 | 98 | if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) { |
99 | - $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1); |
|
99 | + $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)).substr(substr($methodName, 3), 1); |
|
100 | 100 | |
101 | 101 | $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
102 | 102 | $field = Tca::table($this->dataType)->field($fieldName); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) { |
119 | - $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1); |
|
119 | + $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)).substr(substr($methodName, 3), 1); |
|
120 | 120 | $this->$propertyName = $arguments[0]; |
121 | 121 | } |
122 | 122 | return $value; |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | |
175 | 175 | // Fetch values from repository. |
176 | 176 | $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName(); |
177 | - $findByProperty = 'findBy' . ucfirst($foreignPropertyName); |
|
177 | + $findByProperty = 'findBy'.ucfirst($foreignPropertyName); |
|
178 | 178 | |
179 | 179 | // Date picker (type == group) are special fields because property path must contain the table name |
180 | 180 | // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
181 | 181 | $propertyValue = $this->uid; |
182 | 182 | if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) { |
183 | - $propertyValue = $this->dataType . '.' . $this->uid; |
|
183 | + $propertyValue = $this->dataType.'.'.$this->uid; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable(); |
201 | 201 | $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField(); |
202 | 202 | $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType); |
203 | - $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField); |
|
203 | + $find = 'findOneBy'.GeneralUtility::underscoredToUpperCamelCase($foreignField); |
|
204 | 204 | |
205 | 205 | /** @var Content $foreignObject */ |
206 | 206 | $this->$propertyName = $foreignContentRepository->$find($this->getUid()); |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | public function offsetGet($offset) |
254 | 254 | { |
255 | 255 | $offset = Field::name($offset)->of($this)->toPropertyName(); |
256 | - $getter = 'get' . ucfirst($offset); |
|
256 | + $getter = 'get'.ucfirst($offset); |
|
257 | 257 | return $this->$getter(); |
258 | 258 | } |
259 | 259 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | public function offsetSet($offset, $value) |
271 | 271 | { |
272 | 272 | $offset = Field::name($offset)->of($this)->toPropertyName(); |
273 | - $setter = 'set' . ucfirst($offset); |
|
273 | + $setter = 'set'.ucfirst($offset); |
|
274 | 274 | $this->$setter($value); |
275 | 275 | return $this; |
276 | 276 | } |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | */ |
468 | 468 | protected function isBackendMode() |
469 | 469 | { |
470 | - return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend();; |
|
470 | + return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend(); ; |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | } |
@@ -28,450 +28,450 @@ |
||
28 | 28 | class Content implements \ArrayAccess |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - protected $uid; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $dataType; |
|
40 | - |
|
41 | - /** |
|
42 | - * Constructor for a Content object. |
|
43 | - * |
|
44 | - * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ... |
|
45 | - * @param array $contentData |
|
46 | - * @return \Fab\Vidi\Domain\Model\Content |
|
47 | - * @throws \InvalidArgumentException |
|
48 | - * @throws NotExistingClassException |
|
49 | - */ |
|
50 | - public function __construct($dataType, array $contentData = array()) |
|
51 | - { |
|
52 | - |
|
53 | - $this->dataType = $dataType; |
|
54 | - $this->uid = empty($contentData['uid']) ? null : (int)$contentData['uid']; |
|
55 | - |
|
56 | - /** @var TableService $table */ |
|
57 | - $table = Tca::table($dataType); |
|
58 | - |
|
59 | - // Initialize the array containing the allowed fields to be filled-in. |
|
60 | - $fields = array('pid'); |
|
61 | - |
|
62 | - // If a creation time stamp has been defined for this data type. |
|
63 | - if ($table->getTimeCreationField()) { |
|
64 | - $fields[] = $table->getTimeCreationField(); |
|
65 | - } |
|
66 | - |
|
67 | - // If an update time stamp has been defined for this data type. |
|
68 | - if ($table->getTimeModificationField()) { |
|
69 | - $fields[] = $table->getTimeModificationField(); |
|
70 | - } |
|
71 | - |
|
72 | - // Merge the other fields allowed for this data type. |
|
73 | - $fields = array_merge($fields, $table->getFields()); |
|
74 | - |
|
75 | - // Fetch excluded fields from the grid. |
|
76 | - if ($this->isBackendMode()) { |
|
77 | - $fields = $this->filterForConfiguration($fields); |
|
78 | - $fields = $this->filterForBackendUser($fields); |
|
79 | - } |
|
80 | - |
|
81 | - // Get column to be displayed |
|
82 | - foreach ($fields as $fieldName) { |
|
83 | - if (array_key_exists($fieldName, $contentData)) { |
|
84 | - $propertyName = Field::name($fieldName)->of($dataType)->toPropertyName(); |
|
85 | - $this->$propertyName = $contentData[$fieldName]; |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Dispatches magic methods (findBy[Property]()) |
|
92 | - * |
|
93 | - * @param string $methodName The name of the magic method |
|
94 | - * @param string $arguments The arguments of the magic method |
|
95 | - * @throws UnsupportedMethodException |
|
96 | - * @return mixed |
|
97 | - * @api |
|
98 | - */ |
|
99 | - public function __call($methodName, $arguments) |
|
100 | - { |
|
101 | - $value = null; |
|
102 | - if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) { |
|
103 | - $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1); |
|
104 | - |
|
105 | - $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
106 | - $field = Tca::table($this->dataType)->field($fieldName); |
|
107 | - |
|
108 | - $value = $this->$propertyName; |
|
109 | - |
|
110 | - // true means it is a relation and it is not yet resolved. |
|
111 | - if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) { |
|
112 | - $value = $this->resolveRelation($propertyName); |
|
113 | - } elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) { |
|
114 | - |
|
115 | - // Attempt to convert the value into a label for radio and select fields. |
|
116 | - $label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value); |
|
117 | - if ($label) { |
|
118 | - $value = $label; |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) { |
|
123 | - $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1); |
|
124 | - $this->$propertyName = $arguments[0]; |
|
125 | - } |
|
126 | - return $value; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Tell whether the property has a relation. |
|
131 | - * |
|
132 | - * @param string $propertyName |
|
133 | - * @return bool |
|
134 | - */ |
|
135 | - protected function hasRelation($propertyName) |
|
136 | - { |
|
137 | - $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
138 | - return Tca::table($this->dataType)->field($fieldName)->hasRelation(); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Try to "resolve" the property whether it has a relation. |
|
143 | - * If the property has not relation it simply returns the same value. |
|
144 | - * |
|
145 | - * @throws \RuntimeException |
|
146 | - * @param string $propertyName |
|
147 | - * @return mixed |
|
148 | - */ |
|
149 | - protected function resolveRelation($propertyName) |
|
150 | - { |
|
151 | - |
|
152 | - // Convert property name to field name and get the foreign data type. |
|
153 | - $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
154 | - $foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType(); |
|
155 | - |
|
156 | - // Get the foreign repository instance form the factory |
|
157 | - /** @var ContentRepository $foreignContentRepository */ |
|
158 | - $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName); |
|
159 | - |
|
160 | - if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) { |
|
161 | - |
|
162 | - // Fetch values from repository |
|
163 | - $values = GeneralUtility::trimExplode(',', $this->$propertyName); |
|
164 | - $this->$propertyName = $foreignContentRepository->findIn('uid', $values); |
|
165 | - } elseif (Tca::table($this->dataType)->field($fieldName)->hasMany()) { |
|
166 | - // Include relation many-to-many and one-to-many |
|
167 | - // Tca::table($this->dataType)->field($fieldName)->hasRelationOneToMany() |
|
168 | - // Tca::table($this->dataType)->field($fieldName)->hasRelationManyToMany() |
|
169 | - |
|
170 | - $foreignFieldName = Tca::table($this->dataType)->field($fieldName)->getForeignField(); |
|
171 | - if (empty($foreignFieldName)) { |
|
172 | - $message = sprintf('Missing "foreign_field" key for field "%s" in table "%s".', |
|
173 | - $fieldName, |
|
174 | - $this->dataType |
|
175 | - ); |
|
176 | - throw new \RuntimeException($message, 1376149186); |
|
177 | - } |
|
178 | - |
|
179 | - // Fetch values from repository. |
|
180 | - $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName(); |
|
181 | - $findByProperty = 'findBy' . ucfirst($foreignPropertyName); |
|
182 | - |
|
183 | - // Date picker (type == group) are special fields because property path must contain the table name |
|
184 | - // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
|
185 | - $propertyValue = $this->uid; |
|
186 | - if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) { |
|
187 | - $propertyValue = $this->dataType . '.' . $this->uid; |
|
188 | - } |
|
189 | - |
|
190 | - $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue); |
|
191 | - |
|
192 | - } elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) { |
|
193 | - |
|
194 | - $fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration(); |
|
195 | - |
|
196 | - // First case, we are on the "good side" of the relation, just query the repository |
|
197 | - if (empty($fieldConfiguration['foreign_field'])) { |
|
198 | - $this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName); |
|
199 | - } else { |
|
200 | - // Second case, we are the "bad side" of the relation, query the foreign repository |
|
201 | - // e.g. in case of one-to-one relation. |
|
202 | - |
|
203 | - // We must query the opposite side to get the identifier of the foreign object. |
|
204 | - $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable(); |
|
205 | - $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField(); |
|
206 | - $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType); |
|
207 | - $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField); |
|
208 | - |
|
209 | - /** @var Content $foreignObject */ |
|
210 | - $this->$propertyName = $foreignContentRepository->$find($this->getUid()); |
|
211 | - } |
|
212 | - |
|
213 | - } |
|
214 | - return $this->$propertyName; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @return int |
|
219 | - */ |
|
220 | - public function getUid() |
|
221 | - { |
|
222 | - return $this->uid; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public function getDataType() |
|
229 | - { |
|
230 | - return $this->dataType; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Whether a offset exists |
|
235 | - * |
|
236 | - * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
|
237 | - * @param mixed $offset |
|
238 | - * @return boolean true on success or false on failure. |
|
239 | - * @throws \RuntimeException |
|
240 | - * @throws \InvalidArgumentException |
|
241 | - */ |
|
242 | - public function offsetExists($offset) |
|
243 | - { |
|
244 | - $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
245 | - return isset($this->$offset); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Offset to retrieve |
|
250 | - * |
|
251 | - * @link http://php.net/manual/en/arrayaccess.offsetget.php |
|
252 | - * @param mixed $offset |
|
253 | - * @return mixed Can return all value types. |
|
254 | - * @throws \RuntimeException |
|
255 | - * @throws \InvalidArgumentException |
|
256 | - */ |
|
257 | - public function offsetGet($offset) |
|
258 | - { |
|
259 | - $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
260 | - $getter = 'get' . ucfirst($offset); |
|
261 | - return $this->$getter(); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Offset to set |
|
266 | - * |
|
267 | - * @link http://php.net/manual/en/arrayaccess.offsetset.php |
|
268 | - * @param mixed $offset |
|
269 | - * @param mixed $value |
|
270 | - * @return $this |
|
271 | - * @throws \RuntimeException |
|
272 | - * @throws \InvalidArgumentException |
|
273 | - */ |
|
274 | - public function offsetSet($offset, $value) |
|
275 | - { |
|
276 | - $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
277 | - $setter = 'set' . ucfirst($offset); |
|
278 | - $this->$setter($value); |
|
279 | - return $this; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Offset to unset |
|
284 | - * |
|
285 | - * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
|
286 | - * @param mixed $offset |
|
287 | - * @throws NotImplementedException |
|
288 | - * @return void |
|
289 | - */ |
|
290 | - public function offsetUnset($offset) |
|
291 | - { |
|
292 | - $message = 'Un-setting value for Array object is not supported'; |
|
293 | - throw new NotImplementedException($message, 1376132306); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Convert this to array |
|
298 | - * |
|
299 | - * @return array |
|
300 | - * @throws \InvalidArgumentException |
|
301 | - */ |
|
302 | - public function toArray() |
|
303 | - { |
|
304 | - $result['uid'] = $this->uid; |
|
305 | - $propertiesAndValues = json_decode(json_encode($this), true); |
|
306 | - |
|
307 | - foreach ($propertiesAndValues as $propertyName => $value) { |
|
308 | - $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
309 | - $result[$fieldName] = $value; |
|
310 | - } |
|
311 | - |
|
312 | - return $result; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Convert this object to an array containing the resolved values. |
|
317 | - * |
|
318 | - * @param bool $resolveRelations |
|
319 | - * @return array |
|
320 | - * @throws \Exception |
|
321 | - */ |
|
322 | - public function toValues($resolveRelations = true) |
|
323 | - { |
|
324 | - $result['uid'] = $this->uid; |
|
325 | - $propertiesAndValues = json_decode(json_encode($this), true); |
|
326 | - |
|
327 | - foreach ($propertiesAndValues as $propertyName => $value) { |
|
328 | - $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
329 | - |
|
330 | - $result[$fieldName] = $value; |
|
331 | - if ($resolveRelations) { |
|
332 | - $field = Tca::table($this->dataType)->field($fieldName); |
|
333 | - |
|
334 | - $resolvedValue = ''; |
|
335 | - if ($field->getType() === FieldType::FILE) { |
|
336 | - |
|
337 | - if ($field->hasMany()) { |
|
338 | - $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this); |
|
339 | - |
|
340 | - $resolvedValue = []; |
|
341 | - foreach ($files as $file) { |
|
342 | - $resolvedValue[] = $file->getIdentifier(); |
|
343 | - } |
|
344 | - } else { |
|
345 | - $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this); |
|
346 | - if (!empty($files)) { |
|
347 | - $resolvedValue = current($files)->getIdentifier(); |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - // Reset value |
|
352 | - $result[$fieldName] = $resolvedValue; |
|
353 | - |
|
354 | - } elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) { |
|
355 | - $objects = $this[$fieldName]; |
|
356 | - if (is_array($objects)) { |
|
357 | - $resolvedValue = []; |
|
358 | - foreach ($objects as $object) { |
|
359 | - /** @var $object Content */ |
|
360 | - $labelField = Tca::table($object->getDataType())->getLabelField(); |
|
361 | - $resolvedValue[] = $object[$labelField]; |
|
362 | - } |
|
363 | - } elseif ($objects instanceof Content) { |
|
364 | - $labelField = Tca::table($objects->getDataType())->getLabelField(); |
|
365 | - $resolvedValue = $objects[$labelField]; |
|
366 | - } |
|
367 | - |
|
368 | - // Reset value |
|
369 | - $result[$fieldName] = $resolvedValue; |
|
370 | - } |
|
371 | - } |
|
372 | - } |
|
373 | - |
|
374 | - return $result; |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Return the properties of this object. |
|
379 | - * |
|
380 | - * @return array |
|
381 | - */ |
|
382 | - public function toProperties() |
|
383 | - { |
|
384 | - $result[] = 'uid'; |
|
385 | - $propertiesAndValues = json_decode(json_encode($this), true); |
|
386 | - |
|
387 | - foreach ($propertiesAndValues as $propertyName => $value) { |
|
388 | - $result[] = $propertyName; |
|
389 | - } |
|
390 | - return $result; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Return the properties of this object. |
|
395 | - * |
|
396 | - * @return array |
|
397 | - */ |
|
398 | - public function toFields() |
|
399 | - { |
|
400 | - $result[] = 'uid'; |
|
401 | - $propertiesAndValues = json_decode(json_encode($this), true); |
|
402 | - |
|
403 | - foreach ($propertiesAndValues as $propertyName => $value) { |
|
404 | - $result[] = Property::name($propertyName)->of($this)->toFieldName(); |
|
405 | - } |
|
406 | - |
|
407 | - return $result; |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * @return string |
|
412 | - */ |
|
413 | - public function __toString() |
|
414 | - { |
|
415 | - $labelField = Tca::table($this->dataType)->getLabelField(); |
|
416 | - return $this[$labelField]; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Remove fields according to BE User permission. |
|
421 | - * |
|
422 | - * @param $fields |
|
423 | - * @return array |
|
424 | - * @throws \Exception |
|
425 | - */ |
|
426 | - protected function filterForBackendUser($fields) |
|
427 | - { |
|
428 | - if (!$this->getBackendUser()->isAdmin()) { |
|
429 | - foreach ($fields as $key => $fieldName) { |
|
430 | - if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) { |
|
431 | - unset($fields[$key]); |
|
432 | - } |
|
433 | - } |
|
434 | - } |
|
435 | - return $fields; |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Remove fields according to Grid configuration. |
|
440 | - * |
|
441 | - * @param $fields |
|
442 | - * @return array |
|
443 | - */ |
|
444 | - protected function filterForConfiguration($fields) |
|
445 | - { |
|
446 | - |
|
447 | - $excludedFields = Tca::grid($this->dataType)->getExcludedFields(); |
|
448 | - foreach ($fields as $key => $field) { |
|
449 | - if (in_array($field, $excludedFields)) { |
|
450 | - unset($fields[$key]); |
|
451 | - } |
|
452 | - } |
|
453 | - |
|
454 | - return $fields; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Returns an instance of the current Backend User. |
|
459 | - * |
|
460 | - * @return BackendUserAuthentication |
|
461 | - */ |
|
462 | - protected function getBackendUser() |
|
463 | - { |
|
464 | - return $GLOBALS['BE_USER']; |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Returns whether the current mode is Backend |
|
469 | - * |
|
470 | - * @return bool |
|
471 | - */ |
|
472 | - protected function isBackendMode() |
|
473 | - { |
|
474 | - return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend();; |
|
475 | - } |
|
31 | + /** |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + protected $uid; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $dataType; |
|
40 | + |
|
41 | + /** |
|
42 | + * Constructor for a Content object. |
|
43 | + * |
|
44 | + * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ... |
|
45 | + * @param array $contentData |
|
46 | + * @return \Fab\Vidi\Domain\Model\Content |
|
47 | + * @throws \InvalidArgumentException |
|
48 | + * @throws NotExistingClassException |
|
49 | + */ |
|
50 | + public function __construct($dataType, array $contentData = array()) |
|
51 | + { |
|
52 | + |
|
53 | + $this->dataType = $dataType; |
|
54 | + $this->uid = empty($contentData['uid']) ? null : (int)$contentData['uid']; |
|
55 | + |
|
56 | + /** @var TableService $table */ |
|
57 | + $table = Tca::table($dataType); |
|
58 | + |
|
59 | + // Initialize the array containing the allowed fields to be filled-in. |
|
60 | + $fields = array('pid'); |
|
61 | + |
|
62 | + // If a creation time stamp has been defined for this data type. |
|
63 | + if ($table->getTimeCreationField()) { |
|
64 | + $fields[] = $table->getTimeCreationField(); |
|
65 | + } |
|
66 | + |
|
67 | + // If an update time stamp has been defined for this data type. |
|
68 | + if ($table->getTimeModificationField()) { |
|
69 | + $fields[] = $table->getTimeModificationField(); |
|
70 | + } |
|
71 | + |
|
72 | + // Merge the other fields allowed for this data type. |
|
73 | + $fields = array_merge($fields, $table->getFields()); |
|
74 | + |
|
75 | + // Fetch excluded fields from the grid. |
|
76 | + if ($this->isBackendMode()) { |
|
77 | + $fields = $this->filterForConfiguration($fields); |
|
78 | + $fields = $this->filterForBackendUser($fields); |
|
79 | + } |
|
80 | + |
|
81 | + // Get column to be displayed |
|
82 | + foreach ($fields as $fieldName) { |
|
83 | + if (array_key_exists($fieldName, $contentData)) { |
|
84 | + $propertyName = Field::name($fieldName)->of($dataType)->toPropertyName(); |
|
85 | + $this->$propertyName = $contentData[$fieldName]; |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Dispatches magic methods (findBy[Property]()) |
|
92 | + * |
|
93 | + * @param string $methodName The name of the magic method |
|
94 | + * @param string $arguments The arguments of the magic method |
|
95 | + * @throws UnsupportedMethodException |
|
96 | + * @return mixed |
|
97 | + * @api |
|
98 | + */ |
|
99 | + public function __call($methodName, $arguments) |
|
100 | + { |
|
101 | + $value = null; |
|
102 | + if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) { |
|
103 | + $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1); |
|
104 | + |
|
105 | + $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
106 | + $field = Tca::table($this->dataType)->field($fieldName); |
|
107 | + |
|
108 | + $value = $this->$propertyName; |
|
109 | + |
|
110 | + // true means it is a relation and it is not yet resolved. |
|
111 | + if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) { |
|
112 | + $value = $this->resolveRelation($propertyName); |
|
113 | + } elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) { |
|
114 | + |
|
115 | + // Attempt to convert the value into a label for radio and select fields. |
|
116 | + $label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value); |
|
117 | + if ($label) { |
|
118 | + $value = $label; |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) { |
|
123 | + $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1); |
|
124 | + $this->$propertyName = $arguments[0]; |
|
125 | + } |
|
126 | + return $value; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Tell whether the property has a relation. |
|
131 | + * |
|
132 | + * @param string $propertyName |
|
133 | + * @return bool |
|
134 | + */ |
|
135 | + protected function hasRelation($propertyName) |
|
136 | + { |
|
137 | + $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
138 | + return Tca::table($this->dataType)->field($fieldName)->hasRelation(); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Try to "resolve" the property whether it has a relation. |
|
143 | + * If the property has not relation it simply returns the same value. |
|
144 | + * |
|
145 | + * @throws \RuntimeException |
|
146 | + * @param string $propertyName |
|
147 | + * @return mixed |
|
148 | + */ |
|
149 | + protected function resolveRelation($propertyName) |
|
150 | + { |
|
151 | + |
|
152 | + // Convert property name to field name and get the foreign data type. |
|
153 | + $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
154 | + $foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType(); |
|
155 | + |
|
156 | + // Get the foreign repository instance form the factory |
|
157 | + /** @var ContentRepository $foreignContentRepository */ |
|
158 | + $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName); |
|
159 | + |
|
160 | + if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) { |
|
161 | + |
|
162 | + // Fetch values from repository |
|
163 | + $values = GeneralUtility::trimExplode(',', $this->$propertyName); |
|
164 | + $this->$propertyName = $foreignContentRepository->findIn('uid', $values); |
|
165 | + } elseif (Tca::table($this->dataType)->field($fieldName)->hasMany()) { |
|
166 | + // Include relation many-to-many and one-to-many |
|
167 | + // Tca::table($this->dataType)->field($fieldName)->hasRelationOneToMany() |
|
168 | + // Tca::table($this->dataType)->field($fieldName)->hasRelationManyToMany() |
|
169 | + |
|
170 | + $foreignFieldName = Tca::table($this->dataType)->field($fieldName)->getForeignField(); |
|
171 | + if (empty($foreignFieldName)) { |
|
172 | + $message = sprintf('Missing "foreign_field" key for field "%s" in table "%s".', |
|
173 | + $fieldName, |
|
174 | + $this->dataType |
|
175 | + ); |
|
176 | + throw new \RuntimeException($message, 1376149186); |
|
177 | + } |
|
178 | + |
|
179 | + // Fetch values from repository. |
|
180 | + $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName(); |
|
181 | + $findByProperty = 'findBy' . ucfirst($foreignPropertyName); |
|
182 | + |
|
183 | + // Date picker (type == group) are special fields because property path must contain the table name |
|
184 | + // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
|
185 | + $propertyValue = $this->uid; |
|
186 | + if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) { |
|
187 | + $propertyValue = $this->dataType . '.' . $this->uid; |
|
188 | + } |
|
189 | + |
|
190 | + $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue); |
|
191 | + |
|
192 | + } elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) { |
|
193 | + |
|
194 | + $fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration(); |
|
195 | + |
|
196 | + // First case, we are on the "good side" of the relation, just query the repository |
|
197 | + if (empty($fieldConfiguration['foreign_field'])) { |
|
198 | + $this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName); |
|
199 | + } else { |
|
200 | + // Second case, we are the "bad side" of the relation, query the foreign repository |
|
201 | + // e.g. in case of one-to-one relation. |
|
202 | + |
|
203 | + // We must query the opposite side to get the identifier of the foreign object. |
|
204 | + $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable(); |
|
205 | + $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField(); |
|
206 | + $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType); |
|
207 | + $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField); |
|
208 | + |
|
209 | + /** @var Content $foreignObject */ |
|
210 | + $this->$propertyName = $foreignContentRepository->$find($this->getUid()); |
|
211 | + } |
|
212 | + |
|
213 | + } |
|
214 | + return $this->$propertyName; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @return int |
|
219 | + */ |
|
220 | + public function getUid() |
|
221 | + { |
|
222 | + return $this->uid; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public function getDataType() |
|
229 | + { |
|
230 | + return $this->dataType; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Whether a offset exists |
|
235 | + * |
|
236 | + * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
|
237 | + * @param mixed $offset |
|
238 | + * @return boolean true on success or false on failure. |
|
239 | + * @throws \RuntimeException |
|
240 | + * @throws \InvalidArgumentException |
|
241 | + */ |
|
242 | + public function offsetExists($offset) |
|
243 | + { |
|
244 | + $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
245 | + return isset($this->$offset); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Offset to retrieve |
|
250 | + * |
|
251 | + * @link http://php.net/manual/en/arrayaccess.offsetget.php |
|
252 | + * @param mixed $offset |
|
253 | + * @return mixed Can return all value types. |
|
254 | + * @throws \RuntimeException |
|
255 | + * @throws \InvalidArgumentException |
|
256 | + */ |
|
257 | + public function offsetGet($offset) |
|
258 | + { |
|
259 | + $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
260 | + $getter = 'get' . ucfirst($offset); |
|
261 | + return $this->$getter(); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Offset to set |
|
266 | + * |
|
267 | + * @link http://php.net/manual/en/arrayaccess.offsetset.php |
|
268 | + * @param mixed $offset |
|
269 | + * @param mixed $value |
|
270 | + * @return $this |
|
271 | + * @throws \RuntimeException |
|
272 | + * @throws \InvalidArgumentException |
|
273 | + */ |
|
274 | + public function offsetSet($offset, $value) |
|
275 | + { |
|
276 | + $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
277 | + $setter = 'set' . ucfirst($offset); |
|
278 | + $this->$setter($value); |
|
279 | + return $this; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Offset to unset |
|
284 | + * |
|
285 | + * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
|
286 | + * @param mixed $offset |
|
287 | + * @throws NotImplementedException |
|
288 | + * @return void |
|
289 | + */ |
|
290 | + public function offsetUnset($offset) |
|
291 | + { |
|
292 | + $message = 'Un-setting value for Array object is not supported'; |
|
293 | + throw new NotImplementedException($message, 1376132306); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Convert this to array |
|
298 | + * |
|
299 | + * @return array |
|
300 | + * @throws \InvalidArgumentException |
|
301 | + */ |
|
302 | + public function toArray() |
|
303 | + { |
|
304 | + $result['uid'] = $this->uid; |
|
305 | + $propertiesAndValues = json_decode(json_encode($this), true); |
|
306 | + |
|
307 | + foreach ($propertiesAndValues as $propertyName => $value) { |
|
308 | + $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
309 | + $result[$fieldName] = $value; |
|
310 | + } |
|
311 | + |
|
312 | + return $result; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Convert this object to an array containing the resolved values. |
|
317 | + * |
|
318 | + * @param bool $resolveRelations |
|
319 | + * @return array |
|
320 | + * @throws \Exception |
|
321 | + */ |
|
322 | + public function toValues($resolveRelations = true) |
|
323 | + { |
|
324 | + $result['uid'] = $this->uid; |
|
325 | + $propertiesAndValues = json_decode(json_encode($this), true); |
|
326 | + |
|
327 | + foreach ($propertiesAndValues as $propertyName => $value) { |
|
328 | + $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
329 | + |
|
330 | + $result[$fieldName] = $value; |
|
331 | + if ($resolveRelations) { |
|
332 | + $field = Tca::table($this->dataType)->field($fieldName); |
|
333 | + |
|
334 | + $resolvedValue = ''; |
|
335 | + if ($field->getType() === FieldType::FILE) { |
|
336 | + |
|
337 | + if ($field->hasMany()) { |
|
338 | + $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this); |
|
339 | + |
|
340 | + $resolvedValue = []; |
|
341 | + foreach ($files as $file) { |
|
342 | + $resolvedValue[] = $file->getIdentifier(); |
|
343 | + } |
|
344 | + } else { |
|
345 | + $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this); |
|
346 | + if (!empty($files)) { |
|
347 | + $resolvedValue = current($files)->getIdentifier(); |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + // Reset value |
|
352 | + $result[$fieldName] = $resolvedValue; |
|
353 | + |
|
354 | + } elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) { |
|
355 | + $objects = $this[$fieldName]; |
|
356 | + if (is_array($objects)) { |
|
357 | + $resolvedValue = []; |
|
358 | + foreach ($objects as $object) { |
|
359 | + /** @var $object Content */ |
|
360 | + $labelField = Tca::table($object->getDataType())->getLabelField(); |
|
361 | + $resolvedValue[] = $object[$labelField]; |
|
362 | + } |
|
363 | + } elseif ($objects instanceof Content) { |
|
364 | + $labelField = Tca::table($objects->getDataType())->getLabelField(); |
|
365 | + $resolvedValue = $objects[$labelField]; |
|
366 | + } |
|
367 | + |
|
368 | + // Reset value |
|
369 | + $result[$fieldName] = $resolvedValue; |
|
370 | + } |
|
371 | + } |
|
372 | + } |
|
373 | + |
|
374 | + return $result; |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Return the properties of this object. |
|
379 | + * |
|
380 | + * @return array |
|
381 | + */ |
|
382 | + public function toProperties() |
|
383 | + { |
|
384 | + $result[] = 'uid'; |
|
385 | + $propertiesAndValues = json_decode(json_encode($this), true); |
|
386 | + |
|
387 | + foreach ($propertiesAndValues as $propertyName => $value) { |
|
388 | + $result[] = $propertyName; |
|
389 | + } |
|
390 | + return $result; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Return the properties of this object. |
|
395 | + * |
|
396 | + * @return array |
|
397 | + */ |
|
398 | + public function toFields() |
|
399 | + { |
|
400 | + $result[] = 'uid'; |
|
401 | + $propertiesAndValues = json_decode(json_encode($this), true); |
|
402 | + |
|
403 | + foreach ($propertiesAndValues as $propertyName => $value) { |
|
404 | + $result[] = Property::name($propertyName)->of($this)->toFieldName(); |
|
405 | + } |
|
406 | + |
|
407 | + return $result; |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * @return string |
|
412 | + */ |
|
413 | + public function __toString() |
|
414 | + { |
|
415 | + $labelField = Tca::table($this->dataType)->getLabelField(); |
|
416 | + return $this[$labelField]; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Remove fields according to BE User permission. |
|
421 | + * |
|
422 | + * @param $fields |
|
423 | + * @return array |
|
424 | + * @throws \Exception |
|
425 | + */ |
|
426 | + protected function filterForBackendUser($fields) |
|
427 | + { |
|
428 | + if (!$this->getBackendUser()->isAdmin()) { |
|
429 | + foreach ($fields as $key => $fieldName) { |
|
430 | + if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) { |
|
431 | + unset($fields[$key]); |
|
432 | + } |
|
433 | + } |
|
434 | + } |
|
435 | + return $fields; |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * Remove fields according to Grid configuration. |
|
440 | + * |
|
441 | + * @param $fields |
|
442 | + * @return array |
|
443 | + */ |
|
444 | + protected function filterForConfiguration($fields) |
|
445 | + { |
|
446 | + |
|
447 | + $excludedFields = Tca::grid($this->dataType)->getExcludedFields(); |
|
448 | + foreach ($fields as $key => $field) { |
|
449 | + if (in_array($field, $excludedFields)) { |
|
450 | + unset($fields[$key]); |
|
451 | + } |
|
452 | + } |
|
453 | + |
|
454 | + return $fields; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Returns an instance of the current Backend User. |
|
459 | + * |
|
460 | + * @return BackendUserAuthentication |
|
461 | + */ |
|
462 | + protected function getBackendUser() |
|
463 | + { |
|
464 | + return $GLOBALS['BE_USER']; |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Returns whether the current mode is Backend |
|
469 | + * |
|
470 | + * @return bool |
|
471 | + */ |
|
472 | + protected function isBackendMode() |
|
473 | + { |
|
474 | + return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend();; |
|
475 | + } |
|
476 | 476 | |
477 | 477 | } |
@@ -21,50 +21,50 @@ |
||
21 | 21 | class FacetController extends ActionController |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Suggest values according to a facet. |
|
26 | - * Output a json list of key / values. |
|
27 | - * |
|
28 | - * @param string $facet |
|
29 | - * @param string $searchTerm |
|
30 | - * @Validate("Fab\Vidi\Domain\Validator\FacetValidator", param="facet") |
|
31 | - */ |
|
32 | - public function autoSuggestAction($facet, $searchTerm) |
|
33 | - { |
|
24 | + /** |
|
25 | + * Suggest values according to a facet. |
|
26 | + * Output a json list of key / values. |
|
27 | + * |
|
28 | + * @param string $facet |
|
29 | + * @param string $searchTerm |
|
30 | + * @Validate("Fab\Vidi\Domain\Validator\FacetValidator", param="facet") |
|
31 | + */ |
|
32 | + public function autoSuggestAction($facet, $searchTerm) |
|
33 | + { |
|
34 | 34 | |
35 | - $suggestions = $this->getFacetSuggestionService()->getSuggestions($facet); |
|
35 | + $suggestions = $this->getFacetSuggestionService()->getSuggestions($facet); |
|
36 | 36 | |
37 | 37 | |
38 | - return $this->responseFactory->createResponse() |
|
39 | - ->withAddedHeader('Content-Type', 'application/json') |
|
40 | - ->withBody($this->streamFactory->createStream(json_encode($suggestions))); |
|
41 | - } |
|
38 | + return $this->responseFactory->createResponse() |
|
39 | + ->withAddedHeader('Content-Type', 'application/json') |
|
40 | + ->withBody($this->streamFactory->createStream(json_encode($suggestions))); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Suggest values for all configured facets in the Grid. |
|
45 | - * Output a json list of key / values. |
|
46 | - */ |
|
47 | - public function autoSuggestsAction() |
|
48 | - { |
|
43 | + /** |
|
44 | + * Suggest values for all configured facets in the Grid. |
|
45 | + * Output a json list of key / values. |
|
46 | + */ |
|
47 | + public function autoSuggestsAction() |
|
48 | + { |
|
49 | 49 | |
50 | - $suggestions = []; |
|
51 | - foreach (Tca::grid()->getFacets() as $facet) { |
|
52 | - /** @var FacetInterface $facet */ |
|
53 | - $name = $facet->getName(); |
|
54 | - $suggestions[$name] = $this->getFacetSuggestionService()->getSuggestions($name); |
|
55 | - } |
|
50 | + $suggestions = []; |
|
51 | + foreach (Tca::grid()->getFacets() as $facet) { |
|
52 | + /** @var FacetInterface $facet */ |
|
53 | + $name = $facet->getName(); |
|
54 | + $suggestions[$name] = $this->getFacetSuggestionService()->getSuggestions($name); |
|
55 | + } |
|
56 | 56 | |
57 | - return $this->responseFactory->createResponse() |
|
58 | - ->withAddedHeader('Content-Type', 'application/json') |
|
59 | - ->withBody($this->streamFactory->createStream(json_encode($suggestions))); |
|
60 | - } |
|
57 | + return $this->responseFactory->createResponse() |
|
58 | + ->withAddedHeader('Content-Type', 'application/json') |
|
59 | + ->withBody($this->streamFactory->createStream(json_encode($suggestions))); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return FacetSuggestionService|object |
|
64 | - */ |
|
65 | - protected function getFacetSuggestionService() |
|
66 | - { |
|
67 | - return GeneralUtility::makeInstance(FacetSuggestionService::class); |
|
68 | - } |
|
62 | + /** |
|
63 | + * @return FacetSuggestionService|object |
|
64 | + */ |
|
65 | + protected function getFacetSuggestionService() |
|
66 | + { |
|
67 | + return GeneralUtility::makeInstance(FacetSuggestionService::class); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
@@ -17,20 +17,20 @@ |
||
17 | 17 | class ExportXlsMenuItem extends AbstractComponentView |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * Renders a "xls export" item to be placed in the menu. |
|
22 | - * Only the admin is allowed to export for now as security is not handled. |
|
23 | - * |
|
24 | - * @return string |
|
25 | - * @throws \InvalidArgumentException |
|
26 | - */ |
|
27 | - public function render() |
|
28 | - { |
|
29 | - $result = sprintf('<li><a href="#" class="dropdown-item export-xls" data-format="xls">%s %s</a></li>', |
|
30 | - $this->getIconFactory()->getIcon('mimetypes-excel', Icon::SIZE_SMALL), |
|
31 | - $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:export-xls') |
|
32 | - ); |
|
33 | - return $result; |
|
34 | - } |
|
20 | + /** |
|
21 | + * Renders a "xls export" item to be placed in the menu. |
|
22 | + * Only the admin is allowed to export for now as security is not handled. |
|
23 | + * |
|
24 | + * @return string |
|
25 | + * @throws \InvalidArgumentException |
|
26 | + */ |
|
27 | + public function render() |
|
28 | + { |
|
29 | + $result = sprintf('<li><a href="#" class="dropdown-item export-xls" data-format="xls">%s %s</a></li>', |
|
30 | + $this->getIconFactory()->getIcon('mimetypes-excel', Icon::SIZE_SMALL), |
|
31 | + $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:export-xls') |
|
32 | + ); |
|
33 | + return $result; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |
@@ -17,19 +17,19 @@ |
||
17 | 17 | class ExportCsvMenuItem extends AbstractComponentView |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * Renders a "csv export" item to be placed in the menu. |
|
22 | - * Only the admin is allowed to export for now as security is not handled. |
|
23 | - * |
|
24 | - * @return string |
|
25 | - * @throws \InvalidArgumentException |
|
26 | - */ |
|
27 | - public function render() |
|
28 | - { |
|
29 | - $result = sprintf('<li><a href="#" class="dropdown-item export-csv" data-format="csv">%s %s</a></li>', |
|
30 | - $this->getIconFactory()->getIcon('mimetypes-text-csv', Icon::SIZE_SMALL), |
|
31 | - $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:export-csv') |
|
32 | - ); |
|
33 | - return $result; |
|
34 | - } |
|
20 | + /** |
|
21 | + * Renders a "csv export" item to be placed in the menu. |
|
22 | + * Only the admin is allowed to export for now as security is not handled. |
|
23 | + * |
|
24 | + * @return string |
|
25 | + * @throws \InvalidArgumentException |
|
26 | + */ |
|
27 | + public function render() |
|
28 | + { |
|
29 | + $result = sprintf('<li><a href="#" class="dropdown-item export-csv" data-format="csv">%s %s</a></li>', |
|
30 | + $this->getIconFactory()->getIcon('mimetypes-text-csv', Icon::SIZE_SMALL), |
|
31 | + $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:export-csv') |
|
32 | + ); |
|
33 | + return $result; |
|
34 | + } |
|
35 | 35 | } |
@@ -17,35 +17,35 @@ |
||
17 | 17 | class MassDeleteMenuItem extends AbstractComponentView |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * Renders a "mass delete" menu item to be placed in the grid menu. |
|
22 | - * |
|
23 | - * @return string |
|
24 | - * @throws \InvalidArgumentException |
|
25 | - */ |
|
26 | - public function render() |
|
27 | - { |
|
28 | - return sprintf('<li><a href="%s" class="dropdown-item mass-delete" >%s %s</a>', |
|
29 | - $this->getMassDeleteUri(), |
|
30 | - $this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL), |
|
31 | - $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:delete') |
|
32 | - ); |
|
33 | - } |
|
20 | + /** |
|
21 | + * Renders a "mass delete" menu item to be placed in the grid menu. |
|
22 | + * |
|
23 | + * @return string |
|
24 | + * @throws \InvalidArgumentException |
|
25 | + */ |
|
26 | + public function render() |
|
27 | + { |
|
28 | + return sprintf('<li><a href="%s" class="dropdown-item mass-delete" >%s %s</a>', |
|
29 | + $this->getMassDeleteUri(), |
|
30 | + $this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL), |
|
31 | + $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:delete') |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return string |
|
37 | - * @throws \InvalidArgumentException |
|
38 | - */ |
|
39 | - protected function getMassDeleteUri() |
|
40 | - { |
|
41 | - $additionalParameters = array( |
|
42 | - $this->getModuleLoader()->getParameterPrefix() => array( |
|
43 | - 'controller' => 'Content', |
|
44 | - 'action' => 'delete', |
|
45 | - 'format' => 'json', |
|
46 | - ), |
|
47 | - ); |
|
48 | - return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
49 | - } |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + * @throws \InvalidArgumentException |
|
38 | + */ |
|
39 | + protected function getMassDeleteUri() |
|
40 | + { |
|
41 | + $additionalParameters = array( |
|
42 | + $this->getModuleLoader()->getParameterPrefix() => array( |
|
43 | + 'controller' => 'Content', |
|
44 | + 'action' => 'delete', |
|
45 | + 'format' => 'json', |
|
46 | + ), |
|
47 | + ); |
|
48 | + return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | } |
@@ -16,13 +16,13 @@ |
||
16 | 16 | class DividerMenuItem extends AbstractComponentView |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Renders a "divider" menu item to be placed in the grid menu. |
|
21 | - * |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public function render() |
|
25 | - { |
|
26 | - return ' <li><hr class="dropdown-divider"></li>'; |
|
27 | - } |
|
19 | + /** |
|
20 | + * Renders a "divider" menu item to be placed in the grid menu. |
|
21 | + * |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public function render() |
|
25 | + { |
|
26 | + return ' <li><hr class="dropdown-divider"></li>'; |
|
27 | + } |
|
28 | 28 | } |
@@ -17,20 +17,20 @@ |
||
17 | 17 | class ExportXmlMenuItem extends AbstractComponentView |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * Renders an "xml export" item to be placed in the menu. |
|
22 | - * Only the admin is allowed to export for now as security is not handled. |
|
23 | - * |
|
24 | - * @return string |
|
25 | - * @throws \InvalidArgumentException |
|
26 | - */ |
|
27 | - public function render() |
|
28 | - { |
|
29 | - $result = sprintf('<li><a href="#" class="dropdown-item export-xml" data-format="xml">%s %s</a></li>', |
|
30 | - $this->getIconFactory()->getIcon('mimetypes-text-html', Icon::SIZE_SMALL), |
|
31 | - $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:export-xml') |
|
32 | - ); |
|
33 | - return $result; |
|
34 | - } |
|
20 | + /** |
|
21 | + * Renders an "xml export" item to be placed in the menu. |
|
22 | + * Only the admin is allowed to export for now as security is not handled. |
|
23 | + * |
|
24 | + * @return string |
|
25 | + * @throws \InvalidArgumentException |
|
26 | + */ |
|
27 | + public function render() |
|
28 | + { |
|
29 | + $result = sprintf('<li><a href="#" class="dropdown-item export-xml" data-format="xml">%s %s</a></li>', |
|
30 | + $this->getIconFactory()->getIcon('mimetypes-text-html', Icon::SIZE_SMALL), |
|
31 | + $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:export-xml') |
|
32 | + ); |
|
33 | + return $result; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |
@@ -58,9 +58,9 @@ |
||
58 | 58 | protected function resolvePath($uri) |
59 | 59 | { |
60 | 60 | $uri = GeneralUtility::getFileAbsFileName($uri); |
61 | - $uri = substr($uri, strlen(Environment::getPublicPath() . '/')); |
|
61 | + $uri = substr($uri, strlen(Environment::getPublicPath().'/')); |
|
62 | 62 | if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() && $uri !== false) { |
63 | - $uri = '../' . $uri; |
|
63 | + $uri = '../'.$uri; |
|
64 | 64 | } |
65 | 65 | return $uri; |
66 | 66 | } |
@@ -21,48 +21,48 @@ |
||
21 | 21 | class AdditionalAssetsViewHelper extends AbstractBackendViewHelper |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var PageRenderer |
|
26 | - * @Inject |
|
27 | - */ |
|
28 | - public $pageRenderer; |
|
24 | + /** |
|
25 | + * @var PageRenderer |
|
26 | + * @Inject |
|
27 | + */ |
|
28 | + public $pageRenderer; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Load the assets (JavaScript, CSS) for this Vidi module. |
|
32 | - * |
|
33 | - * @return void |
|
34 | - * @api |
|
35 | - */ |
|
36 | - public function render() |
|
37 | - { |
|
38 | - /** @var ModuleLoader $moduleLoader */ |
|
39 | - $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
30 | + /** |
|
31 | + * Load the assets (JavaScript, CSS) for this Vidi module. |
|
32 | + * |
|
33 | + * @return void |
|
34 | + * @api |
|
35 | + */ |
|
36 | + public function render() |
|
37 | + { |
|
38 | + /** @var ModuleLoader $moduleLoader */ |
|
39 | + $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
40 | 40 | |
41 | - foreach ($moduleLoader->getAdditionalStyleSheetFiles() as $addCssFile) { |
|
42 | - $fileNameAndPath = $this->resolvePath($addCssFile); |
|
43 | - $this->pageRenderer->addCssFile($fileNameAndPath); |
|
44 | - } |
|
41 | + foreach ($moduleLoader->getAdditionalStyleSheetFiles() as $addCssFile) { |
|
42 | + $fileNameAndPath = $this->resolvePath($addCssFile); |
|
43 | + $this->pageRenderer->addCssFile($fileNameAndPath); |
|
44 | + } |
|
45 | 45 | |
46 | - foreach ($moduleLoader->getAdditionalJavaScriptFiles() as $addJsFile) { |
|
47 | - $fileNameAndPath = $this->resolvePath($addJsFile); |
|
48 | - $this->pageRenderer->addJsFile($fileNameAndPath); |
|
49 | - } |
|
50 | - } |
|
46 | + foreach ($moduleLoader->getAdditionalJavaScriptFiles() as $addJsFile) { |
|
47 | + $fileNameAndPath = $this->resolvePath($addJsFile); |
|
48 | + $this->pageRenderer->addJsFile($fileNameAndPath); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Resolve a resource path. |
|
54 | - * |
|
55 | - * @param string $uri |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - protected function resolvePath($uri) |
|
59 | - { |
|
60 | - $uri = GeneralUtility::getFileAbsFileName($uri); |
|
61 | - $uri = substr($uri, strlen(Environment::getPublicPath() . '/')); |
|
62 | - if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() && $uri !== false) { |
|
63 | - $uri = '../' . $uri; |
|
64 | - } |
|
65 | - return $uri; |
|
66 | - } |
|
52 | + /** |
|
53 | + * Resolve a resource path. |
|
54 | + * |
|
55 | + * @param string $uri |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + protected function resolvePath($uri) |
|
59 | + { |
|
60 | + $uri = GeneralUtility::getFileAbsFileName($uri); |
|
61 | + $uri = substr($uri, strlen(Environment::getPublicPath() . '/')); |
|
62 | + if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() && $uri !== false) { |
|
63 | + $uri = '../' . $uri; |
|
64 | + } |
|
65 | + return $uri; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | } |