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

class Dashboard_Model extends CI_Model
{
    
    /**
     * This function used to check the login credentials of the user
     * @param string $email : This is email of the user
     * @param string $password : This is encrypted password of the user
     */
    function Count_Users()
    {
        $query = $this->db->get('users');
        
       if($query->num_rows()>0)
       {
            return $query->num_rows();
       }

       else
       {
           return false;
       }
    }

    function Count_Titles()
    {
        $query = $this->db->get('ballot');
        
       if($query->num_rows()>0)
       {
            return $query->num_rows();
       }

       else
       {
           return false;
       }
    }

    function Count_Candidates()
    {
        $query = $this->db->get('participants');
        
       if($query->num_rows()>0)
       {
            return $query->num_rows();
       }

       else
       {
           return false;
       }
    }

    function Count_Votes()
    {
       // $query = $this->db->select_sum('vote')->from('participants')->get();
		
		 $query = $this->db->select_sum('vote')->from('ballot_status')->get();
        
       if($query->num_rows()>0)
       {
            return ($query->result()[0]->vote) ;
       }

       else
       {
           return false;
       }
    }
    
    function Fetch_Ballot_Data()
    {
       // $query = $this->db->select('*')->from('ballot')->get();
$this->db->select('*,COUNT(ballot_status.vote) as t_votes');
$this->db->from('ballot');
$this->db->join('ballot_status','ballot_status.ballot_name=ballot.ballot_name')->where('ballot_status.vote','1');
$this->db->group_by('ballot.ballot_name');	
$query=$this->db->get();

       if($query->num_rows()>0)
       {
             return $query->result();
       }

       else
       {
           return false;
       }
    }

}

?>
