1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
FileInfo.php
См. документацию.
1<?php
2
3namespace Bitrix\UI\FileUploader;
4
5use Bitrix\Main\Type\Dictionary;
6
7class FileInfo extends FileData implements \JsonSerializable
8{
9 protected $id;
10 protected int $fileId = 0;
11 protected bool $treatImageAsFile = false;
12 protected ?string $downloadUrl = null;
13 protected ?string $previewUrl = null;
14 protected int $previewWidth = 0;
15 protected int $previewHeight = 0;
16 protected ?Dictionary $customData = null;
17 protected ?Dictionary $viewerAttrs = null;
18
25 public function __construct($id, string $name, string $contentType, int $size)
26 {
27 parent::__construct($name, $contentType, $size);
28 $this->id = $id;
29 }
30
31 public static function createFromBFile(int $id): ?FileInfo
32 {
33 $file = \CFile::getFileArray($id);
34 if (!is_array($file))
35 {
36 return null;
37 }
38
39 $fileName = !empty($file['ORIGINAL_NAME']) ? $file['ORIGINAL_NAME'] : $file['FILE_NAME'];
40 $fileInfo = new static($id, $fileName, $file['CONTENT_TYPE'], (int)$file['FILE_SIZE']);
41 $fileInfo->setWidth($file['WIDTH']);
42 $fileInfo->setHeight($file['HEIGHT']);
43 $fileInfo->setFileId($id);
44
45 return $fileInfo;
46 }
47
48 public static function createFromTempFile(string $tempFileId): ?FileInfo
49 {
50 [$guid, $signature] = explode('.', $tempFileId);
51
52 $tempFile = TempFileTable::getList([
53 'filter' => [
54 '=GUID' => $guid,
55 '=UPLOADED' => true,
56 ],
57 ])->fetchObject();
58
59 if (!$tempFile)
60 {
61 return null;
62 }
63
64 $fileInfo = new static($tempFileId, $tempFile->getFilename(), $tempFile->getMimetype(), $tempFile->getSize());
65 $fileInfo->setWidth($tempFile->getWidth());
66 $fileInfo->setHeight($tempFile->getHeight());
67 $fileInfo->setFileId($tempFile->getFileId());
68
69 return $fileInfo;
70 }
71
75 public function getId()
76 {
77 return $this->id;
78 }
79
80 public function setId($id): void
81 {
82 if (is_int($id) || is_string($id))
83 {
84 $this->id = $id;
85 }
86 }
87
88 public function getFileId(): int
89 {
90 return $this->fileId;
91 }
92
93 public function setFileId(int $fileId): void
94 {
95 $this->fileId = $fileId;
96 }
97
98 public function shouldTreatImageAsFile(): bool
99 {
101 }
102
103 public function setTreatImageAsFile(bool $flag): void
104 {
105 $this->treatImageAsFile = $flag;
106 }
107
108 public function getDownloadUrl(): ?string
109 {
110 return $this->downloadUrl;
111 }
112
113 public function setDownloadUrl(string $downloadUrl): void
114 {
115 $this->downloadUrl = $downloadUrl;
116 }
117
118 public function getPreviewUrl(): ?string
119 {
120 return $this->previewUrl;
121 }
122
123 public function setPreviewUrl(string $previewUrl, int $previewWidth, int $previewHeight): void
124 {
125 $this->previewUrl = $previewUrl;
126 $this->previewWidth = $previewWidth;
127 $this->previewHeight = $previewHeight;
128 }
129
130 public function getPreviewWidth(): int
131 {
132 return $this->previewWidth;
133 }
134
135 public function getPreviewHeight(): int
136 {
138 }
139
140 public function setCustomData(array $customData): self
141 {
142 $this->getCustomData()->setValues($customData);
143
144 return $this;
145 }
146
150 public function getCustomData(): Dictionary
151 {
152 if ($this->customData === null)
153 {
154 $this->customData = new Dictionary();
155 }
156
157 return $this->customData;
158 }
159
160 public function setViewerAttrs(array $viewerAttrs): self
161 {
162 $this->getViewerAttrs()->setValues($viewerAttrs);
163
164 return $this;
165 }
166
167 public function getViewerAttrs(): Dictionary
168 {
169 if ($this->viewerAttrs === null)
170 {
171 $this->viewerAttrs = new Dictionary();
172 }
173
174 return $this->viewerAttrs;
175 }
176
177 public function jsonSerialize(): array
178 {
179 return [
180 'serverFileId' => $this->getId(),
181 'serverId' => $this->getId(), // compatibility
182 'type' => $this->getContentType(),
183 'name' => $this->getName(),
184 'size' => $this->getSize(),
185 'width' => $this->getWidth(),
186 'height' => $this->getHeight(),
187 'isImage' => $this->isImage(),
188 'isVideo' => $this->isVideo(),
189 'treatImageAsFile' => $this->isImage() && $this->shouldTreatImageAsFile(),
190 'downloadUrl' => $this->getDownloadUrl(),
191 'serverPreviewUrl' => $this->getPreviewUrl(),
192 'serverPreviewWidth' => $this->getPreviewWidth(),
193 'serverPreviewHeight' => $this->getPreviewHeight(),
194 'customData' => $this->customData !== null ? $this->getCustomData()->getValues() : [],
195 'viewerAttrs' => $this->viewerAttrs !== null ? $this->getViewerAttrs()->getValues() : [],
196 ];
197 }
198}
static getList(array $parameters=array())
Определения datamanager.php:431
string $contentType
Определения FileData.php:8
string $name
Определения FileData.php:7
int $previewWidth
Определения FileInfo.php:14
Dictionary $customData
Определения FileInfo.php:16
setDownloadUrl(string $downloadUrl)
Определения FileInfo.php:113
__construct($id, string $name, string $contentType, int $size)
Определения FileInfo.php:25
static createFromTempFile(string $tempFileId)
Определения FileInfo.php:48
static createFromBFile(int $id)
Определения FileInfo.php:31
setViewerAttrs(array $viewerAttrs)
Определения FileInfo.php:160
string $downloadUrl
Определения FileInfo.php:12
shouldTreatImageAsFile()
Определения FileInfo.php:98
setTreatImageAsFile(bool $flag)
Определения FileInfo.php:103
string $previewUrl
Определения FileInfo.php:13
Dictionary $viewerAttrs
Определения FileInfo.php:17
bool $treatImageAsFile
Определения FileInfo.php:11
int $previewHeight
Определения FileInfo.php:15
setCustomData(array $customData)
Определения FileInfo.php:140
setFileId(int $fileId)
Определения FileInfo.php:93
setPreviewUrl(string $previewUrl, int $previewWidth, int $previewHeight)
Определения FileInfo.php:123
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$fileName
Определения quickway.php:305