<?php
/** Generated Model Class **/ 

Class Donatur {    
	private static $columns = "nama,jenis,keterangan,aktif";
	private static $errors;
	
	private static function generate_date($field_name,$array) {
		if (isset($array[$field_name.'_date']) && isset($array[$field_name.'_month']) && isset($array[$field_name.'_date']))
		$array[$field_name.''] = mktime(0, 0, 0, $array[$field_name.'_month'], $array[$field_name.'_date'], $array[$field_name.'_year']);
		
		return $array;
	}
	
	public static function create($array) {
		$donatur = R::dispense("donatur");
		
		$donatur->import($array,self::$columns);
		$id = R::store($donatur);
		
		return $id;
	}
	
	public static function update($id,$array) {
		$donatur = R::load("donatur",$id);
		
		$donatur->import($array,self::$columns);		
		
		R::store($donatur);
		return true;
	}
	
	public static function countAll($active = "") {
	
		if ($active == "all") {
			$q = "select count(1) from donatur";
		} else {
			$q = "select count(1) from donatur where aktif = 'y'";
		}
		
		$data = R::getCell($q);
		return $data;
	}
	
	public static function getAll($active = "") {

		if ($active == "all") {
			$q = "select * from donatur";
		} else {
			$q = "select * from donatur where aktif = 'y'";
		}
		
		$data = R::getAll($q);
		return $data;
	}
	
	public static function get($id) {
		$q = "select * from donatur where id = $id";
		$data = R::getRow($q);
		return $data;
	}
	
	public static function getNama($id) {
		$q = "select nama from donatur where id = $id";
		$data = R::getCell($q);
		return $data;
	}
	
	public static function getByName($donatur = "") {
		$q = "select * from donatur where nama like '%".$donatur."%'";
		
		$data = R::getRow($q);
		return $data;
	}
	
	public static function getByJenis($jenis,$active = "") {
		$q = "select * from donatur where jenis = '$jenis'";
		
		$data = R::getAll($q);
		return $data;
	}
	
	public static function getColumns() {
		return explode(",",self::$columns);
	}

	public static function remove($id) {
		$data = R::load("donatur",$id);
		$data["aktif"] = "t";
		R::store($data);
		// R::trash($data);
	}
	
	public static function delete($id) {
		$data = R::load("donatur",$id);
		R::trash($data);
	}
}
?>
