PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.4.2
JetFormBuilder — Dynamic Blocks Form Builder v1.4.2
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 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / form-break.php
jetformbuilder / includes Last commit date
actions 4 years ago addons 4 years ago admin 4 years ago blocks 4 years ago classes 4 years ago compatibility 4 years ago dev-mode 4 years ago exceptions 4 years ago form-actions 4 years ago form-messages 4 years ago form-patterns 4 years ago form-response 4 years ago gateways 4 years ago generators 4 years ago integrations 4 years ago presets 4 years ago request 4 years ago shortcodes 4 years ago widgets 4 years ago autoloader.php 4 years ago file-upload.php 4 years ago form-break.php 4 years ago form-handler.php 4 years ago form-manager.php 4 years ago live-form.php 4 years ago plugin.php 4 years ago post-type.php 4 years ago
form-break.php
234 lines
1 <?php
2
3
4 namespace Jet_Form_Builder;
5
6
7 use Jet_Form_Builder\Classes\Get_Template_Trait;
8 use Jet_Form_Builder\Classes\Tools;
9
10 class Form_Break {
11
12 use Get_Template_Trait;
13
14 private $pages = 0;
15 private $form_breaks = array();
16 private $count_form_breaks = null;
17 private $current_page = 1;
18 private $current_form_break = 0;
19 private $is_editor = false;
20 private $progress_type = 'default';
21
22 public function get_pages() {
23 return $this->pages;
24 }
25
26 public function get_breaks() {
27 return $this->form_breaks;
28 }
29
30 public function get_count_breaks() {
31 if ( is_null( $this->count_form_breaks ) ) {
32 $this->count_form_breaks = count( $this->form_breaks );
33 }
34
35 return $this->count_form_breaks;
36 }
37
38 public function get_current() {
39 return $this->current_page;
40 }
41
42 public function set_progress_type( $type ) {
43 if ( ! is_string( $type ) ) {
44 return;
45 }
46 $this->progress_type = $type;
47 }
48
49 public function set_editor_mode( $is_editor ) {
50 if ( ! $is_editor ) {
51 $this->is_editor = false;
52 $this->pages = 0;
53 $this->form_breaks = array();
54 $this->count_form_breaks = 0;
55
56 return $this;
57 }
58
59 $this->is_editor = true;
60 $this->pages = 2;
61 $this->form_breaks = array(
62 array(
63 'label' => 'Start Page'
64 ),
65 array(
66 'label' => 'Second Page'
67 ),
68 array(
69 'label' => 'Last Page'
70 ),
71 );
72
73 return $this;
74 }
75
76 public function add_progress( $last_progress ) {
77 $this->form_breaks[] = $last_progress;
78
79 return $this;
80 }
81
82
83 public function set_pages( $blocks, $last_page_from_blocks = true ) {
84 $count_blocks = count( $blocks );
85 $last_break = false;
86
87 foreach ( $blocks as $index => $field ) {
88 if ( ! Live_Form::instance()->is_field( $field, 'form-break' ) ) {
89 continue;
90 }
91 $form_break = Plugin::instance()->blocks->get_field_attrs( $field['blockName'], $field['attrs'] );
92
93 if ( $last_page_from_blocks && $index + 1 === $count_blocks ) {
94 $last_break = $form_break;
95 unset( $blocks[ $index ] );
96 continue;
97 }
98
99 $this->pages ++;
100 $this->form_breaks[] = $form_break;
101 }
102 if ( $last_page_from_blocks && ! empty( $this->form_breaks ) ) {
103 $this->form_breaks[] = $last_break ? $last_break : array( 'label' => __( 'Last Page' ) );
104 }
105
106 return $blocks;
107 }
108
109 public function with_progress_wrapper( $content, $additional_classes = array() ) {
110 $type = $this->progress_type ?: 'default';
111
112 $classes = array_merge( array(
113 "jet-form-builder-progress-pages",
114 "jfb-progress-type--$type"
115 ), $additional_classes );
116
117 return sprintf(
118 '<div class="%1$s" data-type="%2$s">%3$s</div>',
119 implode( ' ', $classes ),
120 $type,
121 $content
122 );
123 }
124
125 public function render_default_progress() {
126 ob_start();
127 include Tools::get_global_template( 'fields/progress-bar.php' );
128
129 return ob_get_clean();
130 }
131
132 public function render_progress( $type = '', $additional_classes = array() ) {
133 if ( $type ) {
134 $this->set_progress_type( $type );
135 }
136
137 switch ( $this->progress_type ) {
138 case 'default':
139 $content = $this->render_default_progress();
140 break;
141 default:
142 $content = apply_filters( "jet-form-builder/render/progress-bar/$this->progress_type", '', $this );
143 break;
144 }
145
146 return $this->with_progress_wrapper( $content, $additional_classes );
147 }
148
149 public function get_progress_item_class( $index ) {
150 $classes = array( 'jet-form-builder-progress-pages__item--wrapper' );
151
152 if ( $this->is_editor ) {
153 if ( 0 === $index ) {
154 $classes[] = 'passed-page';
155 }
156 if ( 1 === $index ) {
157 $classes[] = 'active-page';
158 }
159 } elseif ( $index === $this->current_form_break ) {
160 $classes[] = 'active-page';
161 } elseif ( $index < $this->current_form_break ) {
162 $classes[] = 'passed-page';
163 }
164
165 return implode( ' ', $classes );
166 }
167
168 /**
169 * Maybe start new page
170 *
171 * @param bool $force_first
172 *
173 * @return string
174 */
175 public function maybe_start_page( $force_first = false ) {
176
177 if ( 0 >= $this->pages ) {
178 return '';
179 }
180
181 if ( $force_first ) {
182 $this->current_page = 1;
183 $this->current_form_break = 0;
184 } else {
185 $this->current_page ++;
186 $this->current_form_break ++;
187 }
188
189
190 ob_start();
191 do_action( 'jet-form-builder/before-page-start', $this );
192
193 $hidden_class = '';
194
195 if ( 1 < $this->current_page ) {
196 $hidden_class = 'jet-form-builder-page--hidden';
197 }
198
199 include Tools::get_global_template( 'common/start-page.php' );
200
201 do_action( 'jet-form-builder/after-page-start', $this );
202
203 return ob_get_clean();
204 }
205
206 /**
207 * Maybe start new page
208 *
209 * @param $is_last
210 * @param $field
211 *
212 * @return string
213 */
214 public function maybe_end_page( $is_last = false, $field = false ) {
215
216 if ( 0 >= $this->pages ) {
217 return '';
218 }
219
220 if ( ! $is_last && ! Live_Form::instance()->is_field( $field, 'form-break' ) ) {
221 return '';
222 }
223
224 ob_start();
225 do_action( 'jet-form-builder/before-page-end', $this );
226
227 include Tools::get_global_template( 'common/end-page.php' );
228
229 do_action( 'jet-form-builder/after-page-end', $this );
230
231 return ob_get_clean();
232 }
233
234 }