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