TYPO3 CMS  TYPO3_7-6
ElementEntity.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 
21 {
22  const REFERENCES_ChildOf = 'childOf';
23  const REFERENCES_ParentOf = 'parentOf';
24  const EVENT_Construct = 'TYPO3\\CMS\\Version\\Dependency\\ElementEntity::construct';
25  const EVENT_CreateChildReference = 'TYPO3\\CMS\\Version\\Dependency\\ElementEntity::createChildReference';
26  const EVENT_CreateParentReference = 'TYPO3\\CMS\\Version\\Dependency\\ElementEntity::createParentReference';
27  const RESPONSE_Skip = 'TYPO3\\CMS\\Version\\Dependency\\ElementEntity->skip';
28 
32  protected $invalid = false;
33 
37  protected $table;
38 
42  protected $id;
43 
47  protected $data;
48 
52  protected $record;
53 
57  protected $dependency;
58 
62  protected $children;
63 
67  protected $parents;
68 
72  protected $traversingParents = false;
73 
77  protected $outerMostParent;
78 
82  protected $nestedChildren;
83 
92  public function __construct($table, $id, array $data = [], \TYPO3\CMS\Version\Dependency\DependencyResolver $dependency)
93  {
94  $this->table = $table;
95  $this->id = (int)$id;
96  $this->data = $data;
97  $this->dependency = $dependency;
98  $this->dependency->executeEventCallback(self::EVENT_Construct, $this);
99  }
100 
104  public function setInvalid($invalid)
105  {
106  $this->invalid = (bool)$invalid;
107  }
108 
112  public function isInvalid()
113  {
114  return $this->invalid;
115  }
116 
122  public function getTable()
123  {
124  return $this->table;
125  }
126 
132  public function getId()
133  {
134  return $this->id;
135  }
136 
142  public function setId($id)
143  {
144  $this->id = (int)$id;
145  }
146 
152  public function getData()
153  {
154  return $this->data;
155  }
156 
163  public function getDataValue($key)
164  {
165  $result = null;
166  if ($this->hasDataValue($key)) {
167  $result = $this->data[$key];
168  }
169  return $result;
170  }
171 
179  public function setDataValue($key, $value)
180  {
181  $this->data[$key] = $value;
182  }
183 
190  public function hasDataValue($key)
191  {
192  return isset($this->data[$key]);
193  }
194 
200  public function __toString()
201  {
202  return self::getIdentifier($this->table, $this->id);
203  }
204 
210  public function getDependency()
211  {
212  return $this->dependency;
213  }
214 
220  public function getChildren()
221  {
222  if (!isset($this->children)) {
223  $this->children = [];
224  $where = 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->table, 'sys_refindex') . ' AND recuid='
225  . $this->id . ' AND workspace=' . $this->dependency->getWorkspace();
226  $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', $where, '', 'sorting');
227  if (is_array($rows)) {
228  foreach ($rows as $row) {
229  if ($row['ref_table'] !== '_FILE' && $row['ref_table'] !== '_STRING') {
230  $arguments = [
231  'table' => $row['ref_table'],
232  'id' => $row['ref_uid'],
233  'field' => $row['field'],
234  'scope' => self::REFERENCES_ChildOf
235  ];
236 
237  $callbackResponse = $this->dependency->executeEventCallback(self::EVENT_CreateChildReference, $this, $arguments);
238  if ($callbackResponse !== self::RESPONSE_Skip) {
239  $this->children[] = $this->getDependency()->getFactory()->getReferencedElement(
240  $row['ref_table'],
241  $row['ref_uid'],
242  $row['field'],
243  [],
244  $this->getDependency()
245  );
246  }
247  }
248  }
249  }
250  }
251  return $this->children;
252  }
253 
259  public function getParents()
260  {
261  if (!isset($this->parents)) {
262  $this->parents = [];
263  $where = 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->table, 'sys_refindex')
264  . ' AND deleted=0 AND ref_uid=' . $this->id . ' AND workspace=' . $this->dependency->getWorkspace();
265  $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', $where, '', 'sorting');
266  if (is_array($rows)) {
267  foreach ($rows as $row) {
268  $arguments = ['table' => $row['tablename'], 'id' => $row['recuid'], 'field' => $row['field'], 'scope' => self::REFERENCES_ParentOf];
269  $callbackResponse = $this->dependency->executeEventCallback(self::EVENT_CreateParentReference, $this, $arguments);
270  if ($callbackResponse !== self::RESPONSE_Skip) {
271  $this->parents[] = $this->getDependency()->getFactory()->getReferencedElement(
272  $row['tablename'],
273  $row['recuid'],
274  $row['field'],
275  [],
276  $this->getDependency()
277  );
278  }
279  }
280  }
281  }
282  return $this->parents;
283  }
284 
290  public function hasReferences()
291  {
292  return !empty($this->getChildren()) || !empty($this->getParents());
293  }
294 
300  public function getOuterMostParent()
301  {
302  if (!isset($this->outerMostParent)) {
303  $parents = $this->getParents();
304  if (empty($parents)) {
305  $this->outerMostParent = $this;
306  } else {
307  $this->outerMostParent = false;
309  foreach ($parents as $parent) {
310  $outerMostParent = $parent->getElement()->getOuterMostParent();
311  if ($outerMostParent instanceof \TYPO3\CMS\Version\Dependency\ElementEntity) {
312  $this->outerMostParent = $outerMostParent;
313  break;
314  } elseif ($outerMostParent === false) {
315  break;
316  }
317  }
318  }
319  }
320  return $this->outerMostParent;
321  }
322 
328  public function getNestedChildren()
329  {
330  if (!isset($this->nestedChildren)) {
331  $this->nestedChildren = [];
332  $children = $this->getChildren();
334  foreach ($children as $child) {
335  $this->nestedChildren = array_merge($this->nestedChildren, [$child->getElement()->__toString() => $child->getElement()], $child->getElement()->getNestedChildren());
336  }
337  }
338  return $this->nestedChildren;
339  }
340 
348  public static function getIdentifier($table, $id)
349  {
350  return $table . ':' . $id;
351  }
352 
358  public function getRecord()
359  {
360  if (empty($this->record['uid']) || (int)$this->record['uid'] !== $this->getId()) {
361  $this->record = [];
362  $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid,pid,t3ver_wsid,t3ver_state,t3ver_oid', $this->getTable(), 'uid=' . $this->getId());
363  if (is_array($row)) {
364  $this->record = $row;
365  }
366  }
367  return $this->record;
368  }
369 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
__construct($table, $id, array $data=[], \TYPO3\CMS\Version\Dependency\DependencyResolver $dependency)