[BUGFIX] FAL: Image Processing doesn't respect GFX "thumbnails_png"
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Collection / AbstractFileCollection.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Collection;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Steffen Ritter <steffen.ritter@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Abstract collection.
31 *
32 * @author Steffen Ritter <steffen.ritter@typo3.org>
33 */
34 abstract class AbstractFileCollection extends \TYPO3\CMS\Core\Collection\AbstractRecordCollection {
35
36 /**
37 * The table name collections are stored to
38 *
39 * @var string
40 */
41 static protected $storageTableName = 'sys_file_collection';
42
43 /**
44 * The type of file collection
45 * (see \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE constants)
46 *
47 * @var string
48 */
49 static protected $type;
50
51 /**
52 * The name of the field items are handled with
53 * (usually either criteria, items or folder)
54 *
55 * @var string
56 */
57 static protected $itemsCriteriaField;
58
59 /**
60 * Field contents of $itemsCriteriaField. Defines which the items or search criteria for the items
61 * depending on the type (see self::$type above) of this file collection.
62 *
63 * @var mixed
64 */
65 protected $itemsCriteria;
66
67 /**
68 * Name of the table records of this collection are stored in
69 *
70 * @var string
71 */
72 protected $itemTableName = 'sys_file';
73
74 /**
75 * Sets the description.
76 *
77 * @param string $description
78 */
79 public function setDescription($description) {
80 $this->description = $description;
81 }
82
83 /**
84 * Sets the title.
85 *
86 * @param string $title
87 */
88 public function setTitle($title) {
89 $this->title = $title;
90 }
91
92 /**
93 * Return the key of the current element
94 *
95 * @return string
96 */
97 public function key() {
98 /** @var $currentRecord \TYPO3\CMS\Core\Resource\File */
99 $currentRecord = $this->storage->current();
100 return $currentRecord->getIdentifier();
101 }
102
103 /**
104 * Generates comma-separated list of entry uids for usage in TCEmain
105 *
106 * @param boolean $includeTableName
107 * @return string
108 */
109 protected function getItemUidList($includeTableName = FALSE) {
110 $list = array();
111 /** @var $entry \TYPO3\CMS\Core\Resource\File */
112 foreach ($this->storage as $entry) {
113 $list[] = $this->getItemTableName() . '_' . $entry->getUid();
114 }
115 return implode(',', $list);
116 }
117
118 /**
119 * Returns an array of the persistable properties and contents
120 * which are processable by TCEmain.
121 *
122 * @return array
123 */
124 protected function getPersistableDataArray() {
125 return array(
126 'title' => $this->getTitle(),
127 'type' => static::$type,
128 'description' => $this->getDescription(),
129 static::$itemsCriteriaField => $this->getItemsCriteria()
130 );
131 }
132
133 /**
134 * Similar to method in \TYPO3\CMS\Core\Collection\AbstractRecordCollection,
135 * but without 'table_name' => $this->getItemTableName()
136 *
137 * @return array
138 */
139 public function toArray() {
140 $itemArray = array();
141 /** @var $item \TYPO3\CMS\Core\Resource\File */
142 foreach ($this->storage as $item) {
143 $itemArray[] = $item->toArray();
144 }
145 return array(
146 'uid' => $this->getIdentifier(),
147 'title' => $this->getTitle(),
148 'description' => $this->getDescription(),
149 'items' => $itemArray
150 );
151 }
152
153 /**
154 * Gets the current available items.
155 *
156 * @return array
157 */
158 public function getItems() {
159 $itemArray = array();
160 /** @var $item \TYPO3\CMS\Core\Resource\File */
161 foreach ($this->storage as $item) {
162 $itemArray[] = $item;
163 }
164 return $itemArray;
165 }
166
167 /**
168 * Similar to method in \TYPO3\CMS\Core\Collection\AbstractRecordCollection,
169 * but without $this->itemTableName= $array['table_name'],
170 * but with $this->storageItemsFieldContent = $array[self::$storageItemsField];
171 *
172 * @param array $array
173 */
174 public function fromArray(array $array) {
175 $this->uid = $array['uid'];
176 $this->title = $array['title'];
177 $this->description = $array['description'];
178 $this->itemsCriteria = $array[static::$itemsCriteriaField];
179 }
180
181 /**
182 * Gets ths items criteria.
183 *
184 * @return mixed
185 */
186 public function getItemsCriteria() {
187 return $this->itemsCriteria;
188 }
189
190 /**
191 * Sets the items criteria.
192 *
193 * @param mixed $itemsCriteria
194 */
195 public function setItemsCriteria($itemsCriteria) {
196 $this->itemsCriteria = $itemsCriteria;
197 }
198
199 /**
200 * Adds a file to this collection.
201 *
202 * @param \TYPO3\CMS\Core\Resource\FileInterface $data
203 */
204 public function add(\TYPO3\CMS\Core\Resource\FileInterface $data) {
205 $this->storage->push($data);
206 }
207
208 /**
209 * Adds all files of another collection to the corrent one.
210 *
211 * @param \TYPO3\CMS\Core\Collection\CollectionInterface $other
212 */
213 public function addAll(\TYPO3\CMS\Core\Collection\CollectionInterface $other) {
214 /** @var $value \TYPO3\CMS\Core\Resource\File */
215 foreach ($other as $value) {
216 $this->add($value);
217 }
218 }
219
220 /**
221 * Removes a file from this collection.
222 *
223 * @param \TYPO3\CMS\Core\Resource\File $file
224 */
225 public function remove(\TYPO3\CMS\Core\Resource\File $file) {
226 $offset = 0;
227 /** @var $value \TYPO3\CMS\Core\Resource\File */
228 foreach ($this->storage as $value) {
229 if ($value === $file) {
230 break;
231 }
232 $offset++;
233 }
234 $this->storage->offsetUnset($offset);
235 }
236
237 /**
238 * Removes all elements of the current collection.
239 */
240 public function removeAll() {
241 $this->storage = new \SplDoublyLinkedList();
242 }
243
244 }
245
246
247 ?>