0byt3m1n1
Path:
/
data
/
17
/
1
/
18
/
11
/
1670011
/
user
/
1801231
/
htdocs
/
marketting
/
system
/
application
/
models
/
[
Home
]
File: reviews_model.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); /* | ------------------------------------------------------------------------- | COPYRIGHT NOTICE | Copyright 2008 JROX Technologies, Inc. All Rights Reserved. | ------------------------------------------------------------------------- | This script may be only used and modified in accordance to the license | agreement attached (license.txt) except where expressly noted within | commented areas of the code body. This copyright notice and the | comments above and below must remain intact at all times. By using this | code you agree to indemnify JROX Technologies, Inc, its corporate agents | and affiliates from any liability that might arise from its use. | | Selling the code for this program without prior written consent is | expressly forbidden and in violation of Domestic and International | copyright laws. | | ------------------------------------------------------------------------- | FILENAME - reviews_model.php | ------------------------------------------------------------------------- | | This model handles the functions for managing the product reviews | */ class Reviews_Model extends Model { function _add_review($id = '') { $data = $this->db_validation_model->_clean_data($_POST); $data['product_id'] = $id; $data['member_id'] = $this->session->userdata('userid'); $data['date'] = _generate_timestamp(); //insert into db if (!$this->db->insert('products_reviews', $data)) { show_error($this->lang->line('could_not_add_review')); //log error log_message('error', 'Could not insert review into products_reviews table'); return false; } else { $review_id = $this->db->insert_id(); //log success log_message('info', 'review '. $review_id . ' inserted into products_reviews table'); } return $review_id; } // ------------------------------------------------------------------------ function _change_status($data = '', $type = '0') { foreach ($data as $id) { $this->db->where('id', $id); if ($type == 'delete') { $this->_delete_review((int)($id)); } else { //update member in db $data = array( 'status' => $type, ); if (!$this->db->update('products_reviews', $data)) { show_error($this->lang->line('could_not_update_review')); //log error log_message('error', 'Could not update review ID #' . $id . ' in products_reviews table'); return false; } //log success log_message('info', 'Status Changed for review ID# ' . $id); } } return true; } // ------------------------------------------------------------------------ function _update_review($id = '') { $data = $this->db_validation_model->_clean_data($_POST); $this->db->where('id', $id); if (!$this->db->update('products_reviews', $data)) { show_error($this->lang->line('could_not_update_review')); //log error log_message('error', 'Could not update review into products_reviews table'); return false; } else { $review_id = $this->db->insert_id(); //log success log_message('info', 'review '. $review_id . ' updated in products_reviews table'); } return $review_id; } // ------------------------------------------------------------------------ function _get_product_review_details($id = '') { $sql = 'SELECT ' . $this->db->dbprefix('products_reviews') . '.*, (SELECT username from ' . $this->db->dbprefix('members') . ' WHERE ' . $this->db->dbprefix('products_reviews') . '.member_id = ' . $this->db->dbprefix('members') . '.member_id) as member, (SELECT product_name from ' . $this->db->dbprefix('products') . ' WHERE ' . $this->db->dbprefix('products_reviews') . '.product_id = ' . $this->db->dbprefix('products') . '.product_id) as product FROM ' . $this->db->dbprefix('products_reviews') . ' WHERE ' . $this->db->dbprefix('products_reviews') . '.id = ' . $id; $query = $this->db->query($sql); if ($query->num_rows() > 0) { return $query->result_array(); } return false; } // ------------------------------------------------------------------------ function _delete_review($id = '') { $this->db->where('id', $id); if ($query = $this->db->delete('products_reviews')) { return true; } return false; } // ------------------------------------------------------------------------ function _get_product_reviews($limit = 25, $offset = 0, $sort_column = '', $sort_order = '', $where_column = '', $where_value = '', $public = false) { //get all the products from db for list view if (!$sort_order) $sort_order = $this->config->item('dbs_rev_order'); if (!$sort_column) $sort_column = $this->config->item('dbs_rev_column'); if (!empty($where_column) && !empty($where_value)) { $sql = 'SELECT ' . $this->db->dbprefix('products_reviews') . '.*, (SELECT username from ' . $this->db->dbprefix('members') . ' WHERE ' . $this->db->dbprefix('products_reviews') . '.member_id = ' . $this->db->dbprefix('members') . '.member_id) as username, (SELECT product_name from ' . $this->db->dbprefix('products') . ' WHERE ' . $this->db->dbprefix('products_reviews') . '.product_id = ' . $this->db->dbprefix('products') . '.product_id) as product FROM ' . $this->db->dbprefix('products_reviews') . ' WHERE ' . $this->db->dbprefix('products_reviews') . '.product_id = ' . $where_value; if ($public == true) { $sql .= ' AND ' . $this->db->dbprefix('products_reviews') . '.status = \'1\' ORDER BY ' . $sort_column . ' ' . $sort_order; } else { $sql .= ' ORDER BY ' . $sort_column . ' ' . $sort_order . ' LIMIT ' . $offset. ', ' . $limit; } } else { $sql = 'SELECT ' . $this->db->dbprefix('products_reviews') . '.*, (SELECT username from ' . $this->db->dbprefix('members') . ' WHERE ' . $this->db->dbprefix('products_reviews') . '.member_id = ' . $this->db->dbprefix('members') . '.member_id) as username, (SELECT product_name from ' . $this->db->dbprefix('products') . ' WHERE ' . $this->db->dbprefix('products_reviews') . '.product_id = ' . $this->db->dbprefix('products') . '.product_id) as product FROM ' . $this->db->dbprefix('products_reviews') . ' ORDER BY ' . $sort_column . ' ' . $sort_order . ' LIMIT ' . $offset. ', ' . $limit; } $query = $this->db->query($sql); if ($query->num_rows() > 0) { return $query->result_array(); } return false; } // ------------------------------------------------------------------------ } ?>
© 2017 -
ZeroByte.ID
.