/home/hdwebsolution/www/sareenn/application/models/Admin_model.php
<?php

defined('BASEPATH') or exit('No direct script access allowed');



class Admin_model extends CI_Model

{



  public function __construct()

  {

    $this->load->database();
  }


  public function reset_db()

  {
    die;

    $this->db->truncate('products');
    $this->db->truncate('product_images');
    $this->db->truncate('product_variants');
  }

  public function reset_admin()

  {

    $this->db->truncate('admins');
  }



  // Insert registration data in database

  public function registration_insert($data)

  {

    // Query to check whether username already exist or not

    $this->db->select('*');

    $this->db->from('admins');

    $this->db->where('admin_email', $data['email']);

    $query = $this->db->get();

    if ($query->num_rows() == 0) {

      // Query to insert data in database

      $this->db->insert('admins', $data);

      return true;
    } else {

      return false;
    }
  }



  public function get_admin_info($admin_id)

  {

    $this->db->select('*');

    $this->db->where('id', $admin_id);

    $query = $this->db->get('admins');

    return $query->row(); // get the row first

  }



  // Admin Login



  public function admin_login($data)

  {

    $this->db->where('admin_email', $data['email']);

    $query = $this->db->get('admins');

    $result = $query->row(); // get the row first



    if (!empty($result) && password_verify($data['password'], $result->admin_password)) {

      // if this email exists, and the input password is verified using password_verify

      return $result;
    } else {

      return false;
    }
  }



  public function get_all_product_details($id)

  {

    $this->db->select('p.*, c.category_name');
    $this->db->from('products p');
    $this->db->join('categories c', 'p.category_id = c.id', 'left');
    $this->db->where('p.id', $id);
    $this->db->group_by('p.id');
    $query = $this->db->get();
    return $query->row();
  }

  public function get_all_products()

  {
    $this->db->select('p.*, c.category_name');
    $this->db->from('products p');
    $this->db->join('categories c', 'p.category_id = c.id', 'left');
    $this->db->group_by('p.id');
    $query = $this->db->get();
    return $query->result_array();
  }

  public function get_all_inactive_products()

  {
    $this->db->select('p.*, c.category_name');
    $this->db->from('products p');
    $this->db->join('categories c', 'p.category_id = c.id', 'left');
    $this->db->where('product_is_active', '0');
    $this->db->group_by('p.id');
    $query = $this->db->get();
    return $query->result_array();
  }


  ////////////////////////////////////////////////////////////////////////////////////////////////////////////


  public function get_website_settings()

  {

    $this->db->select('*');

    $this->db->from('settings');

    $query = $this->db->get();



    if ($query->num_rows() >= 1) {

      return $query->result_array();
    } else {

      return false;
    }
  }



  public function setting_create_request($create_data)

  {

    if ($this->db->insert('settings', $create_data)) {

      return true;
    } else {

      return false;
    }
  }



  public function setting_update_request($setting_id, $update_data)

  {

    if ($this->db->update('settings', $update_data, array('id' => $setting_id))) {

      return true;
    } else {

      return false;
    }
  }



  public function setting_delete_request($setting_id)

  {

    if ($this->db->delete('settings', array('id' => $setting_id))) {

      return true;
    } else {

      return false;
    }
  }
}