|
Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/laciasmara.com/public_html/shop/application/models/ |
Upload File : |
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Review_m extends CI_Model
{
private $table = 'product_review';
public function get_all_reviews()
{
return $this->db->select('*, AVG(rating) AS average_rating, COUNT(id) AS total_reviews')
->from($this->table)
->get()
->result();
}
/**
* Get average rating and total reviews for a specific product.
*
* @param int $product_id The ID of the product.
* @return array An associative array with average rating and total reviews.
*/
public function get_product_reviews($product_id)
{
return $this->db->select('AVG(rating) AS average_rating, COUNT(id) AS total_reviews')
->from($this->table)
->where('product_id', $product_id)
->get()
->row_array();
}
/**
* Get Review by ID.
* @param int $review_id The ID of the review.
* @return object The review object.
*/
public function get_review_by_id($review_id)
{
return $this->db->select('*')
->from($this->table)
->where('id', $review_id)
->get()
->row();
}
/**
* Get all reviews for a specific product.
*
* @param int $product_id The ID of the product.
* @param int $limit Number of reviews to retrieve.
* @param int $offset Offset for pagination.
* @return array An array of reviews.
*/
public function get_reviews($product_id, $limit = 10, $offset = 0)
{
return $this->db->select('rating, subject, review, display_name, review_date')
->from($this->table)
->where('product_id', $product_id)
->limit($limit, $offset)
->order_by('review_date', 'DESC')
->get()
->result_array();
}
/**
* Add a new review for a product.
*
* @param array $data Associative array containing review data.
* @return bool True on success, false on failure.
*/
public function add_review($data)
{
return $this->db->insert($this->table, $data);
}
}