‪TYPO3CMS  ‪main
ResourceView.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\CMS\Core\Imaging\IconSize;
28 
33 {
34  public ?string ‪$moduleUri;
35  public ?string ‪$editContentUri;
36  public ?string ‪$editDataUri;
37  public ?string ‪$replaceUri;
38 
39  public bool ‪$isDownloadable = true;
40  public bool ‪$isSelectable = true;
41  public bool ‪$isSelected = false;
42 
43  public function ‪__construct(
44  public readonly ‪ResourceInterface $resource,
45  public readonly ‪UserPermissions $userPermissions,
46  public readonly ‪Icon $icon
47  ) {}
48 
49  public function ‪getUid(): ?int
50  {
51  if ($this->resource instanceof ‪File) {
52  return $this->resource->getUid();
53  }
54 
55  return null;
56  }
57 
58  public function ‪getIdentifier(): string
59  {
60  return $this->resource->getStorage()->getUid() . ':' . $this->resource->getIdentifier();
61  }
62 
63  public function ‪getMetaDataUid(): ?int
64  {
65  if ($this->resource instanceof ‪File
66  && $this->‪canEditMetadata()) {
67  return (int)$this->resource->getMetaData()->offsetGet('uid');
68  }
69 
70  return null;
71  }
72 
73  public function ‪getType(): string
74  {
75  if ($this->resource instanceof ‪Folder) {
76  return 'folder';
77  }
78  if ($this->resource instanceof ‪File) {
79  return 'file';
80  }
81 
82  return 'resource';
83  }
84 
85  public function ‪getName(): string
86  {
87  if ($this->resource instanceof ‪Folder) {
88  return ListUtility::resolveSpecialFolderName($this->resource);
89  }
90 
91  return $this->resource->getName();
92  }
93 
94  public function ‪getPath(): string
95  {
96  $resource = $this->resource;
97  if ($resource instanceof ‪File && !$resource->‪isMissing()) {
98  $resource = $resource->getParentFolder();
99  }
100  if ($resource instanceof ‪Folder) {
101  return $resource->getReadablePath();
102  }
103 
104  return '';
105  }
106 
107  public function ‪getPublicUrl(): ?string
108  {
109  if (!$this->resource instanceof ‪File) {
110  return null;
111  }
112 
113  return $this->resource->getPublicUrl();
114  }
115 
116  public function ‪getPreview(): ?‪File
117  {
118  if ($this->resource instanceof ‪File
119  && ($this->resource->isImage() || $this->resource->isMediaFile())
120  ) {
121  return $this->resource;
122  }
123 
124  return null;
125  }
126 
127  public function ‪getThumbnailUri(): ?string
128  {
129  $preview = $this->‪getPreview();
130  if (!$preview) {
131  return null;
132  }
133 
134  return $preview
135  ->process(‪ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, ['width' => '32c', 'height' => '32c'])
136  ->getPublicUrl() ?? null;
137  }
138 
139  public function ‪getIconIdentifier(): string
140  {
141  return $this->icon->getIdentifier();
142  }
143 
144  public function ‪getIconSmall(): ‪Icon
145  {
146  $icon = clone $this->icon;
147  $icon->‪setSize(IconSize::SMALL);
148 
149  return $icon;
150  }
151 
152  public function ‪getIconMedium(): ‪Icon
153  {
154  $icon = clone $this->icon;
155  $icon->‪setSize(IconSize::MEDIUM);
156 
157  return $icon;
158  }
159 
160  public function ‪getIconLarge(): ‪Icon
161  {
162  $icon = clone $this->icon;
163  $icon->‪setSize(IconSize::LARGE);
164 
165  return $icon;
166  }
167 
168  public function ‪getCreatedAt(): ?int
169  {
170  if ($this->resource instanceof ‪File) {
171  return $this->resource->getCreationTime();
172  }
173  if ($this->resource instanceof ‪Folder) {
174  return $this->resource->getCreationTime();
175  }
176 
177  return null;
178  }
179 
180  public function ‪getUpdatedAt(): ?int
181  {
182  if ($this->resource instanceof ‪File) {
183  return $this->resource->getModificationTime();
184  }
185  if ($this->resource instanceof ‪Folder) {
186  return $this->resource->getModificationTime();
187  }
188 
189  return null;
190  }
191 
192  public function ‪getCheckboxConfig(): ?array
193  {
194  if (($this->resource instanceof ‪Folder || $this->resource instanceof ‪File)
195  && !$this->resource->checkActionPermission('read')) {
196  return null;
197  }
198 
199  return [
200  'class' => 't3js-multi-record-selection-check',
201  'name' => 'CBC[_FILE|' . md5($this->‪getIdentifier()) . ']',
202  'value' => $this->‪getIdentifier(),
203  'checked' => ‪$this->isSelected,
204  ];
205  }
206 
207  public function ‪isMissing(): ?bool
208  {
209  if ($this->resource instanceof ‪File) {
210  return $this->resource->isMissing();
211  }
212 
213  return null;
214  }
215 
216  public function ‪isLocked(): bool
217  {
218  if ($this->resource instanceof ‪InaccessibleFolder) {
219  return true;
220  }
221 
222  return false;
223  }
224 
225  public function ‪canEditMetadata(): bool
226  {
227  return $this->resource instanceof ‪File
228  && $this->resource->‪isIndexed()
229  && $this->resource->checkActionPermission('editMeta')
230  && $this->userPermissions->editMetaData;
231  }
232 
233  public function ‪canRead(): ?bool
234  {
235  if ($this->resource instanceof ‪File || $this->resource instanceof ‪Folder) {
236  return $this->resource->checkActionPermission('read');
237  }
238 
239  return null;
240  }
241 
242  public function ‪canWrite(): ?bool
243  {
244  if ($this->resource instanceof ‪File || $this->resource instanceof ‪Folder) {
245  return $this->resource->checkActionPermission('write');
246  }
247 
248  return null;
249  }
250 
251  public function ‪canDelete(): ?bool
252  {
253  if ($this->resource instanceof ‪File || $this->resource instanceof ‪Folder) {
254  return $this->resource->checkActionPermission('delete');
255  }
256 
257  return null;
258  }
259 
260  public function ‪canCopy(): ?bool
261  {
262  if ($this->resource instanceof ‪File || $this->resource instanceof ‪Folder) {
263  return $this->resource->checkActionPermission('copy');
264  }
265 
266  return null;
267  }
268 
269  public function ‪canRename(): ?bool
270  {
271  if ($this->resource instanceof ‪File || $this->resource instanceof ‪Folder) {
272  return $this->resource->checkActionPermission('rename');
273  }
274 
275  return null;
276  }
277 
278  public function ‪canMove(): ?bool
279  {
280  if ($this->resource instanceof ‪File || $this->resource instanceof ‪Folder) {
281  return $this->resource->checkActionPermission('move');
282  }
283 
284  return null;
285  }
286 }
‪TYPO3\CMS\Filelist\Dto\UserPermissions
Definition: UserPermissions.php:24
‪TYPO3\CMS\Core\Imaging\Icon\setSize
‪setSize(string|IconSize $size)
Definition: Icon.php:193
‪TYPO3\CMS\Filelist\Dto\ResourceView\$isSelectable
‪bool $isSelectable
Definition: ResourceView.php:40
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Filelist\Dto\ResourceView\$replaceUri
‪string $replaceUri
Definition: ResourceView.php:37
‪TYPO3\CMS\Filelist\Dto\ResourceView\isMissing
‪isMissing()
Definition: ResourceView.php:207
‪TYPO3\CMS\Filelist\Dto\ResourceView\getType
‪getType()
Definition: ResourceView.php:73
‪TYPO3\CMS\Core\Resource\ProcessedFile\CONTEXT_IMAGECROPSCALEMASK
‪const CONTEXT_IMAGECROPSCALEMASK
Definition: ProcessedFile.php:61
‪TYPO3\CMS\Core\Resource\File\isIndexed
‪isIndexed()
Definition: File.php:139
‪TYPO3\CMS\Filelist\Dto\ResourceView\getPublicUrl
‪getPublicUrl()
Definition: ResourceView.php:107
‪TYPO3\CMS\Filelist\Dto\ResourceView\$isDownloadable
‪bool $isDownloadable
Definition: ResourceView.php:39
‪TYPO3\CMS\Filelist\Dto\ResourceView\getUpdatedAt
‪getUpdatedAt()
Definition: ResourceView.php:180
‪TYPO3\CMS\Filelist\Dto\ResourceView\__construct
‪__construct(public readonly ResourceInterface $resource, public readonly UserPermissions $userPermissions, public readonly Icon $icon)
Definition: ResourceView.php:43
‪TYPO3\CMS\Filelist\Dto\ResourceView\getCheckboxConfig
‪getCheckboxConfig()
Definition: ResourceView.php:192
‪TYPO3\CMS\Core\Resource\Utility\ListUtility
Definition: ListUtility.php:26
‪TYPO3\CMS\Filelist\Dto\ResourceView\canDelete
‪canDelete()
Definition: ResourceView.php:251
‪TYPO3\CMS\Filelist\Dto\ResourceView\getThumbnailUri
‪getThumbnailUri()
Definition: ResourceView.php:127
‪TYPO3\CMS\Core\Resource\InaccessibleFolder
Definition: InaccessibleFolder.php:30
‪TYPO3\CMS\Filelist\Dto\ResourceView\getIconMedium
‪getIconMedium()
Definition: ResourceView.php:152
‪TYPO3\CMS\Filelist\Dto\ResourceView\$moduleUri
‪string $moduleUri
Definition: ResourceView.php:34
‪TYPO3\CMS\Filelist\Dto\ResourceView\$isSelected
‪bool $isSelected
Definition: ResourceView.php:41
‪TYPO3\CMS\Filelist\Dto\ResourceView
Definition: ResourceView.php:33
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:38
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Filelist\Dto\ResourceView\canRename
‪canRename()
Definition: ResourceView.php:269
‪TYPO3\CMS\Filelist\Dto\ResourceView\getIconIdentifier
‪getIconIdentifier()
Definition: ResourceView.php:139
‪TYPO3\CMS\Filelist\Dto\ResourceView\getName
‪getName()
Definition: ResourceView.php:85
‪TYPO3\CMS\Filelist\Dto\ResourceView\getPreview
‪getPreview()
Definition: ResourceView.php:116
‪TYPO3\CMS\Filelist\Dto\ResourceView\getUid
‪getUid()
Definition: ResourceView.php:49
‪TYPO3\CMS\Filelist\Dto\ResourceView\getIdentifier
‪getIdentifier()
Definition: ResourceView.php:58
‪TYPO3\CMS\Filelist\Dto\ResourceView\getMetaDataUid
‪getMetaDataUid()
Definition: ResourceView.php:63
‪TYPO3\CMS\Filelist\Dto\ResourceView\getCreatedAt
‪getCreatedAt()
Definition: ResourceView.php:168
‪TYPO3\CMS\Filelist\Dto
Definition: PaginationLink.php:18
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:47
‪TYPO3\CMS\Filelist\Dto\ResourceView\canRead
‪canRead()
Definition: ResourceView.php:233
‪TYPO3\CMS\Filelist\Dto\ResourceView\isLocked
‪isLocked()
Definition: ResourceView.php:216
‪TYPO3\CMS\Filelist\Dto\ResourceView\canEditMetadata
‪canEditMetadata()
Definition: ResourceView.php:225
‪TYPO3\CMS\Core\Resource\ResourceInterface
Definition: ResourceInterface.php:21
‪TYPO3\CMS\Filelist\Dto\ResourceView\canCopy
‪canCopy()
Definition: ResourceView.php:260
‪TYPO3\CMS\Filelist\Dto\ResourceView\canMove
‪canMove()
Definition: ResourceView.php:278
‪TYPO3\CMS\Filelist\Dto\ResourceView\getIconLarge
‪getIconLarge()
Definition: ResourceView.php:160
‪TYPO3\CMS\Filelist\Dto\ResourceView\canWrite
‪canWrite()
Definition: ResourceView.php:242
‪TYPO3\CMS\Filelist\Dto\ResourceView\$editContentUri
‪string $editContentUri
Definition: ResourceView.php:35
‪TYPO3\CMS\Filelist\Dto\ResourceView\getPath
‪getPath()
Definition: ResourceView.php:94
‪TYPO3\CMS\Core\Resource\File\isMissing
‪bool isMissing()
Definition: File.php:281
‪TYPO3\CMS\Filelist\Dto\ResourceView\getIconSmall
‪getIconSmall()
Definition: ResourceView.php:144
‪TYPO3\CMS\Filelist\Dto\ResourceView\$editDataUri
‪string $editDataUri
Definition: ResourceView.php:36