PluginProbe
WP Directory Kit / 1.1.0
WP Directory Kit v1.1.0
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.1.0, at application/models/Field_m.php

165 lines 5.3 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';
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 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 $query = $this->db->get();
39 $res = $this->db->results();
40
41 if(isset($res[0]->total_count))
42 return $res[0]->total_count;
43
44 return 0;
45 }
46
47 public function get_pagination_lang($limit, $offset, $where = array())
48 {
49 $this->db->select('*');
50 $this->db->from($this->_table_name);
51 $this->db->where($where);
52 $this->db->limit($limit);
53 $this->db->offset($offset);
54 $this->db->order_by($this->_order_by);
55 $query = $this->db->get();
56
57 if ($this->db->num_rows() > 0)
58 return $this->db->results();
59
60 return array();
61 }
62
63 public function check_deletable($id)
64 {
65 if(wmvc_user_in_role('administrator')) return true;
66
67 return false;
68 }
69
70
71 /* [END] For dynamic data table */
72
73 public function get_fields_data($field_id = NULL) {
74 static $fields_data = array();
75 if(empty($fields_data)){
76 $query = $this->get();
77 if ($this->db->num_rows() > 0) {
78 foreach($this->db->results() as $field) {
79 $fields_data[$field->idfield] = $field;
80 }
81 }
82 }
83
84 if(!empty($field_id))
85 if(isset($fields_data[(int)$field_id])){
86 return $fields_data[(int)$field_id];
87 } else {
88 return NULL;
89 }
90
91 return $fields_data;
92
93 }
94
95 public function get_sections() {
96 static $sections = array();
97 /* hard section, for uncategory */
98
99 foreach ($this->field_m->get() as $field) {
100 if(wmvc_show_data('field_type',$field) == 'SECTION'){
101 $sections[wmvc_show_data('idfield',$field)] = wmvc_show_data('field_label',$field);
102 }
103 }
104
105 return $sections;
106 }
107
108 public function get_fields_section() {
109 static $fields_section = array();
110
111 $section_id = '0';
112 /* hard section, for uncategory */
113 $this->data['fields_sections'][$section_id] = array(
114 "idfield" => $section_id,
115 "field_type" => "SECTION",
116 "is_locked" =>0,
117 "is_table_visible" =>0,
118 "is_visible_frontend" => 1,
119 "is_visible_dashboard" => 1,
120 "is_hardlocked" => 0,
121 "is_required" => 0,
122 "is_price_format" => 0,
123 "columns_number" => "12",
124 "field_label" => "Unsection",
125 "prefix" => '',
126 "suffix" => '',
127 "values_list" => '',
128 "hint" =>''
129 );
130
131 foreach ($this->field_m->get() as $field) {
132 if(wmvc_show_data('field_type',$field) == 'SECTION'){
133 $section_id = wmvc_show_data('idfield', $field);
134 $fields_section[$section_id] = array(
135 "idfield" => $section_id,
136 "field_type" => wmvc_show_data('field_type',$field),
137 "is_locked" =>wmvc_show_data('is_locked',$field),
138 "is_table_visible" =>wmvc_show_data('is_table_visible',$field),
139 "is_visible_frontend" => wmvc_show_data('is_visible_frontend',$field),
140 "is_visible_dashboard" => wmvc_show_data('is_visible_dashboard',$field),
141 "is_hardlocked" => wmvc_show_data('is_hardlocked',$field),
142 "is_required" => wmvc_show_data('is_required',$field),
143 "is_price_format" => wmvc_show_data('is_required',$field),
144 "columns_number" => wmvc_show_data('columns_number',$field),
145 "field_label" => wmvc_show_data('field_label',$field),
146 "prefix" => wmvc_show_data('prefix',$field),
147 "suffix" => wmvc_show_data('suffix',$field),
148 "values_list" => wmvc_show_data('values_list',$field),
149 "hint" =>wmvc_show_data('hint',$field),
150 "fields" => array()
151 );
152 } else {
153 $fields_section[$section_id]["fields"][] = $field;
154 }
155 }
156 return $fields_section;
157 }
158
159 /* only admin can edit */
160 public function is_related($item_id, $user_id, $method = 'edit')
161 {
162 return false;
163 }
164 }
165 ?>