<?php
/**
 * @copyright ONE/DEPO Project
 * @license   PHP License 3.01 <http://www.php.net/license/3_01.txt>
 */


/**
 * その他テーブル関連
 *
 * @package     Onedepo.Db.Other
 * @author      netnee S.Hayashi <shigeyuki.hayashi@netnee.jp>
 * @access      public
 */
class Onedepo_Db_Other
{
    /**
     * DBアクセスオブジェクト
     *
     * @var     object
     * @access  private
     */
    var $dbaccess = null;

    /**
     * 全件取得
     * 
     * @param string $table テーブル名
     * @return object 取得レコード
     */
    function selectAll($table="t_genre")
    {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Other#selectAll";
        
        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ORDERED);

        $params = array($table);

        $sql  = "SELECT * ";
        $sql .= "  FROM %s ";
        $sql = sprintf($sql, $table);
        $log->debug($sql, $func_name);

        $data = $db->getAll($sql);
        if (DB::isError($data)) {
            die($data->getMessage());
        }
        $this->dbaccess->doClose($db);

        return $data;
    }
    
    
    /**
     * 全件取得
     * 
     * @param string $table テーブル名
     * @param string $shopdiv 区分
     * @return object 取得レコード
     */
    function selectForShopdiv($table="t_genre", $shopdiv=1)
    {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Other#selectForShopdiv";
        
        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ORDERED);
        
        $params = array();
        
        switch($table) {
            case 'v_genre_export':
                $sql  = "SELECT v.* FROM v_genre_export v";
                
                $log->debug($sql, $func_name);
                $data = $db->getAll($sql,$params);
                break;
            
            case 'v_maker_export':
                $sql  = "SELECT v.* FROM v_maker_export v, t_maker t "
                       ."WHERE v.makercd=t.makercd AND t.shopdiv=?";
                
                $log->debug($sql, $func_name);
                $data = $db->getAll($sql,$params);
                break;
                
            case 'v_label_export':
                $sql  = "SELECT v.* FROM v_label_export v, t_maker t "
                       ."WHERE v.makercd=t.makercd AND t.shopdiv=?";
                
                $log->debug($sql, $func_name);
                $data = $db->getAll($sql,$params);
                break;
                
            case 'v_series_export':
                $sql  = "SELECT v.* FROM v_series_export v, t_maker t "
                       ."WHERE v.makercd=t.makercd AND t.shopdiv=?";
                
                $log->debug($sql, $func_name);
                $data = $db->getAll($sql,$params);
                break;
                
            case 'v_cast_export':
                $sql  = "SELECT v.* FROM v_cast_export v, t_cast t "
                       ."WHERE v.castcd=t.castcd AND t.shopdiv=?";
                
                $log->debug($sql, $func_name);
                $data = $db->getAll($sql,$params);
                break;
                
            case 'v_item_list':
            case 'v_item_import_export':
            case 'v_supplier_export':
                $sql = sprintf("SELECT * FROM %s ", $table);
                $log->debug($sql, $func_name);
                $data = $db->getAll($sql);
                break;
        }
        //$log->debug($sql, $func_name);
        //$data = $db->getAll($sql,$params);
        if (DB::isError($data)) {
            die($data->getMessage());
        }
        $this->dbaccess->doClose($db);

        return $data;
    }
}
?>
