PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.4
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.4
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / includes / classes / resources / uploaded-collection.php

uploaded-collection.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.5.4, at includes/classes/resources/uploaded-collection.php

103 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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