TYPO3 CMS  TYPO3_7-6
AbstractFileCollection.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 {
27  protected static $storageTableName = 'sys_file_collection';
28 
35  protected static $type;
36 
43  protected static $itemsCriteriaField;
44 
51  protected $itemsCriteria;
52 
58  protected $itemTableName = 'sys_file';
59 
65  public function setDescription($description)
66  {
67  $this->description = $description;
68  }
69 
75  public function setTitle($title)
76  {
77  $this->title = $title;
78  }
79 
85  public function key()
86  {
88  $currentRecord = $this->storage->current();
89  return $currentRecord->getIdentifier();
90  }
91 
98  protected function getItemUidList($includeTableName = false)
99  {
100  $list = [];
102  foreach ($this->storage as $entry) {
103  $list[] = $this->getItemTableName() . '_' . $entry->getUid();
104  }
105  return implode(',', $list);
106  }
107 
114  protected function getPersistableDataArray()
115  {
116  return [
117  'title' => $this->getTitle(),
118  'type' => static::$type,
119  'description' => $this->getDescription(),
120  static::$itemsCriteriaField => $this->getItemsCriteria()
121  ];
122  }
123 
130  public function toArray()
131  {
132  $itemArray = [];
134  foreach ($this->storage as $item) {
135  $itemArray[] = $item->toArray();
136  }
137  return [
138  'uid' => $this->getIdentifier(),
139  'title' => $this->getTitle(),
140  'description' => $this->getDescription(),
141  'items' => $itemArray
142  ];
143  }
144 
150  public function getItems()
151  {
152  $itemArray = [];
154  foreach ($this->storage as $item) {
155  $itemArray[] = $item;
156  }
157  return $itemArray;
158  }
159 
167  public function fromArray(array $array)
168  {
169  $this->uid = $array['uid'];
170  $this->title = $array['title'];
171  $this->description = $array['description'];
172  $this->itemsCriteria = $array[static::$itemsCriteriaField];
173  }
174 
180  public function getItemsCriteria()
181  {
182  return $this->itemsCriteria;
183  }
184 
191  {
192  $this->itemsCriteria = $itemsCriteria;
193  }
194 
200  public function add(\TYPO3\CMS\Core\Resource\FileInterface $data)
201  {
202  $this->storage->push($data);
203  }
204 
210  public function addAll(\TYPO3\CMS\Core\Collection\CollectionInterface $other)
211  {
213  foreach ($other as $value) {
214  $this->add($value);
215  }
216  }
217 
223  public function remove(\TYPO3\CMS\Core\Resource\File $file)
224  {
225  $offset = 0;
227  foreach ($this->storage as $value) {
228  if ($value === $file) {
229  break;
230  }
231  $offset++;
232  }
233  $this->storage->offsetUnset($offset);
234  }
235 
239  public function removeAll()
240  {
241  $this->storage = new \SplDoublyLinkedList();
242  }
243 }
add(\TYPO3\CMS\Core\Resource\FileInterface $data)