PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.2
JetFormBuilder — Dynamic Blocks Form Builder v3.0.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 / admin / table-record-prepare-trait.php
jetformbuilder / includes / admin Last commit date
buttons 3 years ago exceptions 3 years ago notices 3 years ago pages 3 years ago single-pages 3 years ago table-views 3 years ago tabs-handlers 3 years ago vui-boxes 3 years ago admin-page-interface.php 3 years ago admin-page-trait.php 3 years ago editor.php 3 years ago table-advanced-record-prepare-trait.php 3 years ago table-record-prepare-trait.php 3 years ago
table-record-prepare-trait.php
106 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Admin;
5
6
7 trait Table_Record_Prepare_Trait {
8
9 abstract public function get_columns_handlers(): array;
10
11 abstract public function get_columns_headings(): array;
12
13 abstract public function get_raw_list( array $args ): array;
14
15 abstract public function get_list(): array;
16
17 public function prepare_list( array $custom_list = array() ): array {
18 $list = empty( $custom_list ) ? $this->get_list() : $custom_list;
19
20 if ( ! $list || ! is_array( $list ) ) {
21 return array();
22 }
23 $prepared = array();
24
25 foreach ( $list as $item_id => $record ) {
26 $prepared[ $item_id ] = $this->prepare_record( $record );
27 }
28
29 return $prepared;
30 }
31
32 public function before_prepare_record( array $record, $column_attrs, $column_name ) {
33 }
34
35 public function after_prepare_record( $prepared, array $record, $column_name ) {
36 }
37
38 public function prepare_record( $record ): array {
39 $prepared = array();
40
41 foreach ( $this->get_columns_handlers() as $column_name => $column_attrs ) {
42 $this->before_prepare_record( $record, $column_attrs, $column_name );
43
44 $prepared[ $column_name ] = $this->prepare_column_attrs( $record, $column_attrs, $column_name );
45
46 $this->after_prepare_record( $prepared[ $column_name ], $record, $column_name );
47 }
48
49 return $prepared;
50 }
51
52 public function prepare_column_attrs( array $record, $column_attrs, $column_name ): array {
53 $value = $column_attrs['value'] ?? $record[ $column_name ] ?? false;
54 $column_attrs['type'] = $column_attrs['type'] ?? 'string';
55 $column_attrs['default'] = $column_attrs['default'] ?? false;
56
57 $default = $this->prepare_record_value_type( $column_attrs['default'], $column_attrs );
58
59 if ( ! is_callable( $value ) ) {
60 $column_attrs['value'] = $value ?: $default;
61 } else {
62 $column_attrs['value'] = $this->prepare_record_value_type(
63 call_user_func( $value, $record, $default ),
64 $column_attrs
65 );
66 }
67
68 return $column_attrs;
69 }
70
71 public function transform_to_columns_values( array $columns ): array {
72 $transformed = array();
73
74 foreach ( $this->get_columns_handlers() as $column_name => $column_attrs ) {
75 if ( ! isset( $columns[ $column_name ] ) ) {
76 continue;
77 }
78 $column_attrs['type'] = $column_attrs['type'] ?? 'string';
79 $column_attrs['default'] = $column_attrs['default'] ?? false;
80 $column_attrs['value'] = $columns[ $column_name ];
81
82 $transformed[ $column_name ] = $column_attrs;
83 }
84
85 return $transformed;
86 }
87
88 protected function prepare_record_value_type( $value, $column ) {
89 $type = $column['type'] ?? 'string';
90
91 switch ( $type ) {
92 case 'integer':
93 return (int) $value;
94 case 'float':
95 return (float) $value;
96 case 'array':
97 return (array) $value;
98 case 'string':
99 return (string) $value;
100 case 'rawArray':
101 default:
102 return $value;
103 }
104 }
105
106 }