PluginProbe
WP Directory Kit / 1.2.4
WP Directory Kit v1.2.4
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 / Field_m.php

Field_m.php in WP Directory Kit 1.2.4, at application/models/Field_m.php

175 lines 5.7 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 Field_m extends Winter_MVC_Model {
9
10 public $_table_name = 'wdk_fields';
11 public $_order_by = 'order_index,idfield';
12 public $_primary_key = 'idfield';
13 public $_own_columns = array();
14 public $_timestamps = TRUE;
15 protected $_primary_filter = 'intval';
16 public $form_admin = array();
17 public $fields_list = NULL;
18
19 public $fields_validations = array();
20
21 public function __construct(){
22 $this->fields_validations = array(
23 'is_numerical'=> __('Numerical', 'wpdirectorykit'),
24 'is_phone'=> __('Phone', 'wpdirectorykit'),
25 'is_email'=> __('Email', 'wpdirectorykit'),
26 );
27
28 parent::__construct();
29 }
30
31 /* [START] For dynamic data table */
32
33 public function get_available_fields()
34 {
35 $fields = $this->db->list_fields($this->_table_name);
36
37 return $fields;
38 }
39
40 public function total_lang($where = array())
41 {
42 $this->db->select('COUNT(*) as total_count');
43 $this->db->from($this->_table_name);
44 $this->db->where($where);
45 $this->db->order_by($this->_order_by);
46 $query = $this->db->get();
47 $res = $this->db->results();
48
49 if(isset($res[0]->total_count))
50 return $res[0]->total_count;
51
52 return 0;
53 }
54
55 public function get_pagination_lang($limit, $offset, $where = array())
56 {
57 $this->db->select('*');
58 $this->db->from($this->_table_name);
59 $this->db->where($where);
60 $this->db->limit($limit);
61 $this->db->offset($offset);
62 $this->db->order_by($this->_order_by);
63 $query = $this->db->get();
64
65 if ($this->db->num_rows() > 0)
66 return $this->db->results();
67
68 return array();
69 }
70
71 public function check_deletable($id)
72 {
73 if(wmvc_user_in_role('administrator')) return true;
74
75 return false;
76 }
77
78
79 /* [END] For dynamic data table */
80
81 public function get_fields_data($field_id = NULL) {
82 static $fields_data = array();
83 if(empty($fields_data)){
84 $query = $this->get();
85 if ($this->db->num_rows() > 0) {
86 foreach($this->db->results() as $field) {
87 $fields_data[$field->idfield] = $field;
88 }
89 }
90 }
91
92 if(!empty($field_id))
93 if(isset($fields_data[(int)$field_id])){
94 return $fields_data[(int)$field_id];
95 } else {
96 return NULL;
97 }
98
99 return $fields_data;
100
101 }
102
103 public function get_sections() {
104 static $sections = array();
105 /* hard section, for uncategory */
106
107 foreach ($this->field_m->get() as $field) {
108 if(wmvc_show_data('field_type',$field) == 'SECTION'){
109 $sections[wmvc_show_data('idfield',$field)] = wmvc_show_data('field_label',$field);
110 }
111 }
112
113 return $sections;
114 }
115
116 public function get_fields_section() {
117 static $fields_section = array();
118
119 $section_id = '0';
120 /* hard section, for uncategory */
121 $this->data['fields_sections'][$section_id] = array(
122 "idfield" => $section_id,
123 "field_type" => "SECTION",
124 "is_locked" =>0,
125 "is_table_visible" =>0,
126 "is_visible_frontend" => 1,
127 "is_visible_dashboard" => 1,
128 "is_hardlocked" => 0,
129 "is_required" => 0,
130 "is_price_format" => 0,
131 "columns_number" => "12",
132 "field_label" => "Unsection",
133 "prefix" => '',
134 "suffix" => '',
135 "values_list" => '',
136 "placeholder" => '',
137 "hint" =>''
138 );
139
140 foreach ($this->field_m->get() as $field) {
141 if(wmvc_show_data('field_type',$field) == 'SECTION'){
142 $section_id = wmvc_show_data('idfield', $field);
143 $fields_section[$section_id] = array(
144 "idfield" => $section_id,
145 "field_type" => wmvc_show_data('field_type',$field),
146 "is_locked" =>wmvc_show_data('is_locked',$field),
147 "is_table_visible" =>wmvc_show_data('is_table_visible',$field),
148 "is_visible_frontend" => wmvc_show_data('is_visible_frontend',$field),
149 "is_visible_dashboard" => wmvc_show_data('is_visible_dashboard',$field),
150 "is_hardlocked" => wmvc_show_data('is_hardlocked',$field),
151 "is_required" => wmvc_show_data('is_required',$field),
152 "is_price_format" => wmvc_show_data('is_required',$field),
153 "columns_number" => wmvc_show_data('columns_number',$field),
154 "field_label" => wmvc_show_data('field_label',$field),
155 "prefix" => wmvc_show_data('prefix',$field),
156 "suffix" => wmvc_show_data('suffix',$field),
157 "values_list" => wmvc_show_data('values_list',$field),
158 "placeholder" => wmvc_show_data('placeholder',$field),
159 "hint" =>wmvc_show_data('hint',$field),
160 "fields" => array()
161 );
162 } else {
163 $fields_section[$section_id]["fields"][] = $field;
164 }
165 }
166 return $fields_section;
167 }
168
169 /* only admin can edit */
170 public function is_related($item_id, $user_id, $method = 'edit')
171 {
172 return false;
173 }
174 }
175 ?>