file-collection.php
3 years ago
file-tools.php
3 years ago
file.php
3 years ago
media-block-value.php
3 years ago
sanitize-file-exception.php
3 years ago
upload-dir.php
3 years ago
upload-exception.php
3 years ago
upload-permission-exception.php
3 years ago
uploaded-collection.php
3 years ago
uploaded-file-path.php
3 years ago
uploaded-file.php
3 years ago
file-collection.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Classes\Resources; |
| 5 | |
| 6 | use Jet_Form_Builder\Classes\Arrayable\Collection; |
| 7 | |
| 8 | class File_Collection extends Collection implements Media_Block_Value { |
| 9 | |
| 10 | public function push( array $file ): bool { |
| 11 | try { |
| 12 | $file = new File( $file ); |
| 13 | } catch ( Sanitize_File_Exception $exception ) { |
| 14 | return false; |
| 15 | } |
| 16 | $this->add( $file ); |
| 17 | |
| 18 | return true; |
| 19 | } |
| 20 | |
| 21 | public function push_files( array $files ): File_Collection { |
| 22 | foreach ( $files as $file ) { |
| 23 | $this->push( $file ); |
| 24 | } |
| 25 | |
| 26 | return $this; |
| 27 | } |
| 28 | |
| 29 | /* |
| 30 | * Realisation of |
| 31 | * \Jet_Form_Builder\Classes\Resources\Media_Block_Value |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * @return string |
| 36 | */ |
| 37 | public function get_attachment_id(): string { |
| 38 | return ''; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @return string |
| 43 | */ |
| 44 | public function get_attachment_url(): string { |
| 45 | $urls = array(); |
| 46 | |
| 47 | foreach ( $this as $file ) { |
| 48 | $urls[] = $file->get_attachment_url(); |
| 49 | } |
| 50 | |
| 51 | return implode( ',', $urls ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @return array |
| 56 | */ |
| 57 | public function get_attachment_both(): array { |
| 58 | return array(); |
| 59 | } |
| 60 | } |
| 61 |