Skip to content

Commit 4856a40

Browse files
committed
file model docs
1 parent 9b9fa04 commit 4856a40

File tree

1 file changed

+150
-32
lines changed

1 file changed

+150
-32
lines changed

docs/development/models/file.md

Lines changed: 150 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,40 @@ lang: php
1313

1414
# File Model
1515

16-
**class `ExpressionEngine\Model\File\File`**
16+
In ExpressionEngine 7 the `File` model is inheriting `FileSystemEntity` model, which is also parent of `Directory` model. They share same properties and most of the methods; different models are being used when there is need to distinguish between file and subfolder.
17+
18+
We recommend using `FileSystemEntity` when you need everything that is in certain Upload Directory, and use `File` or `Directory` when working specifically with files or folders within Upload Directory. When saving, always the exact model (`File` or `Directory`) needs to be used.
19+
20+
## `FileSystemEntity`
21+
22+
**class `ExpressionEngine\Model\File\FileSystemEntity`**
1723

1824
[TOC]
1925

20-
## Properties
21-
22-
- `file_id` Key
23-
- `site_id`
24-
- `title`
25-
- `upload_location_id`
26-
- `mime_type`
27-
- `file_name`
28-
- `file_size`
29-
- `description`
30-
- `credit`
31-
- `location`
32-
- `uploaded_by_member_id`
33-
- `upload_date`
34-
- `modified_by_member_id`
35-
- `modified_date`
36-
- `file_hw_original`
37-
38-
## Relationships
26+
### Properties
27+
28+
| Name | Validation | Type | Description |
29+
| ------------------- | -------------------- | ---------- | --------------- |
30+
| `file_id` Key | | | Primary ID of file or subfolder |
31+
| `site_id` | | | MSM site ID, default is 1 |
32+
| `title` | `xss` | | Title (can be different from file name, often used for alt text) |
33+
| `upload_location_id`| | | ID of Upload Directory that the file is in |
34+
| `directory_id` | | | Sobfolder ID, if file is in subfolder |
35+
| `mime_type` | | | Registered MIME type for the file. |
36+
| `file_type` | | | File type. The built-in types are Image / Document / Archive / Audio / Video |
37+
| `file_name` | | | Name of file on filesystem |
38+
| `file_size` | | | File size |
39+
| `description` | `xss` | | Description |
40+
| `credit` | `xss` | | Credits |
41+
| `location` | `xss` | | Location where the photo was made |
42+
| `uploaded_by_member_id`| | | ID of member who initially uploaded the file |
43+
| `upload_date` | | | Date when file was initially uploaded |
44+
| `modified_by_member_id`| | | ID of member who made last modification to the file |
45+
| `modified_date` | | | Date when file was modified last time |
46+
| `file_hw_original` | | | Height and width of the file when it was originally uploaded |
47+
| `total_records` | | | Number of times the file is being used in entries & categories |
48+
49+
### Relationships
3950

4051
#### `UploadDestination`
4152

@@ -57,23 +68,130 @@ Selected categories the file has.
5768

5869
The site the file is apart of.
5970

71+
#### `FileCategories`
72+
73+
Categories that are using this file as category image
74+
75+
#### `FileEntries`
76+
77+
Entries that are using this file
78+
6079
## Methods
6180

62-
- `isImage`
63-
- `isEditableImage`
64-
- `isSVG`
65-
- `getAbsolutePath`
66-
- `getAbsoluteThumbnailPath`
67-
- `getAbsoluteURL`
68-
- `getAbsoluteThumbnailURL`
69-
- `memberHasAccess`
70-
- `exists`
71-
- `isWritable`
72-
- `setCategoriesFromPost`
81+
#### `isFile()`
82+
83+
Returns `true` is entity is `File`, `false` otherwise
84+
85+
#### `isDirectory()`
86+
87+
Returns `true` is entity is `Directory` (subfolder), `false` otherwise
88+
89+
#### `isImage()`
90+
91+
Uses the file's mime-type to determine if the file is an image or not.
92+
93+
#### `isEditableImage()`
94+
95+
Uses the file's mime-type to determine if the file is an editable image or not.
96+
97+
#### `isSVG()`
98+
99+
Uses the file's mime-type to determine if the file is an SVG or not.
100+
101+
#### `getFilesystem()`
102+
103+
Get Filesystem object for the file's Upload Directory
104+
105+
#### `getSubfoldersPath()`
106+
107+
Get the subfolder path to the given file
108+
109+
#### `getBaseServerPath()`
110+
111+
Get base server path for file's upload location
112+
113+
#### `getBaseUrl()`
114+
115+
Get base url for upload location and folder
116+
117+
#### `getAbsolutePath()`
118+
119+
Get abolute path to the file on the filesystem
120+
121+
#### `getAbsoluteManipulationPath($manipulation = 'thumbs')`
122+
123+
Get absolute path to the file's pre-manipulated version on the filesystem. Accepts manipulation name as parameter
124+
125+
#### `getAbsoluteThumbnailPath()`
126+
127+
Uses the file's upload destination's server path to compute the absolute thumbnail path of the file
73128

74-
## Events
129+
#### `getAbsoluteURL()`
130+
131+
Uses the file's upload destination's url to compute the absolute URL of the file
132+
133+
#### `getAbsoluteManipulationURL($manipulation = 'thumbs')`
134+
135+
Get URL for pre-manupuilated file version. Accepts manipulation name as parameter
136+
137+
#### `getAbsoluteThumbnailURL()`
138+
139+
Get URL of file's thumbnail
140+
141+
#### `getThumbnailUrl()`
142+
143+
Alias of `getAbsoluteThumbnailURL`
144+
145+
#### `deleteOriginalFile()`
146+
147+
Deletes the original file
148+
149+
#### `deleteGeneratedFiles()`
150+
151+
Deletes the file's manipulated versions
152+
153+
#### `deleteAllFiles()`
154+
155+
Deletes the original file and all of its manipulated versions
156+
157+
#### `memberHasAccess(Member $member)`
158+
159+
Determines if the member has access permission to file's upload destination.
160+
161+
#### `exists()`
162+
163+
Determines if the file exists
164+
165+
#### `isWritable()`
166+
167+
Determines if the file or subfolder is writable
168+
169+
#### `getChildIds()`
170+
171+
Get an array of IDs for files and folders that belong to this `FileSystemEntity`
172+
173+
#### `actLocally(callable $callback)`
174+
175+
Perform some action on the file in a local context
176+
177+
### Events
75178

76179
- `beforeDelete`
180+
- `beforeInsert`
181+
- `beforeSave`
182+
183+
## `File`
184+
185+
**class `ExpressionEngine\Model\File\File`**
186+
187+
Represents a file. Child of `FileSystemEntity` and is sharing all of it's properties and methods.
188+
Defines some extra necessary
189+
190+
## `Directory`
191+
192+
**class `ExpressionEngine\Model\File\Directory`**
193+
194+
Represents a folder. Child of `FileSystemEntity` and is sharing all of it's properties and methods. Has extra
77195

78196
## Examples
79197

0 commit comments

Comments
 (0)