shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

review.php (4459B)


      1 <?php
      2 class ModelCatalogReview extends Model {
      3 	public function addReview($data) {
      4 		$this->db->query("INSERT INTO " . DB_PREFIX . "review SET author = '" . $this->db->escape($data['author']) . "', product_id = '" . (int)$data['product_id'] . "', text = '" . $this->db->escape(strip_tags($data['text'])) . "', rating = '" . (int)$data['rating'] . "', status = '" . (int)$data['status'] . "', date_added = '" . $this->db->escape($data['date_added']) . "'");
      5 
      6 		$review_id = $this->db->getLastId();
      7 
      8 		$this->cache->delete('product');
      9 
     10 		return $review_id;
     11 	}
     12 
     13 	public function editReview($review_id, $data) {
     14 		$this->db->query("UPDATE " . DB_PREFIX . "review SET author = '" . $this->db->escape($data['author']) . "', product_id = '" . (int)$data['product_id'] . "', text = '" . $this->db->escape(strip_tags($data['text'])) . "', rating = '" . (int)$data['rating'] . "', status = '" . (int)$data['status'] . "', date_added = '" . $this->db->escape($data['date_added']) . "', date_modified = NOW() WHERE review_id = '" . (int)$review_id . "'");
     15 
     16 		$this->cache->delete('product');
     17 	}
     18 
     19 	public function deleteReview($review_id) {
     20 		$this->db->query("DELETE FROM " . DB_PREFIX . "review WHERE review_id = '" . (int)$review_id . "'");
     21 
     22 		$this->cache->delete('product');
     23 	}
     24 
     25 	public function getReview($review_id) {
     26 		$query = $this->db->query("SELECT DISTINCT *, (SELECT pd.name FROM " . DB_PREFIX . "product_description pd WHERE pd.product_id = r.product_id AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS product FROM " . DB_PREFIX . "review r WHERE r.review_id = '" . (int)$review_id . "'");
     27 
     28 		return $query->row;
     29 	}
     30 
     31 	public function getReviews($data = array()) {
     32 		$sql = "SELECT r.review_id, pd.name, r.author, r.rating, r.status, r.date_added FROM " . DB_PREFIX . "review r LEFT JOIN " . DB_PREFIX . "product_description pd ON (r.product_id = pd.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
     33 
     34 		if (!empty($data['filter_product'])) {
     35 			$sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_product']) . "%'";
     36 		}
     37 
     38 		if (!empty($data['filter_author'])) {
     39 			$sql .= " AND r.author LIKE '" . $this->db->escape($data['filter_author']) . "%'";
     40 		}
     41 
     42 		if (isset($data['filter_status']) && $data['filter_status'] !== '') {
     43 			$sql .= " AND r.status = '" . (int)$data['filter_status'] . "'";
     44 		}
     45 
     46 		if (!empty($data['filter_date_added'])) {
     47 			$sql .= " AND DATE(r.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
     48 		}
     49 
     50 		$sort_data = array(
     51 			'pd.name',
     52 			'r.author',
     53 			'r.rating',
     54 			'r.status',
     55 			'r.date_added'
     56 		);
     57 
     58 		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
     59 			$sql .= " ORDER BY " . $data['sort'];
     60 		} else {
     61 			$sql .= " ORDER BY r.date_added";
     62 		}
     63 
     64 		if (isset($data['order']) && ($data['order'] == 'DESC')) {
     65 			$sql .= " DESC";
     66 		} else {
     67 			$sql .= " ASC";
     68 		}
     69 
     70 		if (isset($data['start']) || isset($data['limit'])) {
     71 			if ($data['start'] < 0) {
     72 				$data['start'] = 0;
     73 			}
     74 
     75 			if ($data['limit'] < 1) {
     76 				$data['limit'] = 20;
     77 			}
     78 
     79 			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
     80 		}
     81 
     82 		$query = $this->db->query($sql);
     83 
     84 		return $query->rows;
     85 	}
     86 
     87 	public function getTotalReviews($data = array()) {
     88 		$sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r LEFT JOIN " . DB_PREFIX . "product_description pd ON (r.product_id = pd.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
     89 
     90 		if (!empty($data['filter_product'])) {
     91 			$sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_product']) . "%'";
     92 		}
     93 
     94 		if (!empty($data['filter_author'])) {
     95 			$sql .= " AND r.author LIKE '" . $this->db->escape($data['filter_author']) . "%'";
     96 		}
     97 
     98 		if (isset($data['filter_status']) && $data['filter_status'] !== '') {
     99 			$sql .= " AND r.status = '" . (int)$data['filter_status'] . "'";
    100 		}
    101 
    102 		if (!empty($data['filter_date_added'])) {
    103 			$sql .= " AND DATE(r.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
    104 		}
    105 
    106 		$query = $this->db->query($sql);
    107 
    108 		return $query->row['total'];
    109 	}
    110 
    111 	public function getTotalReviewsAwaitingApproval() {
    112 		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review WHERE status = '0'");
    113 
    114 		return $query->row['total'];
    115 	}
    116 }