<?php
class ModelCatalogStoreRating extends Model {

  public function getStoreRatings(){
		$sql = "SELECT * from " . DB_PREFIX . "store_rating WHERE allow = 1 and status = 1";
		$query = $this->db->query($sql);
		return $query->rows;
	}
  
  public function getStoreRating(){
		$sql = "SELECT * from " . DB_PREFIX . "store_rating WHERE customer_id = " . (int)$this->customer->getId();
		$query = $this->db->query($sql);
		return $query->rows;
	}
  
  public function addStoreRating($data){    
    $sql = "DELETE FROM " . DB_PREFIX . "store_rating WHERE customer_id = " . (int)$this->customer->getId();    
		$query = $this->db->query($sql);
    
    $sql = "INSERT INTO " . DB_PREFIX . "store_rating SET customer_id = " . (int)$this->customer->getId() . ", ".  
    " author = '" . $this->db->escape($this->customer->getFirstName()) . ' ' . $this->db->escape($this->customer->getLastName()) . "', ".
    " text = '" . $this->db->escape($data['text']) . "', ".
    " rating = " . (int)$data['rating'] . ", ".
    " allow = " . (int)$data['allow'] . ", ".
    " date_added = NOW() ";
    
		$query = $this->db->query($sql);
	}

}
