PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.5
JetFormBuilder — Dynamic Blocks Form Builder v2.1.5
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 / blocks / conditional-block / condition-item.php
jetformbuilder / includes / blocks / conditional-block Last commit date
functions 3 years ago operators 3 years ago render-states 3 years ago condition-item.php 3 years ago condition-manager.php 3 years ago condition-response-object.php 3 years ago functions.php 3 years ago operators.php 3 years ago render-state.php 3 years ago render-states-collection.php 3 years ago
condition-item.php
128 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Blocks\Conditional_Block;
5
6 use Jet_Form_Builder\Blocks\Conditional_Block\Functions\Base_Function;
7 use Jet_Form_Builder\Blocks\Conditional_Block\Operators\Base_Operator;
8 use Jet_Form_Builder\Blocks\Exceptions\Condition_Exception;
9 use Jet_Form_Builder\Blocks\Exceptions\Render_Empty_Field;
10 use Jet_Form_Builder\Classes\Arrayable\Arrayable;
11 use Jet_Form_Builder\Exceptions\Repository_Exception;
12 use Jet_Form_Builder\Presets\Types\Dynamic_Preset;
13
14 class Condition_Item implements Arrayable {
15
16 private $type;
17 private $value;
18 private $field;
19 private $operator;
20
21 private $parsed_value;
22
23 /**
24 * All condition options
25 *
26 * @var array
27 */
28 public $base;
29
30 /**
31 * Condition_Item constructor.
32 *
33 * @param array $condition
34 *
35 * @throws Repository_Exception
36 */
37 public function __construct( array $condition ) {
38 $this->base = $condition;
39 $this->value = $condition['value'] ?? '';
40 $this->field = $condition['field'] ?? '';
41 $this->type = $condition['type'] ?? '';
42 $this->operator = $condition['operator'] ?? '';
43
44 Condition_Manager::instance()->get_functions()->isset_function( $this->type );
45 Condition_Manager::instance()->get_operators()->isset_operator( $this->operator );
46 }
47
48 public function to_array(): array {
49 $base = array(
50 'value' => $this->get_parsed_value(),
51 'type' => $this->get_type(),
52 'field' => $this->get_field(),
53 'operator' => $this->get_operator(),
54 );
55 $base = array_merge(
56 $base,
57 $this->get_operator_object()->to_response( $base, $this )
58 );
59
60 return array_merge(
61 $base,
62 $this->get_function_object()->to_response( $base, $this )
63 );
64 }
65
66 public function get_function_object(): Base_Function {
67 return Condition_Manager::instance()->get_functions()->rep_get_item_or_die( $this->type );
68 }
69
70 public function get_operator_object(): Base_Operator {
71 return Condition_Manager::instance()->get_operators()->rep_get_item_or_die( $this->operator );
72 }
73
74 /**
75 * @return array|string
76 */
77 public function get_parsed_value() {
78 if ( ! is_null( $this->parsed_value ) ) {
79 return $this->parsed_value;
80 }
81
82 $value = ( new Dynamic_Preset() )->parse_json( $this->value );
83
84 $this->parsed_value = $this->parse_string( $value );
85
86 return $this->parsed_value;
87 }
88
89 private function parse_string( string $value ) {
90 $value_in_array = explode( ',', $value );
91
92 if ( 1 === count( $value_in_array ) ) {
93 return $value;
94 }
95
96 return array_map( 'trim', $value_in_array );
97 }
98
99 /**
100 * @return string
101 */
102 public function get_type(): string {
103 return $this->type;
104 }
105
106 /**
107 * @return string
108 */
109 public function get_value(): string {
110 return $this->value;
111 }
112
113 /**
114 * @return string
115 */
116 public function get_field(): string {
117 return $this->field;
118 }
119
120 /**
121 * @return string
122 */
123 public function get_operator(): string {
124 return $this->operator;
125 }
126
127 }
128