PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.2
JetFormBuilder — Dynamic Blocks Form Builder v3.6.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 / modules / form-record / tools.php
jetformbuilder / modules / form-record Last commit date
action-types 1 year ago admin 1 month ago assets 1 month ago constraints 2 years ago export 2 months ago models 1 month ago query-views 1 year ago rest-endpoints 1 year ago controller.php 1 month ago module.php 1 year ago records-rest-controller.php 2 years ago tools.php 2 years ago
tools.php
105 lines
1 <?php
2
3
4 namespace JFB_Modules\Form_Record;
5
6 use Jet_Form_Builder\Blocks\Block_Helper;
7 use Jet_Form_Builder\Exceptions\Silence_Exception;
8 use JFB_Modules\Form_Record\Query_Views\Record_Fields_View;
9 use Jet_Form_Builder\Classes\Tools as GlobalTools;
10 use Jet_Form_Builder\Db_Queries\Exceptions\Sql_Exception;
11
12 // If this file is called directly, abort.
13 if ( ! defined( 'WPINC' ) ) {
14 die;
15 }
16
17 class Tools {
18
19 /**
20 * @param array $record
21 */
22 public static function apply_context( array $record ) {
23 $fields = Record_Fields_View::get_request( $record['id'] );
24
25 if ( empty( $fields ) ) {
26 return;
27 }
28
29 // set fields without request
30 jet_fb_context()->set_parsers(
31 Block_Helper::get_blocks_by_post( $record['form_id'] )
32 );
33
34 $request = array();
35
36 foreach ( $fields as $field ) {
37 $attrs = GlobalTools::decode_json( $field['field_attrs'] );
38 $parsed = iterator_to_array( self::iterate_request_line( $field ) );
39
40 $value = current( $parsed );
41 $name = key( $parsed );
42
43 $request[ $name ] = $value;
44
45 try {
46 jet_fb_context()->resolve_parser( $name );
47 } catch ( Silence_Exception $exception ) {
48 jet_fb_context()->set_field_type( $field['field_type'], $name );
49 jet_fb_context()->set_field_settings( $attrs, $name );
50 }
51 }
52
53 jet_fb_context()->set_request( $request );
54 jet_fb_context()->apply_request();
55 }
56
57 /**
58 * @since 3.1.0
59 *
60 * @param array|\Generator $request
61 *
62 * @return \Generator
63 */
64 public static function iterate_request( $request ): \Generator {
65 foreach ( $request as $field ) {
66 yield from self::iterate_request_line( $field );
67 }
68 }
69
70 /**
71 * @since 3.1.0
72 *
73 * @param array $field
74 *
75 * @return \Generator
76 */
77 public static function iterate_request_line( array $field ): \Generator {
78 $attrs = GlobalTools::decode_json( $field['field_attrs'] );
79
80 if ( empty( $attrs['is_encoded'] ) ) {
81 yield $field['field_name'] => $field['field_value'];
82 return;
83 }
84
85 yield $field['field_name'] => GlobalTools::decode_json( $field['field_value'] );
86 }
87
88 /**
89 * @param int $record_id
90 *
91 * @throws Sql_Exception
92 */
93 public static function update_record( int $record_id ) {
94 if ( ! $record_id ) {
95 return;
96 }
97 $controller = ( new Controller() )->set_record_id( $record_id );
98 $controller->set_setting( 'save_errors', jet_form_builder()->has_module( 'dev' ) );
99
100 $controller->save_actions();
101 $controller->save_errors();
102 }
103
104 }
105