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

class Mo_survey extends CI_Model {
	
	function getSoal()
	{
		return $this->db->get('t_soal')->result();
	}

	function gender()
	{
		$sql = $this->db->get('t_gender')->result();
		foreach($sql as $s):
			$list[$s->f_gender_code]= $s->f_gender_name;
		endforeach;
		
		return $list;
	}

	function assessment_result($id)
	{
		$sql_kategori = $this->db->get('t_kondisi')->result();
		$kategori = array();
		$i=0;
		foreach($sql_kategori as $a)
		{
			$kategori[$i] = $a->f_kondisi_name;
			$i++;
		}
		
		$this->db->select('f_id, f_nama, f_gender, f_hp, f_email, f_sekolah, f_jawab, f_yangke, f_ipaddres, date_format(f_date_on,"%d %b %Y %H:%i") f_date_on',false);
		$this->db->where('f_id',$id);
		$sql = $this->db->get('t_survey');
		if($sql->num_rows()>0)
		{
			
			$b= $sql->row_array();
			$c = unserialize($b['f_jawab']);
			$i=0;
			foreach($sql_kategori as $d)
			{
				$tabel[$i]['name'] = $d->f_kondisi_name;
				foreach($c[$d->f_kondisi_id] as $key => $val)
				{
					$ar[$i] += $val;
					$tabel[$i]['y'] += $val;
				}
				$i++;
			}
			
			$final = array('res'=>'ok', 'kondisi'=> $sql_kategori, 'peserta'=>$b,'tabel'=>$tabel,'kategori'=>$kategori,'hasil'=>$ar);
		}
		else
		{
			$final = array('res'=>'no', 'kondisi'=> false, 'peserta'=>false,'tabel'=>false,'kategori'=>false,'hasil'=>false);
		}
		return $final;		
	}
		
	function alias_url($alias)
	{
		$this->db->select('f_account_id');
		$this->db->where('alias_url',$alias);
		$sql = $this->db->get('trn_account');
		if($sql->num_rows() > 0)
		{
			return $sql->row();
		}
		else
		{
			return false;
		}
	}

	function fnEventExp($idAccount)
	{
		$sql = $this->db->select('f_event_id,f_event_start as ed,f_event_end as dt',false)->where('f_account_id',$idAccount)->order_by('f_event_id','desc')->get('t_event');
		if($sql->num_rows() >0 )
		{
			return $sql->row();
		}
		else
		{
			return false;
		}
	}
}
