1 | <?php |
||
36 | class File extends \yii\db\ActiveRecord |
||
37 | { |
||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | public $path; |
||
42 | /** |
||
43 | * @var Storage |
||
44 | */ |
||
45 | private $storage; |
||
46 | |||
47 | /** |
||
48 | * @inheritdoc |
||
49 | * @codeCoverageIgnore |
||
50 | */ |
||
51 | public static function tableName() |
||
55 | |||
56 | /** |
||
57 | * @inheritdoc |
||
58 | * @codeCoverageIgnore |
||
59 | */ |
||
60 | public function attributeLabels() |
||
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | 38 | public function behaviors() |
|
93 | |||
94 | /** |
||
95 | * @inheritdoc |
||
96 | * @codeCoverageIgnore |
||
97 | */ |
||
98 | public function events() |
||
104 | |||
105 | 35 | public function beforeSave($insert) |
|
131 | |||
132 | 35 | public function setStorage(Storage $storage) |
|
139 | |||
140 | 36 | public function getStorage() |
|
148 | |||
149 | /** |
||
150 | * Generate a name |
||
151 | * |
||
152 | * @return string |
||
153 | */ |
||
154 | 34 | public function generateName() |
|
159 | |||
160 | /** |
||
161 | * Is it protected? |
||
162 | * |
||
163 | * @return bool |
||
164 | */ |
||
165 | 35 | public function isProtected() |
|
169 | |||
170 | /** |
||
171 | * Is it unprotected? |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | 5 | public function isUnprotected() |
|
179 | |||
180 | /** |
||
181 | * Is it tmp a file? |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | 6 | public function isTmp() |
|
189 | |||
190 | /** |
||
191 | * Get date create of file in format `Ym` |
||
192 | * |
||
193 | * @return string |
||
194 | */ |
||
195 | 34 | public function getDateOfFile() |
|
203 | |||
204 | /** |
||
205 | * Check owner |
||
206 | * |
||
207 | * @param int $ownerId |
||
208 | * @param int $ownerType |
||
209 | * @return bool |
||
210 | */ |
||
211 | 26 | public function isOwner($ownerId, $ownerType) |
|
219 | |||
220 | /** |
||
221 | * Create a file |
||
222 | * |
||
223 | * @param string $path |
||
224 | * @param int $ownerId |
||
225 | * @param int $ownerType |
||
226 | * @param bool $temporary |
||
227 | * @param bool $protected |
||
228 | * @return File|bool |
||
229 | */ |
||
230 | 35 | public static function create($path, $ownerId, $ownerType, $temporary, $protected) |
|
245 | |||
246 | /** |
||
247 | * Find all by owner |
||
248 | * |
||
249 | * @param int $ownerId |
||
250 | * @param int $ownerType |
||
251 | * @return array |
||
252 | */ |
||
253 | 26 | public static function findAllByOwner($ownerId, $ownerType) |
|
260 | |||
261 | /** |
||
262 | * Find one by owner |
||
263 | * |
||
264 | * @param int $ownerId |
||
265 | * @param int $ownerType |
||
266 | * @return File |
||
267 | */ |
||
268 | 1 | public static function findOneByOwner($ownerId, $ownerType) |
|
274 | |||
275 | /** |
||
276 | * Delete by owner |
||
277 | * |
||
278 | * @param Storage $storage |
||
279 | * @param int $ownerId |
||
280 | * @param int $ownerType |
||
281 | */ |
||
282 | 4 | public function deleteByOwner($storage, $ownerId, $ownerType) |
|
291 | |||
292 | /** |
||
293 | * Deleting a file from the db and from the file system |
||
294 | * |
||
295 | * @return bool |
||
296 | */ |
||
297 | 11 | public function beforeDelete() |
|
302 | } |
||
303 |