PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / application / models / Listingfield_m.php

Listingfield_m.php in WP Directory Kit 1.5.9, at application/models/Listingfield_m.php

178 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // If this file is called directly, abort.
4 if ( ! defined( 'WPINC' ) ) {
5 die;
6 }
7
8 class Listingfield_m extends Winter_MVC_Model {
9
10 public $_table_name = 'wdk_listings_fields';
11 public $_order_by = 'post_id DESC';
12 public $_primary_key = 'post_id';
13 public $_own_columns = array();
14 public $_timestamps = FALSE;
15 protected $_primary_filter = 'intval';
16 public $form_admin = array();
17 public $fields_list = NULL;
18
19 public function __construct(){
20 parent::__construct();
21 }
22
23 /* [START] For dynamic data table */
24
25 public function get_available_fields()
26 {
27 $fields = $this->db->list_fields($this->_table_name);
28
29 return $fields;
30 }
31
32 public function total_lang($where = array())
33 {
34 $this->db->select('COUNT(*) as total_count');
35 $this->db->from($this->_table_name);
36 $this->db->where($where);
37 $this->db->order_by($this->_order_by);
38
39 $query = $this->db->get();
40
41 $res = $this->db->results();
42
43 if(isset($res[0]->total_count))
44 return $res[0]->total_count;
45
46 return 0;
47 }
48
49 public function get_pagination_lang($limit, $offset, $where = array())
50 {
51 $this->db->select('*');
52 $this->db->from($this->_table_name);
53 $this->db->where($where);
54 $this->db->limit($limit);
55 $this->db->offset($offset);
56 $this->db->order_by($this->_order_by);
57
58 $query = $this->db->get();
59
60 if ($this->db->num_rows() > 0)
61 return $this->db->results();
62
63 return array();
64 }
65
66 public function check_deletable($id)
67 {
68 return true;
69 }
70
71 /* [END] For dynamic data table */
72
73 public function insert_custom_fields($fields, $data, $post_id)
74 {
75 $prepared_data = array('post_id' => $data['post_id']);
76
77 foreach($fields as $field)
78 {
79 if($field->field_type == 'SECTION')continue;
80
81 $column = 'field_'.$field->idfield.'_'.$field->field_type;
82
83 $prepared_data[$column] = NULL;
84
85 if(!empty($data['field_'.$field->idfield]))
86 {
87 $prepared_data[$column] = wp_kses_post($data['field_'.$field->idfield]);
88 }
89 }
90
91 if(empty($post_id)) // then insert
92 {
93 return $this->insert($prepared_data, NULL);
94 }
95 else // else update by post_id
96 {
97 return $this->insert($prepared_data, $post_id);
98 }
99 }
100
101 // Create table column for new added or edited fields
102 public function create_table_column($field_data, $field_id)
103 {
104 global $wpdb;
105
106 $existing_fields = $this->get_available_fields();
107
108 $table = $wpdb->prefix . 'wdk_listings_fields';
109 $column_name = 'field_'.$field_id.'_'.$field_data['field_type'];
110
111 if($field_data['field_type'] == 'INPUTBOX' || $field_data['field_type'] == 'DROPDOWN')
112 {
113 $sql = "ALTER TABLE `{$table}`
114 ADD `$column_name` TEXT NULL DEFAULT NULL;";
115 }
116 else if($field_data['field_type'] == 'DROPDOWNMULTIPLE')
117 {
118 $sql = "ALTER TABLE `{$table}`
119 ADD `$column_name` TEXT NULL DEFAULT NULL;";
120 }
121 else if($field_data['field_type'] == 'TEXTAREA')
122 {
123 $sql = "ALTER TABLE `{$table}`
124 ADD `$column_name` TEXT NULL DEFAULT NULL;";
125 }
126 else if($field_data['field_type'] == 'FILEUPLOAD')
127 {
128 $sql = "ALTER TABLE `{$table}`
129 ADD `$column_name` TEXT NULL DEFAULT NULL;";
130 }
131 else if($field_data['field_type'] == 'TEXTAREA_WYSIWYG')
132 {
133 $sql = "ALTER TABLE `{$table}`
134 ADD `$column_name` TEXT NULL DEFAULT NULL;";
135 }
136 else if($field_data['field_type'] == 'NUMBER')
137 {
138 $sql = "ALTER TABLE `{$table}`
139 ADD `$column_name` DECIMAL(16,2) NULL DEFAULT NULL;";
140 }
141 else if($field_data['field_type'] == 'DATE')
142 {
143 $sql = "ALTER TABLE `{$table}`
144 ADD `$column_name` DATETIME NULL DEFAULT NULL;";
145 }
146 else if($field_data['field_type'] == 'CHECKBOX')
147 {
148 $sql = "ALTER TABLE `{$table}`
149 ADD `$column_name` BOOLEAN NULL DEFAULT NULL;";
150 } else {
151 /* if type not exactly */
152 return false;
153 }
154
155 if(!isset($existing_fields[$column_name]))
156 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
157 $query_result = $wpdb->query( $sql );
158
159 }
160
161 // Create table column for new added or edited fields
162 public function delete_table_column($field_data, $field_id)
163 {
164 global $wpdb;
165
166 $table = $wpdb->prefix . 'wdk_listings_fields';
167 $column_name = 'field_'.$field_id.'_'.wmvc_show_data('field_type',$field_data);
168
169 $query_result = $wpdb->query(
170 $wpdb->prepare(
171 "ALTER TABLE `{$table}` DROP %s;",
172 $column_name
173 )
174 );
175 }
176
177 }
178 ?>