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
uploaded-collection.php
93 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Classes\Resources; |
| 5 | |
| 6 | // If this file is called directly, abort. |
| 7 | if ( ! defined( 'WPINC' ) ) { |
| 8 | die; |
| 9 | } |
| 10 | |
| 11 | class Uploaded_Collection implements Media_Block_Value, Uploaded_File_Path { |
| 12 | |
| 13 | /** @var Uploaded_File[] */ |
| 14 | protected $uploads = array(); |
| 15 | |
| 16 | public function __construct( array $uploads = array() ) { |
| 17 | $this->set_uploads( $uploads ); |
| 18 | } |
| 19 | |
| 20 | /* |
| 21 | * Realisation of |
| 22 | * \Jet_Form_Builder\Classes\Resources\Media_Block_Value |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * @return string |
| 27 | */ |
| 28 | public function get_attachment_id(): string { |
| 29 | $ids = array(); |
| 30 | |
| 31 | foreach ( $this->uploads as $upload ) { |
| 32 | $ids[] = $upload->get_attachment_id(); |
| 33 | } |
| 34 | |
| 35 | return implode( ',', $ids ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @return string |
| 40 | */ |
| 41 | public function get_attachment_url(): string { |
| 42 | $urls = array(); |
| 43 | |
| 44 | foreach ( $this->uploads as $upload ) { |
| 45 | $urls[] = $upload->get_attachment_url(); |
| 46 | } |
| 47 | |
| 48 | return implode( ',', $urls ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @return array |
| 53 | */ |
| 54 | public function get_attachment_both(): array { |
| 55 | $both = array(); |
| 56 | |
| 57 | foreach ( $this->uploads as $upload ) { |
| 58 | $both[] = $upload->get_attachment_both(); |
| 59 | } |
| 60 | |
| 61 | return $both; |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Realisation of |
| 66 | * \Jet_Form_Builder\Classes\Resources\Uploaded_File_Path |
| 67 | */ |
| 68 | |
| 69 | /** |
| 70 | * @return string |
| 71 | */ |
| 72 | public function get_attachment_file(): string { |
| 73 | $files = array(); |
| 74 | |
| 75 | foreach ( $this->uploads as $upload ) { |
| 76 | $files[] = $upload->get_attachment_file(); |
| 77 | } |
| 78 | |
| 79 | return implode( ',', $files ); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @param Uploaded_File[] $uploads |
| 84 | */ |
| 85 | public function set_uploads( array $uploads ) { |
| 86 | foreach ( $uploads as $uploaded_file ) { |
| 87 | if ( $uploaded_file instanceof Uploaded_File ) { |
| 88 | $this->uploads[] = $uploaded_file; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 |