<?php
/**
 * CompassDBHandler
 * $Id: CompassDBHandler.inc
 * @author wanggb
 * @access public
 * @package jp.fishow.handler
 */

class CompassDBHandler {

	/**
	 * 一覧を返す。
	 */
	public static function getList($class_name, $table_name, $w_param, $orderkey = null, $direction = "ASC", $offset = null, $limit = null) {
		$db = CompassDBManager::getInstance();

		$result = $db->doSelect($table_name, $w_param, $orderkey, $direction, $offset, $limit);
		
		$objs = array();
		if (count($result) > 0) {
			ErrorLogger::doOutput($result, 0,"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXresult");
			foreach ($result as $row) {
				$tmp = new $class_name($row);
				array_push($objs, $tmp);
				unset($tmp);
			}
		}
		return $objs;
	}


	/**
	 * IDを指定して特定クラスを取得します。
	 */
	public static function getById($class_name, $table_name, $id, $option_param = null) {
		$db = CompassDBManager::getInstance();

		if (is_array($option_param)) {
			$w_param = $option_param;
		} else {
			$w_param = array();
		}
		$w_param["id"] = $id;



		$result = $db->doSelect($table_name, $w_param);

		if (count($result) > 0) {
			return new $class_name($result[0]);
		}

		return null;
	}

	/**
	 * OrderNoを指定して特定クラスを取得します。
	 */
	public static function getByOrder($class_name, $table_name, $order_no, $option_param = null) {
		$db = CompassDBManager::getInstance();

		if (is_array($option_param)) {
			$w_param = $option_param;
		} else {
			$w_param = array();
		}
		$w_param["order_no"] = $order_no;



		$result = $db->doSelect($table_name, $w_param);

		if (count($result) > 0) {
			return new $class_name($result[0]);
		}

		return null;
	}
        
        /**
	 * extract_codeを指定して特定クラスを取得します。
	 */
	public static function getByExtcode($class_name, $table_name, $extract_code, $schedule_id,$option_param = null) {
		$db = CompassDBManager::getInstance();

		if (is_array($option_param)) {
			$w_param = $option_param;
		} else {
			$w_param = array();
		}
		$w_param["extract_code"] = $extract_code;
                $w_param["schedule_id"] = $schedule_id;


                ErrorLogger::doOutput($w_param, 0,"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXw_param");
		$result = $db->doSelect($table_name, $w_param);

		if (count($result) > 0) {
			return new $class_name($result[0]);
		}

		return null;
	}
}

?>