<?php
Class Activity_Model extends CI_Model
{
      //array with categories to be selected
    function category_options()
    {
        $category_options = array("Email", "Type");
        return $category_options;
    }
    
    //search for members
    //$category will be the category item selected
    //$search_for will be whats in the input box
    function activity_search($category, $a, $limit, $offset, $sort_by, $sort_order)
    {
        $sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
	$sort_columns = array('email', 'type', 'date', 'time');
	$sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by 
                        : 'date';
		
      //Change Below
      $q = $this->db->select('email, type, date, time')
		    ->from('activity')
	            ->limit($limit, $offset)
		    ->order_by($sort_by, $sort_order);
        
      
      //if there is a length in the first_name 
        
    //  if(strlen($query_array['first_name']))
      //{
      $q->where($category, $a);//$query_array['searchinfo']);
      //}
      
      //save result for all items
      $ret['rows'] = $q->get()->result();
                
                
                // count query
		$q = $this->db->select('COUNT(*) as count', FALSE)
			->from('users');
		
                //get result
		$tmp = $q->get()->result();
		
                //set result of count
		$ret['num_rows'] = $tmp[0]->count;
                 
		
		return $ret;
    }
    
    function activity_search_no_where_clause($category, $limit, $offset, $sort_by, $sort_order)
    {
        $sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
	$sort_columns = array('email', 'type', 'date', 'time');
	$sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by 
                        : 'date';
		
      //Change Below
      $q = $this->db->select('email, type, date, time')
		    ->from('activity')
	            ->limit($limit, $offset)
		    ->order_by($sort_by, $sort_order);
        
      
      //save result for all items
      $ret['rows'] = $q->get()->result();
                
               	
      return $ret;
    }
    
    //adds an activity to the database
    function insert_activity($email, $type, $date, $time)
    {
      $to_insert = array(
      'email' => $email,
      'type' => $type,
      'date' => $date,
      'time' => $time,
       );
      
      $this->db->insert('activity', $to_insert); 
    }
 
    
}
?>
