PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.8
JetFormBuilder — Dynamic Blocks Form Builder v3.0.8
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-manager.php
jetformbuilder / includes / blocks / conditional-block Last commit date
condition-types 3 years ago functions 3 years ago models 3 years ago operators 3 years ago query-views 3 years ago render-states 3 years ago rest-api 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-manager.php
121 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Blocks\Conditional_Block;
5
6 use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Types\Base_Condition_Type;
7 use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Types\Condition_Field_Item;
8 use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Types\Condition_Render_State_Item;
9 use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Types\Or_Operator_Item;
10 use Jet_Form_Builder\Blocks\Conditional_Block\Rest_Api\Add_Render_State_Endpoint_Option;
11 use Jet_Form_Builder\Blocks\Conditional_Block\Rest_Api\Delete_Render_States_Endpoint;
12 use Jet_Form_Builder\Blocks\Exceptions\Condition_Exception;
13 use Jet_Form_Builder\Blocks\Exceptions\Render_Empty_Field;
14 use Jet_Form_Builder\Classes\Arrayable\Arrayable;
15 use Jet_Form_Builder\Classes\Instance_Trait;
16 use Jet_Form_Builder\Classes\Tools;
17 use Jet_Form_Builder\Exceptions\Repository_Exception;
18
19 /**
20 * @method static Condition_Manager instance()
21 *
22 * Class Condition_Manager
23 * @package Jet_Form_Builder\Blocks\Conditional_Block
24 */
25 class Condition_Manager implements Arrayable {
26
27 use Instance_Trait;
28
29 private $operators;
30 private $functions;
31
32 /**
33 * @var Base_Condition_Type[]
34 */
35 private $types;
36
37 private function __construct() {
38 $this->operators = new Operators();
39 $this->functions = new Functions();
40
41 $this->types = apply_filters(
42 'jet-form-builder/conditional-block/types',
43 array(
44 new Condition_Render_State_Item(),
45 new Or_Operator_Item(),
46 new Condition_Field_Item(),
47 )
48 );
49 }
50
51 public function prepare( array $conditions ): array {
52 $response = array();
53
54 foreach ( $conditions as $condition ) {
55 try {
56 $item = $this->get_current_type( $condition );
57 } catch ( Repository_Exception $exception ) {
58 continue;
59 }
60
61 /**
62 * Catch Condition_Exception on this level,
63 * because in future we can implement "OR" operator
64 * between all conditions.
65 *
66 * Here we could access the global option
67 */
68 try {
69 $response[] = $item->to_array();
70 } catch ( Condition_Exception $exception ) {
71 /**
72 * This exception catches in
73 *
74 * @see \Jet_Form_Builder\Blocks\Types\Base::render_callback_field
75 */
76 throw new Render_Empty_Field( 'This is temporary.' );
77 }
78 }
79
80 return $response;
81 }
82
83 public function to_array(): array {
84 return array(
85 'functions' => Tools::with_placeholder( $this->get_functions()->to_array() ),
86 'operators' => Tools::with_placeholder( $this->get_operators()->to_array() ),
87 'render_states' => Render_State::instance()->to_array(),
88 'rest_add_state' => Add_Render_State_Endpoint_Option::get_endpoint(),
89 'rest_delete_state' => Delete_Render_States_Endpoint::get_endpoint(),
90 );
91 }
92
93 public function get_operators(): Operators {
94 return $this->operators;
95 }
96
97 public function get_functions(): Functions {
98 return $this->functions;
99 }
100
101 /**
102 * @param array $condition
103 *
104 * @return Base_Condition_Type
105 * @throws Repository_Exception
106 */
107 protected function get_current_type( array $condition ): Base_Condition_Type {
108 foreach ( $this->types as $type ) {
109 if ( ! $type->is_supported( $condition ) ) {
110 continue;
111 }
112 $type->init( $condition );
113
114 return $type;
115 }
116
117 throw new Repository_Exception( 'Undefined condition type' );
118 }
119
120 }
121