<?php 

class Waitlistlinkvar_model extends CI_Model {
     
           public function get_waitlistlinkvarurls($hash){
               $current_date = new DateTime();

    $datetimeforlink = date("Y-m-d H:i:s", $current_date->getTimestamp());
        $this->db->distinct();
        return $this->db
            ->select('*')
            ->from('waitlist')
            ->where('hash =', $hash)
            ->where('date_expires >', $datetimeforlink)
            ->where('status <>', 'BOOKED')
            ->get()->result_array();
    }
    
    
      public function _updatewaitlist($linkvar)
    {
        
        $this->db->where('hash', $linkvar['linkvarhash']);
        $status = array('status' => 'BOOKED');    
        if ( ! $this->db->update('waitlist', $status))
        {
            throw new Exception('Could not update waitlist record');
        }
    }

  public function get_batch($where_clause = '', $aggregates = FALSE)
    {
        if ($where_clause != '')
        {
            $this->db->where($where_clause);
        }

        $waitlisters = $this->db->get('waitlist')->result_array();

        return $waitlisters;
    }
    
      public function update($waitlist_id)
    {
           $this->db->where('id', $waitlist_id);
        $status = array('status' => 'BOOKED');    
        if ( ! $this->db->update('waitlist', $status))
        {
            throw new Exception('Could not update waitlist record');
        }
    }

}
