<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

class GuestModel extends CI_Model { 

    public function __construct(){
		parent::__construct();
		$this->load->database();
	}
	   

	function get_rows($where)
    {
		$sql = "select * from guest_tb where id > 0".$where;
		$query = $this->db->query($sql);
		return $query->result_array();
	}

	function delete_row($edit_id)
    {
		$this->db->delete('guest_tb', array('id' => $edit_id));
	}
	
	function get_row($id)
    {
        $sql   = "select * from guest_tb where id = '" . $id . "'";
        $query = $this->db->query($sql);
        $data  = $query->row_array();
        $sql   = "select * from prepackage_qr_tb where id > 0 and isDeleted = 0 and '" . $data['qr_token'] . "' LIKE CONCAT('%', token, '%') ";

        $query = $this->db->query($sql);
        
        return $query->row_array();
    }
    function get_qr_row($id)
    {
        $sql   = "select * from guest_tb where qr_token like '" . '%' . $id . '%' . "'";
        $query = $this->db->query($sql);

        return $query->row_array();
    }

    function get_guest_row($id)
    {
        $sql   = "select * from guest_tb where id = '" . $id . "'";
        $query = $this->db->query($sql);

        return $query->row_array();
    }

	public function update_row($update_data, $id)
	{
		$this->db->update('guest_tb', $update_data, $id);
	}
	
    function extra_face_count($id)
    {
        $sql = "select count(extra_faces_tb.id) as cnt from extra_faces_tb where guest_id = '" . $id . "'";
        $query = $this->db->query($sql);

        return $query->row_array();
    }
}