TYPO3 CMS  TYPO3_7-6
FolderBasedFileCollection.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 
18 
24 {
28  protected static $storageTableName = 'sys_file_collection';
29 
33  protected static $type = 'folder';
34 
38  protected static $itemsCriteriaField = 'folder';
39 
45  protected $folder;
46 
50  protected $recursive;
51 
64  public function loadContents()
65  {
66  if ($this->folder instanceof Folder) {
67  $entries = $this->folder->getFiles(0, 0, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $this->recursive);
68  foreach ($entries as $entry) {
69  $this->add($entry);
70  }
71  }
72  }
73 
79  public function getItemsCriteria()
80  {
81  return $this->folder->getCombinedIdentifier();
82  }
83 
90  protected function getPersistableDataArray()
91  {
92  return [
93  'title' => $this->getTitle(),
94  'type' => self::$type,
95  'description' => $this->getDescription(),
96  'folder' => $this->folder->getIdentifier(),
97  'storage' => $this->folder->getStorage()->getUid()
98  ];
99  }
100 
108  public function fromArray(array $array)
109  {
110  $this->uid = $array['uid'];
111  $this->title = $array['title'];
112  $this->description = $array['description'];
113  $this->recursive = (bool)$array['recursive'];
114  if (!empty($array['folder']) && !empty($array['storage'])) {
116  $storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
118  $storage = $storageRepository->findByUid($array['storage']);
119  if ($storage) {
120  $this->folder = $storage->getFolder($array['folder']);
121  }
122  }
123  }
124 }
add(\TYPO3\CMS\Core\Resource\FileInterface $data)
const FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS
Definition: Folder.php:68