<?php
class M_kategori extends CI_Model{
		function tampil(){
			$this->db->order_by('namakategori ASC');			
			$query = $this->db->get('kategori');		
			return $query ;
		}	
		function filterkategori(){

			$this->db->select('a.namakategori, a.idkategori');
			$this->db->from('kategori as a ');
			$this->db->join('fasilitas as b', 'b.idkategori = a.idkategori');
			$this->db->where('b.status', '1');
			$this->db->order_by('a.namakategori', 'ASC');			
			$this->db->group_by('a.namakategori');			
			$query = $this->db->get();						   		
			return $query;	
		}

		function filekategori($idkategori){
			/*
			$this->db->select('a.filename, a.deskripsi, b.idkategori');
			$this->db->from('file as a  ');
			$this->db->join('fasilitas as b', ' b.idfasilitas = a.nmvalue', 'left');
			$this->db->where(' a.nmtable ', 'fasilitas');
			$this->db->where(' a.nmfield ', 'idfasilitas');
			$this->db->where(' b.idkategori ',$idkategori);
			$this->db->order_by('a.idfile DESC');
			$query = $this->db->get();			   
			$row = $query->row();		
			*/			
			$query = $this->db->query("SELECT a.filename, a.deskripsi, b.idkategori, b.idfasilitas
													FROM file as a 
													LEFT JOIN fasilitas as b ON b.idfasilitas = a.nmvalue
													WHERE a.nmtable='fasilitas' 
													AND a.nmfield = 'idfasilitas' 
													AND b.idkategori='$idkategori' ");    		
			return $query;			   
		}

		function detailfilekategori($idfasilitas){
			/*
			$this->db->select('a.filename, a.deskripsi, b.idkategori');
			$this->db->from('file as a  ');
			$this->db->join('fasilitas as b', ' b.idfasilitas = a.nmvalue', 'left');
			$this->db->where(' a.nmtable ', 'fasilitas');
			$this->db->where(' a.nmfield ', 'idfasilitas');
			$this->db->where(' b.idkategori ',$idkategori);
			$this->db->order_by('a.idfile DESC');
			$query = $this->db->get();			   
			$row = $query->row();		
			*/			
			$query = $this->db->query("SELECT a.filename, a.deskripsi, b.idkategori, b.idfasilitas
													FROM file as a 
													LEFT JOIN fasilitas as b ON b.idfasilitas = a.nmvalue
													WHERE a.nmtable='fasilitas' 
													AND a.nmfield = 'idfasilitas' 
													AND b.idfasilitas='$idfasilitas' ");    		
			return $query;			   
		}
		
		function edit($id){
			$query = $this->db->get_where('kategori',array('idkategori'=>$id));							
			return $query ;
		}

		function in($data_save,$table){
					$this->db->insert($table,$data_save);
		} 	
		function update($where,$data,$table){
				$this->db->where($where);
				$this->db->update($table,$data);
		}	
			function hapus($where,$table){
				$this->db->where($where);
				$this->db->delete($table);
			}				
}