|
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 if (!defined('BASEPATH')) exit('No direct script access allowed');
class Product_manuals_m extends CI_Model
{
protected $table = 'product_manuals';
public function __construct()
{
parent::__construct();
}
function get_all_manuals()
{
$this->db->select('pm.*');
$this->db->from('product_manuals pm');
$this->db->order_by('pm.created_at', 'desc');
$query = $this->db->get();
return $query->result();
}
/**
* Insert new product manual
* @param array $data
* @return int|bool insert_id on success, false on failure
*/
public function insert($data)
{
$this->db->insert($this->table, $data);
if ($this->db->affected_rows() > 0) {
return $this->db->insert_id();
}
return false;
}
/**
* Check if a slug already exists
* @param string $slug
* @param int|null $exclude_id optional id to exclude (for edit mode)
* @return bool
*/
public function check_slug_exists($slug, $exclude_id = null)
{
$this->db->where('slug', $slug);
if ($exclude_id !== null) {
$this->db->where('id !=', $exclude_id);
}
$query = $this->db->get($this->table);
return $query->num_rows() > 0;
}
/**
* Check if a unique code already exists
* @param string $code
* @return bool
*/
public function check_code_exists($code)
{
$this->db->where('unique_code', $code);
$query = $this->db->get($this->table);
return $query->num_rows() > 0;
}
/**
* Get all manuals (with optional filters)
* @param array|null $filter
* @return array
*/
public function get_all($filter = null)
{
if (!empty($filter)) {
$this->db->where($filter);
}
$this->db->order_by('created_at', 'DESC');
return $this->db->get($this->table)->result_array();
}
/**
* Get manual by ID
* @param int $id
* @return array|null
*/
public function get_by_id($id)
{
return $this->db->get_where($this->table, ['id' => $id])->row();
}
/**
* Get manual by slug
* @param string $slug
* @return object|null
*/
public function get_by_slug($slug)
{
$this->db->select('product_manuals.*');
$this->db->from($this->table);
$this->db->where('product_manuals.slug', $slug);
$this->db->where('product_manuals.is_active', 1);
$query = $this->db->get();
return $query->row();
}
/**
* Increment view count
* @param int $id
* @return bool
*/
public function increment_view_count($id)
{
$this->db->set('view_count', 'view_count + 1', FALSE);
$this->db->where('id', $id);
return $this->db->update($this->table);
}
/**
* Update manual data
* @param int $id
* @param array $data
* @return bool
*/
public function update($id, $data)
{
$this->db->where('id', $id);
$this->db->update($this->table, $data);
return $this->db->affected_rows() >= 0;
}
/**
* Delete manual by ID
* @param int $id
* @return bool
*/
public function delete($id)
{
$this->db->where('id', $id);
return $this->db->delete($this->table);
}
/**
* Check if file exists
* @param int $id
* @return bool
*/
public function file_exists($id)
{
$manual = $this->db->get_where($this->table, ['id' => $id])->row();
if ($manual && file_exists(FCPATH . $manual->file_path)) {
return true;
}
return false;
}
function count_guides($is_active = null)
{
$this->db->from($this->table);
if (!is_null($is_active)) {
$this->db->where('is_active', $is_active);
}
return $this->db->count_all_results();
}
}