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


/**
 * メーカーマスタテーブル関連
 *
 * @package     Onedepo.Db.Maker
 * @author      netnee T.Otogawa<tomokazu.otogawa@netnee.jp>
 * @access      public
 */
class Onedepo_Db_Maker
{
    var $dbaccess;


    /**
     * 全件取得
     *
     */
    function selectAll($sort="makernmkana")
    {

        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectAll";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= "  FROM t_maker ";
        $sql .= " WHERE delflg = FALSE ";
        $sql .= " ORDER BY %s";
        $sql = sprintf($sql, $sort);

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

        return $data;
    }
    /**
     * 全件取得
     *
     */
    function selectAllAtDiv($shopdiv=null, $sort="makernmkana")
    {

        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectAll";
        $params = array();

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= "  FROM t_maker ";
        $sql .= " WHERE delflg = FALSE ";
        if (!empty($shopdiv)) {
            $sql .= " AND shopdiv = ? ";
            $params[] = $shopdiv;
        }
        $sql .= " ORDER BY %s";
        $sql = sprintf($sql, $sort);

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            die($data->getMessage());
        }
        $this->dbaccess->doClose($db);

        return $data;
    }

    /**
     * 条件取得
     *
     */
    function selectKey($code)
    {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectKey";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $params = array($code);

        $sql  = "SELECT makercd, makernm, makernmkana, recommenddiv, comment, updcnt ";
        $sql .= "  FROM t_maker ";
        $sql .= " WHERE delflg = FALSE ";
        $sql .= "   AND makercd = ?;";

        $data = $db->getRow($sql, $params);
        if (DB::isError($data)) {
            die($data->userinfo);
        }

        $this->dbaccess->doClose($db);

        return $data;
    }


    /**
     * サーチ検索
     *
     * @param string  $word 検索ワード
     * @param integer $recommenddiv おすすめ区分
     * @param string  $sort ソートキー
     * @return object 取得レコード
     */
    function selectSearch($word, $recommenddiv, $sort="makernmkana")
    {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectSearch";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $params = NULL;

        $sql  = "SELECT makercd, makernm, makernmkana, recommenddiv, comment, updcnt ";
        $sql .= "  FROM t_maker ";
        $sql .= " WHERE delflg = FALSE ";

        if (!empty($word)) {
            $sql .= "   AND (makernm LIKE ? ";
            $sql .= "    OR  makernmkana LIKE ?";
            $sql .= "    OR  comment LIKE ?)";
            $params[] = "%". trim($word) . "%";
            $params[] = "%". trim($word) . "%";
            $params[] = "%". trim($word) . "%";
        }

        if (!empty($recommenddiv)) {
            $sql .= "   AND recommenddiv = ? ";
            $params[] = $recommenddiv;
        }

        $sql .= " ORDER BY %s";
        $sql = sprintf($sql, $sort);

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            die($data->getMessage());
        }

        $this->dbaccess->doClose($db);

        return $data;
    }


    function selectKana($kana, $shopdiv=null, $sort="makernmkana")
    {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectKana";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT makercd, makernm ";
        $sql .= "  FROM t_maker ";
        $sql .= " WHERE delflg = FALSE ";
        $params = array();
        if (!empty($shopdiv)) {
            $sql .=  " AND shopdiv = ?";
            $params[] = $shopdiv;
        }
        

        foreach ($kana as $key => $val) {
            if ($key==0) $sql .= " AND (";
            else         $sql .= " OR ";
            $sql .= " makernmkana LIKE ? ";
            $params[] = "$val%";
        }
        $sql .= " ) ORDER BY %s ";
        $sql = sprintf($sql, $sort);

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            die($data->getMessage());
        }
        $this->dbaccess->doClose($db);

        return $data;
    }
    
    function selectKanaOfItem($kana, $shopdiv=null, $sort="makernmkana")
    {
        $params = array();
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectKanaOfItem";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT makercd, makernm ";
        $sql .= "  FROM t_maker ";
        $sql .= " WHERE delflg = FALSE ";
        if (!empty($shopdiv)) {
            $sql .=  " AND shopdiv = ?";
            $params[] = $shopdiv;
        }
        $sql .= " AND makercd IN (SELECT item.makercd FROM t_item_basic_attr item) ";
        

        foreach ($kana as $key => $val) {
            if ($key==0) $sql .= " AND (";
            else         $sql .= " OR ";
            $sql .= " makernmkana LIKE ? ";
            $params[] = "$val%";
        }
        $sql .= " ) ORDER BY %s ";
        $sql = sprintf($sql, $sort);

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            die($data->getMessage());
        }
        $this->dbaccess->doClose($db);

        return $data;
    }
    
    function selectOfSeries($shopdiv=null, $sort="maker.makernmkana")
    {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectOfSeries";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $params = array();

        $sql  = "SELECT maker.makercd, maker.makernm ";
        $sql .= " FROM t_maker maker ";
        $sql .= " WHERE maker.delflg = FALSE ";
        if (!empty($shopdiv)) {
            $sql .=  " AND maker.shopdiv = ?";
            $params[] = $shopdiv;
        }
        $sql .= " AND   maker.makercd IN (select distinct makercd from t_series series WHERE series.delflg = FALSE ) ";
        $sql .= " ORDER BY %s ";
        $sql = sprintf($sql, $sort);

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            die($data->getMessage());
        }
        $this->dbaccess->doClose($db);

        return $data;
    }

    function selectKeyToKana($key, $initial, $shopdiv=null, $sort="makernmkana")
    {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectKeyToKana";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT makercd, makernm, makernmkana ";
        $sql .= "  FROM t_maker ";
        $sql .= " WHERE delflg = FALSE ";
        $sql .= " AND makercd = ? ";
        $params = array ($key);
        $data = $db->getRow($sql, $params);

        $k = '';
        foreach ($initial as $key => $val) {
            if (in_array(mb_substr($data["makernmkana"],0,1,"UTF-8"), $val)) {
                $k = $key;
                break;
            }
        }

        $sql  = "SELECT makercd, makernm ";
        $sql .= "  FROM t_maker ";
        $sql .= " WHERE delflg = FALSE ";

        $params = array();
        if (!empty($shopdiv)) {
            $sql .=  " AND shopdiv = ?";
            $params[] = $shopdiv;
        }

        foreach ($initial[$k] as $key => $val) {
            if ($key==0) $sql .= " AND ( ";
            else         $sql .= " OR ";
            $sql .= " makernmkana LIKE ? ";
            $params[] = "$val%";
        }
        $sql .= " ) ORDER BY %s ";
        $sql = sprintf($sql, $sort);

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            die($data->getMessage());
        }
        $this->dbaccess->doClose($db);

        return $data;
    }


    /**
     * 追加
     *
     */
    function insert($shopdiv=null, $name, $kana, $comme, $recdiv, $upduser) {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#insert";

        // 更新ユーザ
        $adminauth =& AdminAuthext::getInstance();
        $upduser = $adminauth->getAuthData("membernm");
        $log->debug("membernm", $upduser);
        //--

        $db = $this->dbaccess->doConnect();
        $db->autoCommit();
        $params = array($shopdiv, $name, $kana, $comme, $recdiv, $upduser, $_SERVER['REMOTE_ADDR']);

        $sql  = "select f_maker_update(1, NULL, ?, ?, ?, ?, ?, ?, ?, NULL);";

        $res = $db->getOne($sql, $params);
        if (DB::isError($res) || $res < 0) {
            $log->error("rollback". $res->userinfo, $func_name);
            $db->rollback();
            $this->dbaccess->doClose($db);
            return false;
        }
        $log->debug("commit", $func_name);

        $db->commit();
        $this->dbaccess->doClose($db);
        return true;
    }

    /**
     * 更新取得
     *
     */
    function update($shopdiv=null, $code, $name, $kana, $comme, $recdiv, $updcnt, $upduser) {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Genre#update";

        // 更新ユーザ
        $adminauth =& AdminAuthext::getInstance();
        $upduser = $adminauth->getAuthData("membernm");
        $log->debug("membernm", $upduser);
        //--

        $db = $this->dbaccess->doConnect();
        $db->autoCommit();
        $params = array($code, $shopdiv, $name, $kana, $comme, $recdiv, $upduser, $_SERVER['REMOTE_ADDR'], $updcnt);

        $sql  = "select f_maker_update(2, ?, ?, ?, ?, ?, ?, ?, ?, ?);";

        $res = $db->getOne($sql, $params);
        if (DB::isError($res) || $res < 0) {
            $log->error("rollback". $res->userinfo, $func_name);
            $db->rollback();
            $this->dbaccess->doClose($db);
            return false;
        }
        $log->debug("commit", $func_name);

        $db->commit();
        $this->dbaccess->doClose($db);
        return true;
    }

    /**
     * 削除
     *
     */
    function delete($shopdiv=null, $code, $updcnt, $upduser) {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#delete";

        // 更新ユーザ
        $adminauth =& AdminAuthext::getInstance();
        $upduser = $adminauth->getAuthData("membernm");
        $log->debug("membernm", $upduser);
        //--

        $db = $this->dbaccess->doConnect();
        $db->autoCommit();
        $params = array($code, $shopdiv, $upduser, $_SERVER['REMOTE_ADDR'], $updcnt);

        $sql  = "SELECT f_maker_update(3, ?, ?, NULL, NULL, NULL, NULL, ?, ?, ?);";

        $res = $db->getOne($sql, $params);
        if (DB::isError($res) || $res < 0) {
            $log->debug("rollback". $res->userinfo, $func_name);
            $db->rollback();
            $this->dbaccess->doClose($db);
            return false;
        }
        $log->debug("commit", $func_name);

        $db->commit();
        $this->dbaccess->doClose($db);
        return true;
    }

    /**
    * おすすめでメーカー取得（ビューを参照）
    *   ※商品が１件以上登録されているメーカーを拾います。
    *
    * @param    string  $sort   ソートキー
    */
    function viewSelectAllRecommend($shopdiv=null, $sort="makernmkana"){
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#viewSelectAllRecommend";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "   SELECT makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= "     FROM v_maker_list ";
        $sql .= "    WHERE recommenddiv = 1 ";
        $sql .= "      AND item_count > 0 ";
        $params = array();
        if (!empty($shopdiv)) {
            $sql .=  " AND shopdiv = ?";
            $params[] = $shopdiv;
        }

        $sql .= " ORDER BY %s";
        $sql = sprintf($sql, $sort);

        $res = $db->getAll($sql, $params);
        if (DB::isError($res)) {
            $log->debug($res->userinfo, $func_name);
            $this->dbaccess->doClose($db);
            return false;
        }

        $this->dbaccess->doClose($db);
        return $res;
    }


    /**
    * 未使用？
    * かなにマッチするメーカーを取得（ビューを参照）
    *
    * @param    array   $kana   取得したい「かな」の配列
    * @param    string  $sort   ソートキー
    */
    function viewSelectKana($shopdiv=null, $kana, $sort="makernmkana"){
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#viewSelectKana";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= "  FROM v_maker_list ";

        $params = array();
        foreach ($kana as $key => $val) {
            if ($key==0) $sql .= " WHERE (";
            else         $sql .= " OR";
            $sql .= " makernmkana LIKE ?";
            $params[] = "$val%";
        }
        $sql .= ") ORDER BY %s";
        $sql = sprintf($sql, $sort);

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            $this->dbaccess->doClose($db);
            return false;
        }
        $this->dbaccess->doClose($db);

        return $data;
    }


    /**
    * 未使用？
    * かなにマッチしないメーカーを取得（ビューを参照）
    *   ※ただし「を」と「ん」は拾います！！
    *
    * @param    string  $sort   ソートキー
    */
    function viewSelectNonKana($shopdiv=null, $sort="makernmkana"){
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#viewSelectNonKana";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT  makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= "  FROM v_maker_list ";
        $sql .= " WHERE makernmkana !~* '^[あ-わ]' ";
        $sql .= " ORDER BY %s";
        $sql = sprintf($sql, $sort);


        $data = $db->getAll($sql);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            $this->dbaccess->doClose($db);
            return false;
        }
        $this->dbaccess->doClose($db);

        return $data;
    }


    /**
    * かなにマッチする画像S有りメーカーを取得（ビューを参照）
    *   ※おすすめを拾いません！
    *   ※商品が１件以上登録されているメーカーを拾います。
    *
    * @param    array   $kana   取得したい「かな」の配列
    * @param    string  $sort   ソートキー
    */
    function viewSelectImageByKana($shopdiv=null, $kana, $sort="makernmkana"){
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#viewSelectImageByKana";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT mkr.makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= "  FROM t_maker mkr ";
        $sql .= "    INNER JOIN t_item_basic_attr b ";
        $sql .= "      ON b.makercd = mkr.makercd  AND b.delflg = FALSE";
        $sql .= " WHERE mkr.delflg = FALSE ";
        $sql .= "   AND recommenddiv = 2 ";
        $sql .= "   AND mkr.makercd IN (SELECT generalcd FROM t_image WHERE typediv = 4 AND imgsizecd = 'S' AND delflg = FALSE) ";

        $params = array();
        if (!empty($shopdiv)) {
            $sql .=  " AND mkr.shopdiv = ?";
            $params[] = $shopdiv;
        }


        foreach ($kana as $key => $val) {
            if ($key==0) $sql .= " AND (";
            else         $sql .= " OR";
            $sql .= " makernmkana LIKE ?";
            $params[] = "$val%";
        }

        $sql .= ") ";
        $sql .= " GROUP BY mkr.makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= " ORDER BY %s";
        $sql = sprintf($sql, $sort);


        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            $this->dbaccess->doClose($db);
            return false;
        }
        $this->dbaccess->doClose($db);

        return $data;
    }


    /**
    * かなにマッチする画像S無しメーカーを取得（ビューを参照）
    *   ※おすすめを拾いません！
    *   ※商品が１件以上登録されているメーカーを拾います。
    *
    * @param    array   $kana   取得したい「かな」の配列
    * @param    string  $sort   ソートキー
    */
    function viewSelectNoimageByKana($shopdiv=null, $kana, $sort="makernmkana"){
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#viewSelectNoimageByKana";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT mkr.makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= "  FROM t_maker mkr ";
        $sql .= "    INNER JOIN t_item_basic_attr b ";
        $sql .= "      ON b.makercd = mkr.makercd  AND b.delflg = FALSE";
        $sql .= " WHERE mkr.delflg = FALSE ";
        $sql .= "   AND recommenddiv = 2 ";
        $sql .= "   AND mkr.makercd NOT IN (SELECT generalcd FROM t_image WHERE typediv = 4 AND imgsizecd = 'S' AND delflg = FALSE) ";

        $params = array();
        if (!empty($shopdiv)) {
            $sql .=  " AND mkr.shopdiv = ?";
            $params[] = $shopdiv;
        }

        foreach ($kana as $key => $val) {
            if ($key==0) $sql .= " AND (";
            else         $sql .= " OR";
            $sql .= " makernmkana LIKE ?";
            $params[] = "$val%";
        }

        $sql .= ") ";
        $sql .= " GROUP BY mkr.makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= " ORDER BY %s";
        $sql = sprintf($sql, $sort);


        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            $this->dbaccess->doClose($db);
            return false;
        }
        $this->dbaccess->doClose($db);

        return $data;
    }


    /**
    * かなにマッチしない画像S有りメーカーを取得（ビューを参照）
    *   ※ただし「を」と「ん」は拾います！！
    *   ※おすすめを拾いません！
    *   ※商品が１件以上登録されているメーカーを拾います。
    *
    * @param    string  $sort   ソートキー
    */
    function viewSelectImageByNonKana($shopdiv=null, $sort="makernmkana"){
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#viewSelectImageByNonKana";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT mkr.makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= "  FROM t_maker mkr ";
        $sql .= "    INNER JOIN t_item_basic_attr b ";
        $sql .= "      ON b.makercd = mkr.makercd  AND b.delflg = FALSE";
        $sql .= " WHERE mkr.delflg = FALSE ";
        $sql .= "   AND recommenddiv = 2 ";
        $sql .= "   AND mkr.makercd IN (SELECT generalcd FROM t_image WHERE typediv = 4 AND imgsizecd = 'S' AND delflg = FALSE) ";
        $sql .= "   AND mkr.makernmkana \!~* '^[あ-わ]' ";
        $params = array();
        if (!empty($shopdiv)) {
            $sql .=  " AND mkr.shopdiv = ?";
            $params[] = $shopdiv;
        }

        $sql .= " GROUP BY mkr.makercd, makernm, makernmkana, recommenddiv, comment ";

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            $this->dbaccess->doClose($db);
            return false;
        }
        $this->dbaccess->doClose($db);

        return $data;
    }


    /**
    * かなにマッチしない画像S無しメーカーを取得（ビューを参照）
    *   ※ただし「を」と「ん」は拾います！！
    *   ※おすすめを拾いません！
    *   ※商品が１件以上登録されているメーカーを拾います。
    *
    * @param    string  $sort   ソートキー
    */
    function viewSelectNoimageByNonKana($shopdiv=null, $sort="makernmkana"){
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#viewSelectNoimageByNonKana";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $sql  = "SELECT mkr.makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= "  FROM t_maker mkr ";
        $sql .= "    INNER JOIN t_item_basic_attr b ";
        $sql .= "      ON b.makercd = mkr.makercd  AND b.delflg = FALSE";
        $sql .= " WHERE mkr.delflg = FALSE ";
        $sql .= "   AND recommenddiv = 2 ";
        $sql .= "   AND mkr.makercd NOT IN (SELECT generalcd FROM t_image WHERE typediv = 4 AND imgsizecd = 'S' AND delflg = FALSE) ";
        $sql .= "   AND makernmkana \!~* '^[あ-わ]' ";

        $params = array();
        if (!empty($shopdiv)) {
            $sql .=  " AND mkr.shopdiv = ?";
            $params[] = $shopdiv;
        }

        $sql .= " GROUP BY mkr.makercd, makernm, makernmkana, recommenddiv, comment ";
        $sql .= " ORDER BY %s";
        $sql = sprintf($sql, $sort);


        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            $this->dbaccess->doClose($db);
            return false;
        }
        $this->dbaccess->doClose($db);

        return $data;
    }


    /**
     * 全件取得
     *
     */
    function viewselectAll($shopdiv=null, $sort="makernmkana")
    {

        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectAll";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $params = array();
        $sql  = "SELECT * ";
        $sql .= "  FROM v_maker_list ";
        if (!empty($shopdiv)) {
            $sql .=  " WHERE shopdiv = ?";
            $params[] = $shopdiv;
        }
        $sql .= " ORDER BY %s";
        $sql = sprintf($sql, $sort);

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            die($data->getMessage());
        }
        $this->dbaccess->doClose($db);

        return $data;
    }

    /**
     * 条件取得
     *
     */
    function viewselectKey($shopdiv=null, $code)
    {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectKey";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);


        $sql  = "SELECT * ";
        $sql .= "  FROM v_maker_list ";
        if (!empty($code)) {
            $sql .= "   WHERE makercd = ?";
            $params[] = $code;
        } else {
            $sql .= "   WHERE makercd IS NULL";
        }
        
        if (!empty($shopdiv)) {
            $sql .=  " AND shopdiv = ?";
            $params[] = $shopdiv;
        }

        $data = $db->getRow($sql, $params);
        if (DB::isError($data)) {
            die($data->userinfo);
        }

        $this->dbaccess->doClose($db);

        return $data;
    }


    /**
     * サーチ検索
     *
     * @param string  $word 検索ワード
     * @param integer $recommenddiv おすすめ区分
     * @param string  $sort ソートキー
     * @return object 取得レコード
     */
    function viewselectSearch($shopdiv=null, $word, $recommenddiv, $sort="makernmkana")
    {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Maker#selectSearch";

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $params = NULL;

        $sql  = "SELECT * ";
        $sql .= "  FROM v_maker_list ";
        $sql .= " WHERE ";

        $w = array();
        if (!empty($word)) {
            $w1  = "   (makernm LIKE ? ";
            $w1 .= "    OR  makernmkana LIKE ?";
            $w1 .= "    OR  comment LIKE ?)";
            $params[] = "%". trim($word) . "%";
            $params[] = "%". trim($word) . "%";
            $params[] = "%". trim($word) . "%";
        }
        if (!empty($w1)) $w[] = $w1;

        if (!empty($recommenddiv)) {
            $w[] = "   recommenddiv = ? ";
            $params[] = $recommenddiv;
        }
        if (!empty($shopdiv)) {
            $w[] .=  "  shopdiv = ?";
            $params[] = $shopdiv;
        }
        $sql .= implode(" AND ", $w);

        $sql .= " ORDER BY %s";
        $sql = sprintf($sql, $sort);

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->debug($data->userinfo, $func_name);
            die($data->getMessage());
        }

        $this->dbaccess->doClose($db);

        return $data;
    }


}
?>
