PluginProbe
WP Directory Kit / 1.2.3
WP Directory Kit v1.2.3
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 1.4.0 1.4.1 All 35 releases
wpdirectorykit / application / models / Listingfield_m.php

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

155 lines 4.4 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'] == 'TEXTAREA_WYSIWYG')
127 {
128 $sql = "ALTER TABLE `{$table}`
129 ADD `$column_name` TEXT NULL DEFAULT NULL;";
130 }
131 else if($field_data['field_type'] == 'NUMBER')
132 {
133 $sql = "ALTER TABLE `{$table}`
134 ADD `$column_name` DECIMAL(16,2) NULL DEFAULT NULL;";
135 }
136 else if($field_data['field_type'] == 'DATE')
137 {
138 $sql = "ALTER TABLE `{$table}`
139 ADD `$column_name` DATETIME NULL DEFAULT NULL;";
140 }
141 else if($field_data['field_type'] == 'CHECKBOX')
142 {
143 $sql = "ALTER TABLE `{$table}`
144 ADD `$column_name` BOOLEAN NULL DEFAULT NULL;";
145 } else {
146 /* if type not exactly */
147 return false;
148 }
149
150 if(!isset($existing_fields[$column_name]))
151 $query_result = $wpdb->query( $sql );
152 }
153
154 }
155 ?>