TYPO3 CMS  TYPO3_6-2
StaticRecordCollection.php
Go to the documentation of this file.
1 <?php
3 
22 
31  static public function create(array $collectionRecord, $fillItems = FALSE) {
33  $collection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $collectionRecord['table_name']);
34  $collection->fromArray($collectionRecord);
35  if ($fillItems) {
36  $collection->loadContents();
37  }
38  return $collection;
39  }
40 
46  public function __construct($tableName = NULL) {
47  parent::__construct();
48  if (!empty($tableName)) {
49  $this->setItemTableName($tableName);
50  } elseif (empty($this->itemTableName)) {
51  throw new \RuntimeException('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection needs a valid itemTableName.', 1330293778);
52  }
53  }
54 
67  public function loadContents() {
68  $entries = $this->getCollectedRecords();
69  $this->removeAll();
70  foreach ($entries as $entry) {
71  $this->add($entry);
72  }
73  }
74 
83  protected function getPersistableDataArray() {
84  return array(
85  'title' => $this->getTitle(),
86  'description' => $this->getDescription(),
87  'items' => $this->getItemUidList(TRUE),
88  'type' => 'static',
89  'table_name' => $this->getItemTableName()
90  );
91  }
92 
99  public function add($data) {
100  $this->storage->push($data);
101  }
102 
109  public function addAll(\TYPO3\CMS\Core\Collection\CollectionInterface $other) {
110  foreach ($other as $value) {
111  $this->add($value);
112  }
113  }
114 
123  public function remove($data) {
124  $offset = 0;
125  foreach ($this->storage as $value) {
126  if ($value == $data) {
127  break;
128  }
129  $offset++;
130  }
131  $this->storage->offsetUnset($offset);
132  }
133 
141  public function removeAll() {
142  $this->storage = new \SplDoublyLinkedList();
143  }
144 
152  protected function getCollectedRecords() {
153  $relatedRecords = array();
154  $resource = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query($this->getItemTableName() . '.*', self::$storageTableName, 'sys_collection_entries', $this->getItemTableName(), 'AND ' . self::$storageTableName . '.uid=' . (int)$this->getIdentifier());
155  if ($resource) {
156  while ($record = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resource)) {
157  $relatedRecords[] = $record;
158  }
159  $GLOBALS['TYPO3_DB']->sql_free_result($resource);
160  }
161  return $relatedRecords;
162  }
163 
164 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static create(array $collectionRecord, $fillItems=FALSE)
addAll(\TYPO3\CMS\Core\Collection\CollectionInterface $other)