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