PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.4.2
JetFormBuilder — Dynamic Blocks Form Builder v1.4.2
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 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 / presets / sources / base-source.php
jetformbuilder / includes / presets / sources Last commit date
base-source.php 4 years ago preset-source-options-page.php 4 years ago preset-source-post.php 4 years ago preset-source-query-var.php 4 years ago preset-source-user.php 4 years ago
base-source.php
116 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Presets\Sources;
5
6 use Jet_Form_Builder\Presets\Preset_Manager;
7
8 abstract class Base_Source {
9
10 protected $fields_map;
11 protected $field_data = array();
12 protected $field_args;
13 protected $preset_data;
14 protected $field = '__condition__';
15 protected $prop;
16 private $src;
17
18 const FUNC_PREFIX = '_source__';
19 const EMPTY = '';
20
21 abstract public function query_source();
22
23 abstract public function get_id();
24
25 public function condition(): bool {
26 return true;
27 }
28
29 public function init_source( $fields_map, $field_args, $preset_data ) {
30 $this->fields_map = $fields_map;
31 $this->field_args = $field_args;
32 $this->preset_data = $preset_data;
33 $this->field = $this->field_args['name'] ?? '';
34 $this->field_data = $this->get_field_data();
35 $this->prop = $this->get_prop();
36 $this->src = $this->maybe_query_source();
37
38 $this->after_init();
39
40 return $this;
41 }
42
43 public function after_init() {
44 }
45
46 public function after_register() {
47 }
48
49 public function maybe_query_source() {
50 if ( $this->prop ) {
51 return $this->query_source();
52 }
53 }
54
55 protected function get_field_data() {
56 if ( $this->has_field_in_map() ) {
57 return $this->fields_map[ $this->field ];
58 }
59 }
60
61 public function has_field_in_map() {
62 return ( isset( $this->fields_map[ $this->field ] ) && ( isset( $this->fields_map[ $this->field ]['prop'] ) || isset( $this->fields_map[ $this->field ]['key'] ) ) );
63 }
64
65 public function src() {
66 return $this->src;
67 }
68
69 protected function can_get_preset() {
70 return ( ! empty( $this->src() ) && ! is_wp_error( $this->src() ) );
71 }
72
73 public function default_prop( string $prop ) {
74 $source = $this->src;
75
76 if ( isset( $source->$prop ) ) {
77 return $source->$prop;
78 } elseif ( isset( $source->data ) && isset( $source->data->$prop ) ) {
79 return $source->data->$prop;
80 }
81
82 return self::EMPTY;
83 }
84
85 protected function get_prop() {
86 return ( ! empty( $this->field_data['prop'] ) ? $this->field_data['prop'] : false );
87 }
88
89 public function get_result_on_prop() {
90 $func_name = self::FUNC_PREFIX . $this->prop;
91
92 if ( is_callable( array( $this, $func_name ) ) ) {
93 return call_user_func( array( $this, $func_name ) );
94 }
95
96 return $this->default_prop( $this->prop );
97 }
98
99 final public function result() {
100 if ( ! $this->can_get_preset() ) {
101 return self::EMPTY;
102 }
103
104 return $this->parse_result_value( $this->get_result_on_prop() );
105 }
106
107 public function parse_result_value( $value ) {
108 if ( ! isset( $this->field_args['type'] ) ) {
109 return $value;
110 }
111
112 return Preset_Manager::instance()->prepare_result( $this->field_args['type'], $value );
113 }
114
115 }
116