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_Model.php

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

244 lines 5.9 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
7 class WPDA_App_Model extends WPDA_Plugin_Table_Base_Model {
8
9 const BASE_TABLE_NAME = 'wpda_app';
10
11 public static function get_by_id( $app_id ) {
12
13 global $wpdb;
14 $dataset = $wpdb->get_results(
15 $wpdb->prepare(
16 'SELECT * FROM `%1s` WHERE app_id = %d', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
17 array(
18 WPDA::remove_backticks( self::get_base_table_name() ),
19 $app_id,
20 )
21 ), // db call ok; no-cache ok.
22 'ARRAY_A'
23 ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
24
25 return 1 === $wpdb->num_rows ? $dataset : false;
26
27 }
28
29 public static function get_by_name( $app_name ) {
30
31 global $wpdb;
32 $dataset = $wpdb->get_results(
33 $wpdb->prepare(
34 'SELECT * FROM `%1s` WHERE app_name = %s', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
35 array(
36 WPDA::remove_backticks( self::get_base_table_name() ),
37 $app_name,
38 )
39 ), // db call ok; no-cache ok.
40 'ARRAY_A'
41 ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
42
43 return 1 === $wpdb->num_rows ? $dataset : false;
44
45 }
46
47 public static function list() {
48
49 global $wpdb;
50 return $wpdb->get_results(
51 $wpdb->prepare(
52 'SELECT * FROM `%1s` ORDER BY app_name', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
53 array(
54 WPDA::remove_backticks( self::get_base_table_name() ),
55 )
56 ), // db call ok; no-cache ok.
57 'ARRAY_A'
58 ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
59
60 }
61
62 public static function add_to_dashboard_menu() {
63
64 global $wpdb;
65 return $wpdb->get_results(
66 $wpdb->prepare(
67 'SELECT * FROM `%1s` WHERE `app_add_to_menu` = 1 ORDER BY app_name', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
68 array(
69 WPDA::remove_backticks( self::get_base_table_name() ),
70 )
71 ), // db call ok; no-cache ok.
72 'ARRAY_A'
73 ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
74
75 }
76
77 public static function create(
78 $app_name,
79 $app_title,
80 $app_type,
81 $app_settings
82 ) {
83
84 global $wpdb;
85 if ( 1 === $wpdb->insert(
86 static::get_base_table_name(),
87 array(
88 'app_name' => $app_name,
89 'app_title' => $app_title,
90 'app_type' => $app_type,
91 'app_settings' => $app_settings,
92 )
93 )
94 ) {
95 return array(
96 'app_id' => $wpdb->insert_id,
97 'msg' => '',
98 );
99 } else {
100 return array(
101 'app_id' => false,
102 'msg' => $wpdb->last_error,
103 );
104 }
105 }
106
107 public static function delete( $app_id ) {
108
109 global $wpdb;
110 return $wpdb->delete(
111 static::get_base_table_name(),
112 array(
113 'app_id' => $app_id,
114 )
115 );
116
117 }
118
119 public static function update(
120 $app_id,
121 $app_name,
122 $app_title,
123 $app_type,
124 $app_settings,
125 $app_add_to_menu
126 ) {
127
128 global $wpdb;
129 $wpdb->update(
130 static::get_base_table_name(),
131 array(
132 'app_name' => $app_name,
133 'app_title' => $app_title,
134 'app_type' => $app_type,
135 'app_settings' => $app_settings,
136 'app_add_to_menu' => $app_add_to_menu,
137 ),
138 array(
139 'app_id' => $app_id,
140 )
141 );
142
143 return $wpdb->last_error;
144
145 }
146
147 public static function copy_all(
148 $app
149 ) {
150
151 $app_id = $app[0]['app_id'];
152 $app_name = $app[0]['app_name'];
153
154 // Determine new app name
155 $copy_nr = 1;
156 $new_app_name = "{$app_name}_{$copy_nr} (copy)";
157 $app_exists = self::get_by_name( $new_app_name );
158 while ( false !== $app_exists ) {
159 $copy_nr++;
160 $new_app_name = "{$app_name}_{$copy_nr} (copy)";
161 $app_exists = self::get_by_name( $new_app_name );
162 }
163
164 // Copy app
165 global $wpdb;
166 if ( 1 === $wpdb->insert(
167 static::get_base_table_name(),
168 array(
169 'app_name' => $new_app_name,
170 'app_title' => $app[0]['app_title'],
171 'app_type' => $app[0]['app_type'],
172 'app_settings' => $app[0]['app_settings'],
173 'app_theme' => $app[0]['app_theme'],
174 )
175 )
176 ) {
177 $new_app_id = $wpdb->insert_id;
178
179 // Copy containers
180 WPDA_App_Container_Model::copy( $app_id, $new_app_id );
181
182 if ( 5 === $app[0]['app_type'] || '5' === $app[0]['app_type'] ) {
183 // App container, copy details
184 $apps = WPDA_App_Apps_Model::select_all( $app_id );
185 foreach ( $apps as $app ) {
186 $detail_app = self::get_by_id( $app['app_id_detail'] );
187 if ( false !== $detail_app ) {
188 $detail_app_ids = static::copy_all($detail_app);
189 if ( false !== $detail_app_ids['app_id'] ) {
190 WPDA_App_Apps_Model::create($new_app_id, $detail_app_ids['app_id'], $app['seq_nr']);
191 }
192 }
193 }
194 }
195
196 return array(
197 'app_id' => $new_app_id,
198 'msg' => '',
199 );
200 } else {
201 return array(
202 'app_id' => false,
203 'msg' => $wpdb->last_error,
204 );
205 }
206
207 }
208
209 public static function copy(
210 $app_id
211 ) {
212
213 $app = self::get_by_id( $app_id );
214 if ( false === $app ) {
215 return false;
216 }
217
218 return static::copy_all( $app );
219
220 }
221
222 public static function update_theme(
223 $app_id,
224 $app_theme
225 ) {
226
227 global $wpdb;
228 $wpdb->update(
229 static::get_base_table_name(),
230 array(
231 'app_theme' => $app_theme,
232 ),
233 array(
234 'app_id' => $app_id,
235 )
236 );
237
238 return $wpdb->last_error;
239
240 }
241
242 }
243
244 }