PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.41
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.41
5.5.85 5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 All 161 releases
wp-data-access / WPDataAccess / Plugin_Table_Models / WPDA_App_Container_Model.php

WPDA_App_Container_Model.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.41, at WPDataAccess/Plugin_Table_Models/WPDA_App_Container_Model.php

276 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDataAccess\Plugin_Table_Models;
4
5 use WPDataAccess\WPDA;
6 class WPDA_App_Container_Model extends WPDA_Plugin_Table_Base_Model {
7 const BASE_TABLE_NAME = 'wpda_app_container';
8
9 public static function select( $app_id, $cnt_seq_nr ) {
10 global $wpdb;
11 if ( 0 === $cnt_seq_nr ) {
12 return $wpdb->get_results(
13 $wpdb->prepare(
14 'SELECT * FROM `%1s` WHERE app_id = %d and cnt_seq_nr = 0 order by cnt_id',
15 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
16 array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id)
17 ),
18 // db call ok; no-cache ok.
19 'ARRAY_A'
20 );
21 // phpcs:ignore Standard.Category.SniffName.ErrorCode
22 } else {
23 return $wpdb->get_results(
24 $wpdb->prepare(
25 'SELECT * FROM `%1s` WHERE app_id = %d and cnt_seq_nr > 0 order by cnt_seq_nr, cnt_id',
26 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
27 array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id)
28 ),
29 // db call ok; no-cache ok.
30 'ARRAY_A'
31 );
32 // phpcs:ignore Standard.Category.SniffName.ErrorCode
33 }
34 }
35
36 public static function select_all( $app_id ) {
37 global $wpdb;
38 return $wpdb->get_results(
39 $wpdb->prepare(
40 'SELECT * FROM `%1s` WHERE app_id = %d order by cnt_seq_nr',
41 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
42 array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id)
43 ),
44 // db call ok; no-cache ok.
45 'ARRAY_A'
46 );
47 // phpcs:ignore Standard.Category.SniffName.ErrorCode
48 }
49
50 public static function get_container( $cnt_id ) {
51 global $wpdb;
52 return $wpdb->get_results(
53 $wpdb->prepare(
54 'SELECT * FROM `%1s` WHERE cnt_id = %d',
55 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
56 array(WPDA::remove_backticks( self::get_base_table_name() ), $cnt_id)
57 ),
58 // db call ok; no-cache ok.
59 'ARRAY_A'
60 );
61 // phpcs:ignore Standard.Category.SniffName.ErrorCode
62 }
63
64 public static function create(
65 $app_id,
66 $app_dbs,
67 $app_tbl,
68 $app_cls,
69 $cnt_title,
70 $cnt_seq_nr,
71 $cnt_table,
72 $cnt_relation = null,
73 $cnt_query = null
74 ) {
75 global $wpdb;
76 if ( 1 === $cnt_seq_nr ) {
77 $max_seq_nr = $wpdb->get_results(
78 $wpdb->prepare(
79 'SELECT max(cnt_seq_nr) FROM `%1s` WHERE app_id = %d',
80 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
81 array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id)
82 ),
83 // db call ok; no-cache ok.
84 'ARRAY_N'
85 );
86 // phpcs:ignore Standard.Category.SniffName.ErrorCode
87 if ( isset( $max_seq_nr[0][0] ) ) {
88 $cnt_seq_nr = $max_seq_nr[0][0] + 1;
89 }
90 }
91 if ( 1 === $wpdb->insert( static::get_base_table_name(), array(
92 'cnt_dbs' => $app_dbs,
93 'cnt_tbl' => $app_tbl,
94 'cnt_cls' => $app_cls,
95 'cnt_title' => $cnt_title,
96 'app_id' => $app_id,
97 'cnt_seq_nr' => $cnt_seq_nr,
98 'cnt_table' => $cnt_table,
99 'cnt_relation' => $cnt_relation,
100 'cnt_query' => $cnt_query,
101 ) ) ) {
102 // Return new container
103 $cnt_id = $wpdb->insert_id;
104 return array(
105 'cnt_id' => $wpdb->insert_id,
106 'msg' => '',
107 );
108 } else {
109 return array(
110 'cnt_id' => false,
111 'msg' => $wpdb->last_error,
112 );
113 }
114 }
115
116 public static function update(
117 $app_id,
118 $app_cnt,
119 $app_dbs,
120 $app_tbl,
121 $app_cls,
122 $cnt_title,
123 $cnt_relation = null
124 ) {
125 global $wpdb;
126 $wpdb->update( static::get_base_table_name(), array(
127 'cnt_dbs' => $app_dbs,
128 'cnt_tbl' => $app_tbl,
129 'cnt_cls' => $app_cls,
130 'cnt_title' => $cnt_title,
131 'cnt_relation' => $cnt_relation,
132 ), array(
133 'app_id' => $app_id,
134 'cnt_id' => $app_cnt,
135 ) );
136 return $wpdb->last_error;
137 }
138
139 public static function delete( $app_id ) {
140 global $wpdb;
141 return $wpdb->delete( static::get_base_table_name(), array(
142 'app_id' => $app_id,
143 ) );
144 }
145
146 public static function delete_container( $cnt_id ) {
147 global $wpdb;
148 return $wpdb->delete( static::get_base_table_name(), array(
149 'cnt_id' => $cnt_id,
150 ) );
151 }
152
153 public static function update_master(
154 $app_id,
155 $app_dbs,
156 $app_tbl,
157 $app_cls,
158 $app_query
159 ) {
160 global $wpdb;
161 $wpdb->update( static::get_base_table_name(), array(
162 'cnt_dbs' => $app_dbs,
163 'cnt_tbl' => $app_tbl,
164 'cnt_cls' => $app_cls,
165 'cnt_query' => $app_query,
166 ), array(
167 'app_id' => $app_id,
168 'cnt_seq_nr' => 0,
169 ) );
170 return $wpdb->last_error;
171 }
172
173 public static function update_table_settings( $cnt_id, $cnt_table_settings ) {
174 global $wpdb;
175 $wpdb->update( static::get_base_table_name(), array(
176 'cnt_table' => $cnt_table_settings,
177 ), array(
178 'cnt_id' => $cnt_id,
179 ) );
180 return $wpdb->last_error;
181 }
182
183 public static function update_rform_settings( $cnt_id, $cnt_form_settings ) {
184 global $wpdb;
185 $wpdb->update( static::get_base_table_name(), array(
186 'cnt_rform' => $cnt_form_settings,
187 ), array(
188 'cnt_id' => $cnt_id,
189 ) );
190 return $wpdb->last_error;
191 }
192
193 public static function update_form_settings( $cnt_id, $cnt_form_settings ) {
194 global $wpdb;
195 $wpdb->update( static::get_base_table_name(), array(
196 'cnt_form' => $cnt_form_settings,
197 ), array(
198 'cnt_id' => $cnt_id,
199 ) );
200 return $wpdb->last_error;
201 }
202
203 public static function update_chart_settings( $cnt_id, $cnt_chart_settings ) {
204 global $wpdb;
205 $wpdb->update( static::get_base_table_name(), array(
206 'cnt_chart' => $cnt_chart_settings,
207 ), array(
208 'cnt_id' => $cnt_id,
209 ) );
210 return $wpdb->last_error;
211 }
212
213 public static function update_map_settings( $cnt_id, $cnt_map_settings ) {
214 global $wpdb;
215 $wpdb->update( static::get_base_table_name(), array(
216 'cnt_map' => $cnt_map_settings,
217 ), array(
218 'cnt_id' => $cnt_id,
219 ) );
220 return $wpdb->last_error;
221 }
222
223 public static function container_move( $cnt_id_from, $cnt_id_to ) {
224 // This is a premium feature.
225 return '';
226 }
227
228 public static function copy( $app_id_old, $app_id_new ) {
229 global $wpdb;
230 $containers = $wpdb->get_results(
231 $wpdb->prepare(
232 'SELECT * FROM `%1s` WHERE app_id = %d order by cnt_seq_nr',
233 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
234 array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id_old)
235 ),
236 // db call ok; no-cache ok.
237 'ARRAY_A'
238 );
239 // phpcs:ignore Standard.Category.SniffName.ErrorCode
240 $cnt_id_conversion = array();
241 foreach ( $containers as $container ) {
242 $cnt_id = $container['cnt_id'];
243 $container['app_id'] = $app_id_new;
244 unset($container['cnt_id']);
245 $wpdb->insert( static::get_base_table_name(), $container );
246 $cnt_id_conversion[$cnt_id] = $wpdb->insert_id;
247 }
248 foreach ( $cnt_id_conversion as $cnt_id_old => $cnt_id_new ) {
249 $container = self::get_container( $cnt_id_new );
250 $relation = $container[0]['cnt_relation'];
251 if ( null !== $relation && '' !== $relation ) {
252 $json = json_decode( $relation, true );
253 if ( isset( $json['cnt_id_master'] ) ) {
254 $cnt_id_master_old = $json['cnt_id_master'];
255 if ( isset( $cnt_id_conversion[$cnt_id_master_old] ) ) {
256 // Update relationship master id
257 $cnt_id_master_new = $cnt_id_conversion[$cnt_id_master_old];
258 $json['cnt_id_master'] = strval( $cnt_id_master_new );
259 $relation = json_encode( $json );
260 } else {
261 // Master no longer available
262 $relation = null;
263 }
264 $wpdb->update( static::get_base_table_name(), array(
265 'cnt_relation' => $relation,
266 ), array(
267 'app_id' => $app_id_new,
268 'cnt_id' => $cnt_id_new,
269 ) );
270 }
271 }
272 }
273 }
274
275 }
276