| 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 |
public function get_attachment_ids(): array { |
| 39 |
$ids = array(); |
| 40 |
|
| 41 |
foreach ( $this->uploads as $upload ) { |
| 42 |
$ids[] = $upload->get_attachment_id(); |
| 43 |
} |
| 44 |
|
| 45 |
return $ids; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* @return string |
| 50 |
*/ |
| 51 |
public function get_attachment_url(): string { |
| 52 |
$urls = array(); |
| 53 |
|
| 54 |
foreach ( $this->uploads as $upload ) { |
| 55 |
$urls[] = $upload->get_attachment_url(); |
| 56 |
} |
| 57 |
|
| 58 |
return implode( ',', $urls ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* @return array |
| 63 |
*/ |
| 64 |
public function get_attachment_both(): array { |
| 65 |
$both = array(); |
| 66 |
|
| 67 |
foreach ( $this->uploads as $upload ) { |
| 68 |
$both[] = $upload->get_attachment_both(); |
| 69 |
} |
| 70 |
|
| 71 |
return $both; |
| 72 |
} |
| 73 |
|
| 74 |
/* |
| 75 |
* Realisation of |
| 76 |
* \Jet_Form_Builder\Classes\Resources\Uploaded_File_Path |
| 77 |
*/ |
| 78 |
|
| 79 |
/** |
| 80 |
* @return string |
| 81 |
*/ |
| 82 |
public function get_attachment_file(): string { |
| 83 |
$files = array(); |
| 84 |
|
| 85 |
foreach ( $this->uploads as $upload ) { |
| 86 |
$files[] = $upload->get_attachment_file(); |
| 87 |
} |
| 88 |
|
| 89 |
return implode( ',', $files ); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* @param Uploaded_File[] $uploads |
| 94 |
*/ |
| 95 |
public function set_uploads( array $uploads ) { |
| 96 |
foreach ( $uploads as $uploaded_file ) { |
| 97 |
if ( $uploaded_file instanceof Uploaded_File ) { |
| 98 |
$this->uploads[] = $uploaded_file; |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|