TYPO3 CMS  TYPO3_6-2
ElementEntity.php
Go to the documentation of this file.
1 <?php
3 
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 = array(), \TYPO3\CMS\Version\Dependency\DependencyResolver $dependency) {
93  $this->table = $table;
94  $this->id = (int)$id;
95  $this->data = $data;
96  $this->dependency = $dependency;
97  $this->dependency->executeEventCallback(self::EVENT_Construct, $this);
98  }
99 
103  public function setInvalid($invalid) {
104  $this->invalid = (bool)$invalid;
105  }
106 
110  public function isInvalid() {
111  return $this->invalid;
112  }
113 
119  public function getTable() {
120  return $this->table;
121  }
122 
128  public function getId() {
129  return $this->id;
130  }
131 
137  public function setId($id) {
138  $this->id = (int)$id;
139  }
140 
146  public function getData() {
147  return $this->data;
148  }
149 
156  public function getDataValue($key) {
157  $result = NULL;
158  if ($this->hasDataValue($key)) {
159  $result = $this->data[$key];
160  }
161  return $result;
162  }
163 
171  public function setDataValue($key, $value) {
172  $this->data[$key] = $value;
173  }
174 
181  public function hasDataValue($key) {
182  return isset($this->data[$key]);
183  }
184 
190  public function __toString() {
191  return self::getIdentifier($this->table, $this->id);
192  }
193 
199  public function getDependency() {
200  return $this->dependency;
201  }
202 
208  public function getChildren() {
209  if (!isset($this->children)) {
210  $this->children = array();
211  $where = 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->table, 'sys_refindex') . ' AND recuid='
212  . $this->id . ' AND workspace=' . $this->dependency->getWorkspace();
213  $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', $where, '', 'sorting');
214  if (is_array($rows)) {
215  foreach ($rows as $row) {
216  if ($row['ref_table'] !== '_FILE' && $row['ref_table'] !== '_STRING') {
217  $arguments = array(
218  'table' => $row['ref_table'],
219  'id' => $row['ref_uid'],
220  'field' => $row['field'],
221  'scope' => self::REFERENCES_ChildOf
222  );
223 
224  $callbackResponse = $this->dependency->executeEventCallback(self::EVENT_CreateChildReference, $this, $arguments);
225  if ($callbackResponse !== self::RESPONSE_Skip) {
226  $this->children[] = $this->getDependency()->getFactory()->getReferencedElement(
227  $row['ref_table'],
228  $row['ref_uid'],
229  $row['field'],
230  array(),
231  $this->getDependency()
232  );
233  }
234  }
235  }
236  }
237  }
238  return $this->children;
239  }
240 
246  public function getParents() {
247  if (!isset($this->parents)) {
248  $this->parents = array();
249  $where = 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->table, 'sys_refindex')
250  . ' AND deleted=0 AND ref_uid=' . $this->id . ' AND workspace=' . $this->dependency->getWorkspace();
251  $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', $where, '', 'sorting');
252  if (is_array($rows)) {
253  foreach ($rows as $row) {
254  $arguments = array('table' => $row['tablename'], 'id' => $row['recuid'], 'field' => $row['field'], 'scope' => self::REFERENCES_ParentOf);
255  $callbackResponse = $this->dependency->executeEventCallback(self::EVENT_CreateParentReference, $this, $arguments);
256  if ($callbackResponse !== self::RESPONSE_Skip) {
257  $this->parents[] = $this->getDependency()->getFactory()->getReferencedElement(
258  $row['tablename'],
259  $row['recuid'],
260  $row['field'],
261  array(),
262  $this->getDependency()
263  );
264  }
265  }
266  }
267  }
268  return $this->parents;
269  }
270 
276  public function hasReferences() {
277  return count($this->getChildren()) > 0 || count($this->getParents()) > 0;
278  }
279 
285  public function getOuterMostParent() {
286  if (!isset($this->outerMostParent)) {
287  $parents = $this->getParents();
288  if (count($parents) === 0) {
289  $this->outerMostParent = $this;
290  } else {
291  $this->outerMostParent = FALSE;
293  foreach ($parents as $parent) {
294  $outerMostParent = $parent->getElement()->getOuterMostParent();
295  if ($outerMostParent instanceof \TYPO3\CMS\Version\Dependency\ElementEntity) {
296  $this->outerMostParent = $outerMostParent;
297  break;
298  } elseif ($outerMostParent === FALSE) {
299  break;
300  }
301  }
302  }
303  }
304  return $this->outerMostParent;
305  }
306 
312  public function getNestedChildren() {
313  if (!isset($this->nestedChildren)) {
314  $this->nestedChildren = array();
315  $children = $this->getChildren();
317  foreach ($children as $child) {
318  $this->nestedChildren = array_merge($this->nestedChildren, array($child->getElement()->__toString() => $child->getElement()), $child->getElement()->getNestedChildren());
319  }
320  }
321  return $this->nestedChildren;
322  }
323 
331  static public function getIdentifier($table, $id) {
332  return $table . ':' . $id;
333  }
334 
340  public function getRecord() {
341  if (empty($this->record['uid']) || (int)$this->record['uid'] !== $this->getId()) {
342  $this->record = array();
343  $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid,pid,t3ver_wsid,t3ver_state,t3ver_oid', $this->getTable(), 'uid=' . $this->getId());
344  if (is_array($row)) {
345  $this->record = $row;
346  }
347  }
348  return $this->record;
349  }
350 
351 }
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
__construct($table, $id, array $data=array(), \TYPO3\CMS\Version\Dependency\DependencyResolver $dependency)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]