| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
class Dependfields_m extends Winter_MVC_Model { |
| 9 |
|
| 10 |
public $_table_name = 'wdk_dependfields'; |
| 11 |
public $_order_by = 'iddependfields'; |
| 12 |
public $_primary_key = 'iddependfields'; |
| 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 |
$this->fields_list = array( |
| 23 |
array( |
| 24 |
'field' => 'main_field', |
| 25 |
'field_label' => __('Main Field', 'wdk-membership'), |
| 26 |
'hint' => '', |
| 27 |
'field_type' => 'INPUTBOX', |
| 28 |
'rules' => 'required' |
| 29 |
), |
| 30 |
array( |
| 31 |
'field' => 'field_id', |
| 32 |
'field_label' => __('Field id', 'wdk-membership'), |
| 33 |
'hint' => '', |
| 34 |
'field_type' => 'INPUTBOX', |
| 35 |
'rules' => 'required' |
| 36 |
), |
| 37 |
array( |
| 38 |
'field' => 'hidden_fields_list', |
| 39 |
'field_label' => __('List with hidden fields', 'wdk-membership'), |
| 40 |
'hint' => '', |
| 41 |
'field_type' => 'INPUTBOX', |
| 42 |
'rules' => 'trim' |
| 43 |
), |
| 44 |
); |
| 45 |
|
| 46 |
foreach($this->fields_list as $key=>$field) |
| 47 |
{ |
| 48 |
$this->fields_list[$key]['label'] = $field['field_label']; |
| 49 |
} |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
public function get_available_fields() |
| 54 |
{ |
| 55 |
$fields = $this->db->list_fields($this->_table_name); |
| 56 |
|
| 57 |
return $fields; |
| 58 |
} |
| 59 |
|
| 60 |
public function total($where = array()) |
| 61 |
{ |
| 62 |
$this->db->select('COUNT(*) as total_count'); |
| 63 |
$this->db->from($this->_table_name); |
| 64 |
|
| 65 |
$this->db->where($where); |
| 66 |
$this->db->order_by($this->_order_by); |
| 67 |
|
| 68 |
$query = $this->db->get(); |
| 69 |
|
| 70 |
$res = $this->db->results(); |
| 71 |
|
| 72 |
if(isset($res[0]->total_count)) |
| 73 |
return $res[0]->total_count; |
| 74 |
|
| 75 |
return 0; |
| 76 |
} |
| 77 |
|
| 78 |
public function get_pagination($limit, $offset = 0, $where = array(), $order_by = NULL, $custom_select = NULL) |
| 79 |
{ |
| 80 |
if(!empty($custom_select)) { |
| 81 |
$this->db->select($custom_select); |
| 82 |
} else { |
| 83 |
$this->db->select('*'); |
| 84 |
} |
| 85 |
|
| 86 |
$this->db->from($this->_table_name); |
| 87 |
|
| 88 |
$this->db->where($where); |
| 89 |
|
| 90 |
if(!empty($limit)) { |
| 91 |
$this->db->limit($limit); |
| 92 |
if(empty($offset)) $offset = 0; |
| 93 |
$this->db->offset($offset); |
| 94 |
} |
| 95 |
|
| 96 |
if(!empty($order_by)){ |
| 97 |
$this->db->order_by($order_by); |
| 98 |
} else { |
| 99 |
$this->db->order_by($this->_order_by); |
| 100 |
} |
| 101 |
|
| 102 |
$query = $this->get(); |
| 103 |
|
| 104 |
if ($this->db->num_rows() > 0) |
| 105 |
return $this->db->results(); |
| 106 |
|
| 107 |
return array(); |
| 108 |
} |
| 109 |
|
| 110 |
public function check_deletable($id) |
| 111 |
{ |
| 112 |
if(wmvc_user_in_role('administrator')) return true; |
| 113 |
} |
| 114 |
|
| 115 |
public function delete($id) { |
| 116 |
|
| 117 |
if(!$this->check_deletable($id)) return false; |
| 118 |
|
| 119 |
parent::delete($id); |
| 120 |
|
| 121 |
return true; |
| 122 |
} |
| 123 |
|
| 124 |
public function is_related($item_id, $user_id, $method = 'edit') |
| 125 |
{ |
| 126 |
if(wmvc_user_in_role('administrator')) return true; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
public function delete_where($where) |
| 131 |
{ |
| 132 |
$this->db->where($where); |
| 133 |
$this->db->delete($this->_table_name); |
| 134 |
} |
| 135 |
|
| 136 |
} |
| 137 |
?> |