TYPO3 CMS  TYPO3_6-2
AbstractFileCollection.php
Go to the documentation of this file.
1 <?php
3 
22 
28  static protected $storageTableName = 'sys_file_collection';
29 
36  static protected $type;
37 
44  static protected $itemsCriteriaField;
45 
52  protected $itemsCriteria;
53 
59  protected $itemTableName = 'sys_file';
60 
66  public function setDescription($description) {
67  $this->description = $description;
68  }
69 
75  public function setTitle($title) {
76  $this->title = $title;
77  }
78 
84  public function key() {
86  $currentRecord = $this->storage->current();
87  return $currentRecord->getIdentifier();
88  }
89 
96  protected function getItemUidList($includeTableName = FALSE) {
97  $list = array();
99  foreach ($this->storage as $entry) {
100  $list[] = $this->getItemTableName() . '_' . $entry->getUid();
101  }
102  return implode(',', $list);
103  }
104 
111  protected function getPersistableDataArray() {
112  return array(
113  'title' => $this->getTitle(),
114  'type' => static::$type,
115  'description' => $this->getDescription(),
116  static::$itemsCriteriaField => $this->getItemsCriteria()
117  );
118  }
119 
126  public function toArray() {
127  $itemArray = array();
129  foreach ($this->storage as $item) {
130  $itemArray[] = $item->toArray();
131  }
132  return array(
133  'uid' => $this->getIdentifier(),
134  'title' => $this->getTitle(),
135  'description' => $this->getDescription(),
136  'items' => $itemArray
137  );
138  }
139 
145  public function getItems() {
146  $itemArray = array();
148  foreach ($this->storage as $item) {
149  $itemArray[] = $item;
150  }
151  return $itemArray;
152  }
153 
161  public function fromArray(array $array) {
162  $this->uid = $array['uid'];
163  $this->title = $array['title'];
164  $this->description = $array['description'];
165  $this->itemsCriteria = $array[static::$itemsCriteriaField];
166  }
167 
173  public function getItemsCriteria() {
174  return $this->itemsCriteria;
175  }
176 
182  public function setItemsCriteria($itemsCriteria) {
183  $this->itemsCriteria = $itemsCriteria;
184  }
185 
191  public function add(\TYPO3\CMS\Core\Resource\FileInterface $data) {
192  $this->storage->push($data);
193  }
194 
200  public function addAll(\TYPO3\CMS\Core\Collection\CollectionInterface $other) {
202  foreach ($other as $value) {
203  $this->add($value);
204  }
205  }
206 
212  public function remove(\TYPO3\CMS\Core\Resource\File $file) {
213  $offset = 0;
215  foreach ($this->storage as $value) {
216  if ($value === $file) {
217  break;
218  }
219  $offset++;
220  }
221  $this->storage->offsetUnset($offset);
222  }
223 
227  public function removeAll() {
228  $this->storage = new \SplDoublyLinkedList();
229  }
230 
231 }
add(\TYPO3\CMS\Core\Resource\FileInterface $data)