TYPO3 CMS  TYPO3_6-2
AbstractRecordCollection.php
Go to the documentation of this file.
1 <?php
3 
31 
37  static protected $storageTableName = 'sys_collection';
38 
44  static protected $storageItemsField = 'items';
45 
51  protected $uid = 0;
52 
58  protected $title;
59 
65  protected $description;
66 
72  protected $itemTableName;
73 
79  protected $storage;
80 
84  public function __construct() {
85  $this->storage = new \SplDoublyLinkedList();
86  }
87 
95  public function current() {
96  return $this->storage->current();
97  }
98 
106  public function next() {
107  $this->storage->next();
108  }
109 
117  public function key() {
118  $currentRecord = $this->storage->current();
119  return $currentRecord['uid'];
120  }
121 
129  public function valid() {
130  return $this->storage->valid();
131  }
132 
140  public function rewind() {
141  $this->storage->rewind();
142  }
143 
151  public function serialize() {
152  $data = array(
153  'uid' => $this->getIdentifier()
154  );
155  return serialize($data);
156  }
157 
166  public function unserialize($serialized) {
167  $data = unserialize($serialized);
168  return self::load($data['uid']);
169  }
170 
178  public function count() {
179  return $this->storage->count();
180  }
181 
187  public function getTitle() {
188  return $this->title;
189  }
190 
196  public function getUid() {
197  return $this->uid;
198  }
199 
205  public function getDescription() {
206  return $this->description;
207  }
208 
215  public function setTitle($title) {
216  $this->title = $title;
217  }
218 
225  public function setDescription($desc) {
226  $this->description = $desc;
227  }
228 
234  public function getItemTableName() {
235  return $this->itemTableName;
236  }
237 
244  public function setItemTableName($tableName) {
245  $this->itemTableName = $tableName;
246  }
247 
258  public function usort($callbackFunction) {
259  // TODO: Implement usort() method with TCEforms in mind
260  throw new \RuntimeException('This method is not yet supported.', 1322545589);
261  }
262 
273  public function moveItemAt($currentPosition, $newPosition = 0) {
274  // TODO: Implement usort() method with TCEforms in mind
275  throw new \RuntimeException('This method is not yet supported.', 1322545626);
276  }
277 
283  public function getIdentifier() {
284  return $this->uid;
285  }
286 
293  public function setIdentifier($id) {
294  $this->uid = (int)$id;
295  }
296 
308  static public function load($id, $fillItems = FALSE) {
309  $collectionRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', static::$storageTableName, 'uid=' . (int)$id . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause(static::$storageTableName));
310  return self::create($collectionRecord, $fillItems);
311  }
312 
321  static public function create(array $collectionRecord, $fillItems = FALSE) {
322  $collection = new static();
323  $collection->fromArray($collectionRecord);
324  if ($fillItems) {
325  $collection->loadContents();
326  }
327  return $collection;
328  }
329 
335  public function persist() {
336  $uid = $this->getIdentifier() == 0 ? 'NEW' . rand(100000, 999999) : $this->getIdentifier();
337  $data = array(
338  trim(static::$storageTableName) => array(
339  $uid => $this->getPersistableDataArray()
340  )
341  );
342  // New records always must have a pid
343  if ($this->getIdentifier() == 0) {
344  $data[trim(static::$storageTableName)][$uid]['pid'] = 0;
345  }
347  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
348  $tce->stripslashes_values = 0;
349  $tce->start($data, array());
350  $tce->process_datamap();
351  }
352 
361  abstract protected function getPersistableDataArray();
362 
372  protected function getItemUidList($includeTableName = TRUE) {
373  $list = array();
374  foreach ($this->storage as $entry) {
375  $list[] = ($includeTableName ? $this->getItemTableName() . '_' : '') . $entry['uid'];
376  }
377  return implode(',', $list);
378  }
379 
385  public function toArray() {
386  $itemArray = array();
387  foreach ($this->storage as $item) {
388  $itemArray[] = $item;
389  }
390  return array(
391  'uid' => $this->getIdentifier(),
392  'title' => $this->getTitle(),
393  'description' => $this->getDescription(),
394  'table_name' => $this->getItemTableName(),
395  'items' => $itemArray
396  );
397  }
398 
405  public function fromArray(array $array) {
406  $this->uid = $array['uid'];
407  $this->title = $array['title'];
408  $this->description = $array['description'];
409  $this->itemTableName = $array['table_name'];
410  }
411 
412 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static create(array $collectionRecord, $fillItems=FALSE)