|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the package lns/digital-asset-management. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please read the |
|
8
|
|
|
* LICENSE file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace TYPO3\CMS\DigitalAssetManagement\Entity; |
|
12
|
|
|
|
|
13
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
14
|
|
|
use TYPO3\CMS\Core\Resource\Folder; |
|
15
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
16
|
|
|
use TYPO3\CMS\Core\Utility\PathUtility; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Immutable folder object, used by getFolderItemsAction(). |
|
20
|
|
|
* |
|
21
|
|
|
* @see FolderItemFile |
|
22
|
|
|
* @see FolderItemImage |
|
23
|
|
|
*/ |
|
24
|
|
|
class FolderItemFolder implements \JsonSerializable |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var string Always set to "folder" |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $type = 'folder'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var int FAL identifier, eg. "42:/path/to/folder" |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $identifier; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string Folder name, not full path, eg. "myFolder" |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $name; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var int Folder modification timestamp, eg. 1553705583 |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $mtime; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string $mtime formatted for display, eg. "30.02.2042" |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $mtimeDisplay; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var int Number of sub items (folders, files, images), eg. 5 |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $itemCount; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var FolderPermission Entity representing access permissions |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $permissions; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Path to folder icon, relative to document root with leading slash, eg. |
|
63
|
|
|
* "/typo3conf/ext/digital_asset_management/Resources/Public/Images/empty.png" |
|
64
|
|
|
* |
|
65
|
|
|
* @var string |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $icon; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param Folder $folder |
|
71
|
|
|
*/ |
|
72
|
|
|
public function __construct(Folder $folder) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->identifier = $folder->getCombinedIdentifier(); |
|
|
|
|
|
|
75
|
|
|
$this->name = $folder->getName(); |
|
76
|
|
|
$this->mtime = $folder->getModificationTime(); |
|
77
|
|
|
$this->mtimeDisplay = BackendUtility::date($this->mtime) ?? ''; |
|
78
|
|
|
$this->itemCount = $folder->getFileCount() + count($folder->getSubfolders()); |
|
79
|
|
|
$this->permissions = new FolderPermission($folder); |
|
80
|
|
|
$this->icon = PathUtility::getAbsoluteWebPath( |
|
81
|
|
|
GeneralUtility::getFileAbsFileName('EXT:digital_asset_management/Resources/Public/Images/empty.png') |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function jsonSerialize() |
|
86
|
|
|
{ |
|
87
|
|
|
return [ |
|
88
|
|
|
'type' => $this->type, |
|
89
|
|
|
'identifier' => $this->identifier, |
|
90
|
|
|
'name' => $this->name, |
|
91
|
|
|
'mtime' => $this->mtime, |
|
92
|
|
|
'mtimeDisplay' => $this->mtimeDisplay, |
|
93
|
|
|
'itemCount' => $this->itemCount, |
|
94
|
|
|
'permissions' => $this->permissions, |
|
95
|
|
|
'icon' => $this->icon, |
|
96
|
|
|
]; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.