| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
class Editlog_m extends Winter_MVC_Model { |
| 9 |
|
| 10 |
public $_table_name = 'wdk_editlog'; |
| 11 |
public $_order_by = 'ideditlog'; |
| 12 |
public $_primary_key = 'ideditlog'; |
| 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' => 'post_id', |
| 25 |
'field_label' => __('Listing Id', 'wpdirectorykit'), |
| 26 |
'hint' => '', |
| 27 |
'field_type' => 'INPUTBOX', |
| 28 |
'rules' => 'required' |
| 29 |
), |
| 30 |
array( |
| 31 |
'field' => 'user_id', |
| 32 |
'field_label' => __('User Id', 'wpdirectorykit'), |
| 33 |
'hint' => '', |
| 34 |
'field_type' => 'INPUTBOX', |
| 35 |
'rules' => 'required' |
| 36 |
), |
| 37 |
array( |
| 38 |
'field' => 'date', |
| 39 |
'field_label' => __('Date', 'wpdirectorykit'), |
| 40 |
'hint' => '', |
| 41 |
'field_type' => 'DATETIME', |
| 42 |
'rules' => 'trim' |
| 43 |
), |
| 44 |
array( |
| 45 |
'field' => 'ip', |
| 46 |
'field_label' => __('IP', 'wpdirectorykit'), |
| 47 |
'hint' => '', |
| 48 |
'field_type' => 'INPUTBOX', |
| 49 |
'rules' => 'trim' |
| 50 |
), |
| 51 |
array( |
| 52 |
'field' => 'comment', |
| 53 |
'field_label' => __('Comment', 'wpdirectorykit'), |
| 54 |
'hint' => '', |
| 55 |
'field_type' => 'INPUTBOX', |
| 56 |
'rules' => 'trim' |
| 57 |
), |
| 58 |
); |
| 59 |
|
| 60 |
foreach($this->fields_list as $key=>$field) |
| 61 |
{ |
| 62 |
$this->fields_list[$key]['label'] = $field['field_label']; |
| 63 |
} |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
public function get_available_fields() |
| 68 |
{ |
| 69 |
$fields = $this->db->list_fields($this->_table_name); |
| 70 |
|
| 71 |
return $fields; |
| 72 |
} |
| 73 |
|
| 74 |
public function total($where = array()) |
| 75 |
{ |
| 76 |
$this->db->select('COUNT(*) as total_count'); |
| 77 |
$this->db->from($this->_table_name); |
| 78 |
|
| 79 |
$this->db->where($where); |
| 80 |
$this->db->order_by($this->_order_by); |
| 81 |
|
| 82 |
$query = $this->db->get(); |
| 83 |
|
| 84 |
$res = $this->db->results(); |
| 85 |
|
| 86 |
if(isset($res[0]->total_count)) |
| 87 |
return $res[0]->total_count; |
| 88 |
|
| 89 |
return 0; |
| 90 |
} |
| 91 |
|
| 92 |
public function get_pagination_listing($listing_id, $limit = NULL, $offset = 0, $where = array(), $order_by = NULL, $custom_select = NULL) |
| 93 |
{ |
| 94 |
if(!empty($custom_select)) { |
| 95 |
$this->db->select($custom_select); |
| 96 |
} else { |
| 97 |
$this->db->select('*'); |
| 98 |
} |
| 99 |
|
| 100 |
global $wpdb; |
| 101 |
$this->db->join($wpdb->users.' ON '.$this->_table_name.'.user_id = '.$wpdb->users.'.ID', NULL, 'LEFT'); |
| 102 |
|
| 103 |
$this->db->from($this->_table_name); |
| 104 |
|
| 105 |
$this->db->where($where); |
| 106 |
$this->db->where('post_id', $listing_id); |
| 107 |
|
| 108 |
if(!empty($limit)) { |
| 109 |
$this->db->limit($limit); |
| 110 |
if(empty($offset)) $offset = 0; |
| 111 |
$this->db->offset($offset); |
| 112 |
} |
| 113 |
|
| 114 |
if(!empty($order_by)){ |
| 115 |
$this->db->order_by($order_by); |
| 116 |
} else { |
| 117 |
$this->db->order_by($this->_order_by); |
| 118 |
} |
| 119 |
|
| 120 |
$query = $this->get(); |
| 121 |
|
| 122 |
if ($this->db->num_rows() > 0) |
| 123 |
return $this->db->results(); |
| 124 |
|
| 125 |
return array(); |
| 126 |
} |
| 127 |
|
| 128 |
public function get_pagination($limit, $offset = 0, $where = array(), $order_by = NULL, $custom_select = NULL) |
| 129 |
{ |
| 130 |
if(!empty($custom_select)) { |
| 131 |
$this->db->select($custom_select); |
| 132 |
} else { |
| 133 |
$this->db->select('*'); |
| 134 |
} |
| 135 |
|
| 136 |
$this->db->where($where); |
| 137 |
|
| 138 |
global $wpdb; |
| 139 |
$this->db->join($wpdb->users.' ON '.$this->_table_name.'.user_id = '.$wpdb->users.'.ID', NULL, 'LEFT'); |
| 140 |
|
| 141 |
$this->db->from($this->_table_name); |
| 142 |
|
| 143 |
$this->db->where($where); |
| 144 |
|
| 145 |
if(!empty($limit)) { |
| 146 |
$this->db->limit($limit); |
| 147 |
if(empty($offset)) $offset = 0; |
| 148 |
$this->db->offset($offset); |
| 149 |
} |
| 150 |
|
| 151 |
if(!empty($order_by)){ |
| 152 |
$this->db->order_by($order_by); |
| 153 |
} else { |
| 154 |
$this->db->order_by($this->_order_by); |
| 155 |
} |
| 156 |
|
| 157 |
$query = $this->get(); |
| 158 |
|
| 159 |
if ($this->db->num_rows() > 0) |
| 160 |
return $this->db->results(); |
| 161 |
|
| 162 |
return array(); |
| 163 |
} |
| 164 |
|
| 165 |
public function check_deletable($id) |
| 166 |
{ |
| 167 |
if(wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) return true; |
| 168 |
} |
| 169 |
|
| 170 |
public function delete($id) { |
| 171 |
|
| 172 |
if(!$this->check_deletable($id)) return false; |
| 173 |
|
| 174 |
parent::delete($id); |
| 175 |
|
| 176 |
return true; |
| 177 |
} |
| 178 |
|
| 179 |
public function is_related($item_id, $user_id, $method = 'edit') |
| 180 |
{ |
| 181 |
if(wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) return true; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
public function delete_where($where) |
| 186 |
{ |
| 187 |
$this->db->where($where); |
| 188 |
$this->db->delete($this->_table_name); |
| 189 |
} |
| 190 |
|
| 191 |
} |
| 192 |
?> |