| Source for file SC_Helper_DB.phpDocumentation is available at SC_Helper_DB.php 
 * This file is part of EC-CUBE * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved. * http://www.lockon.co.jp/ * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * @author LOCKON CO.,LTD. * @version $Id:SC_Helper_DB.php 15532 2007-08-31 14:39:46Z nanasess $     * チェック対象のテーブルに, 該当のカラムが存在するかチェックする.     * 引数 $add が true の場合, 該当のカラムが存在しない場合は, カラムの生成を行う.     * カラムの生成も行う場合は, $col_type も必須となる.     * @param string $table_name テーブル名     * @param string $column_name カラム名     * @param string $col_type カラムのデータ型     * @param string $dsn データソース名     * @param bool $add カラムの作成も行う場合 true     * @return bool カラムが存在する場合とカラムの生成に成功した場合 true,     *                引数 $add == false でカラムが存在しない場合 false    function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) {        $dbFactory = SC_DB_DBFactory_Ex::getInstance();        $dsn = $dbFactory->getDSN($dsn);        $objQuery =& SC_Query_Ex::getSingletonInstance($dsn);        if(!in_array($table_name, $objQuery->listTables())) return false;        if(!$objQuery->isError()) {            list($db_type) = explode(":", $dsn);            $columns = $objQuery->listTableFields($table_name);            $objQuery->query("ALTER TABLE $table_name ADD $col_name $col_type ");     * @param string $table_name テーブル名     * @param string $where データを検索する WHERE 句     * @param string $dsn データソース名     * @param string $sql データの追加を行う場合の SQL文     * @param bool $add データの追加も行う場合 true     * @return bool データが存在する場合 true, データの追加に成功した場合 true,     *                $add == false で, データが存在しない場合 false    function sfDataExists($table_name, $where, $arrval, $dsn = "", $sql = "", $add = false) {        $dbFactory = SC_DB_DBFactory_Ex::getInstance();        $dsn = $dbFactory->getDSN($dsn);        $objQuery =& SC_Query_Ex::getSingletonInstance();        $count = $objQuery->count($table_name, $where, $arrval);     * 引数 $force が false の場合は, 初回のみ DB 接続し,     * @param boolean $force 強制的にDB取得するか     * @param string $col 取得カラムを指定する     * @return array 店舗基本情報の配列        if ($force || ! isset($data)) {            $objQuery =& SC_Query_Ex::getSingletonInstance();                $arrRet = $objQuery->select('*', 'dtb_baseinfo');                $arrRet = $objQuery->select($col, "dtb_baseinfo");        $objQuery =& SC_Query_Ex::getSingletonInstance();        return $objQuery->count("dtb_baseinfo");    /* 選択中のアイテムのルートカテゴリIDを取得する */            $objQuery =& SC_Query_Ex::getSingletonInstance();            if (!isset($_GET['product_id'])) $_GET['product_id'] = "";            if (!isset($_GET['category_id'])) $_GET['category_id'] = "";            if(!empty($_GET['product_id']) || !empty($_GET['category_id'])) {                $category_id = $this->sfGetCategoryId($_GET['product_id'], $_GET['category_id']);                if(count($category_id) > 0) {                    $arrRet = $this->sfGetParents('dtb_category', 'parent_category_id', 'category_id', $category_id);                    $root_id = isset($arrRet[0]) ? $arrRet[0] : "";     * 受注番号、最終ポイント、加算ポイント、利用ポイントから「オーダー前ポイント」を取得する     * @param integer $order_id 受注番号     * @param integer $use_point 利用ポイント     * @param integer $add_point 加算ポイント     * @param integer $order_status 対応状況     * @return array オーダー前ポイントの配列        $objQuery = new SC_Query_Ex();        $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id));        $customer_id = $arrRet[0]['customer_id'];        if($customer_id != "" && $customer_id >= 1) {            $arrRet = $objQuery->select('point', "dtb_customer", "customer_id = ?", array($customer_id));            $point = $arrRet[0]['point'];            $rollback_point = $arrRet[0]['point'];            // 対応状況がポイント利用対象の場合、使用ポイント分を戻す            if (SC_Helper_Purchase_Ex::isUsePoint($order_status)) {                $rollback_point += $use_point;            // 対応状況がポイント加算対象の場合、加算ポイント分を戻す            if (SC_Helper_Purchase_Ex::isAddPoint($order_status)) {                $rollback_point -= $add_point;        return array($point, $rollback_point);     * @param integer $parent_category_id 親カテゴリID     * @param bool $count_check 登録商品数のチェックを行う場合 true     * @return array カテゴリツリーの配列    function sfGetCatTree($parent_category_id, $count_check = false) {        $objQuery =& SC_Query_Ex::getSingletonInstance();        $col .= " cat.category_id,";        $col .= " cat.category_name,";        $col .= " cat.parent_category_id,";        $col .= " cat.creator_id,";        $col .= " cat.create_date,";        $col .= " cat.update_date,";        $col .= " cat.del_flg, ";        $col .= " ttl.product_count";        $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id";            $where = "del_flg = 0 AND product_count > 0";        $objQuery->setOption("ORDER BY rank DESC");        $arrRet = $objQuery->select($col, $from, $where);        $arrParentID = SC_Helper_DB_Ex::sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id);        foreach($arrRet as $key => $array) {            foreach($arrParentID as $val) {                if($array['category_id'] == $val) {                    $arrRet[$key]['display'] = 1;     * カテゴリツリーを走査し, パンくずリスト用の配列を生成する.     * @param integer $parent 上位カテゴリID     * @param array パンくずリスト用の配列    function findTree(&$arrTree, $parent, &$result) {        if ($result[count($result) - 1]['parent_category_id'] === 0) {            foreach ($arrTree as $key => $val) {               if ($val['category_id'] == $parent) {                    $result[] = array('category_id' => $val['category_id'],                                      'parent_category_id' => (int) $val['parent_category_id'],                                      'category_name' => $val['category_name']);                    $this->findTree($arrTree, $val['parent_category_id'], $result);     * @param integer $product_id 商品ID     * @param bool $count_check 登録商品数のチェックを行う場合 true     * @return array カテゴリツリーの配列        $objQuery =& SC_Query_Ex::getSingletonInstance();        $col .= " cat.category_id,";        $col .= " cat.category_name,";        $col .= " cat.parent_category_id,";        $col .= " cat.creator_id,";        $col .= " cat.create_date,";        $col .= " cat.update_date,";        $col .= " cat.del_flg, ";        $col .= " ttl.product_count";        $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id";            $where = "del_flg = 0 AND product_count > 0";        $objQuery->setOption("ORDER BY rank DESC");        $arrRet = $objQuery->select($col, $from, $where);        $arrCategory_id = SC_Helper_DB_Ex::sfGetCategoryId($product_id);        foreach ($arrCategory_id as $pkey => $parent_category_id) {            $arrParentID = SC_Helper_DB_Ex::sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id);            foreach($arrParentID as $pid) {                foreach($arrRet as $key => $array) {                    if($array['category_id'] == $pid) {                        $arrCatTree[$pkey][] = $arrRet[$key];     * @param integer $category_id カテゴリID     * @return string 親カテゴリーを連結した文字列        $objQuery =& SC_Query_Ex::getSingletonInstance();        $arrCatID = $this->sfGetParents("dtb_category", "parent_category_id", "category_id", $category_id);        foreach($arrCatID as $key => $val){            $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";            $CatName = $objQuery->getOne($sql,$arrVal);            $ConbName .= $CatName . ' | ';     * 指定したカテゴリーIDのカテゴリーを取得する.     * @param integer $category_id カテゴリID     * @return array 指定したカテゴリーIDのカテゴリー        $objQuery =& SC_Query_Ex::getSingletonInstance();        $arrVal = array($category_id);        $res = $objQuery->select('category_id AS id, category_name AS name', 'dtb_category', 'category_id = ?', $arrVal);     * 指定したカテゴリーIDの大カテゴリーを取得する.     * @param integer $category_id カテゴリID     * @return array 指定したカテゴリーIDの大カテゴリー        $objQuery =& SC_Query_Ex::getSingletonInstance();        $arrCatID = $this->sfGetParents("dtb_category", "parent_category_id", "category_id", $category_id);        $arrRet['id'] = $arrCatID[0];        $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";        $arrVal = array($arrRet['id']);        $arrRet['name'] = $objQuery->getOne($sql,$arrVal);     * $products_check:true商品登録済みのものだけ取得する     * @param string $addwhere 追加する WHERE 句     * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true     * @param string $head カテゴリ名のプレフィックス文字列     * @return array カテゴリツリーの配列    function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) {        $objQuery =& SC_Query_Ex::getSingletonInstance();            $where.= " AND $addwhere";        $objQuery->setOption("ORDER BY rank DESC");            $col = "T1.category_id, category_name, level";            $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id";            $where .= " AND product_count > 0";            $col = "category_id, category_name, level";        $arrRet = $objQuery->select($col, $from, $where);        for($cnt = 0; $cnt < $max; $cnt ++) {            $id = $arrRet[$cnt]['category_id'];            $name = $arrRet[$cnt]['category_name'];            $arrList[$id] = str_repeat($head, $arrRet[$cnt]['level']) . $name;     * @param bool $parent_zero 親カテゴリの Value=0 の場合 true     * @return array カテゴリツリーの配列        $objQuery =& SC_Query_Ex::getSingletonInstance();        $col = "category_id, parent_category_id, category_name";        $objQuery->setOption("ORDER BY level");        $arrRet = $objQuery->select($col, "dtb_category", $where);        foreach ($arrRet as $arrTmp) {            $arrCatName[$arrTmp['category_id']] =                (($arrTmp['parent_category_id'] > 0) ?                    $arrCatName[$arrTmp['parent_category_id']] : "")                . CATEGORY_HEAD . $arrTmp['category_name'];        $col = "category_id, parent_category_id, category_name, level";        $objQuery->setOption("ORDER BY rank DESC");        $arrRet = $objQuery->select($col, "dtb_category", $where);        for($cnt = 0; $cnt < $max; $cnt ++) {                if($arrRet[$cnt]['level'] == LEVEL_MAX) {                    $arrValue[$cnt] = $arrRet[$cnt]['category_id'];                $arrValue[$cnt] = $arrRet[$cnt]['category_id'];            $arrOutput[$cnt] = $arrCatName[$arrRet[$cnt]['category_id']];        return array($arrValue, $arrOutput);     * @param integer $product_id プロダクトID     * @param integer $category_id カテゴリID     * @return array 選択中の商品のカテゴリIDの配列        $category_id = (int) $category_id;        $product_id = (int) $product_id;        if (SC_Utils_Ex::sfIsInt($category_id) && $category_id != 0 && SC_Helper_DB_Ex::sfIsRecord("dtb_category","category_id", $category_id)) {            $category_id = array($category_id);        } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && SC_Helper_DB_Ex::sfIsRecord("dtb_products","product_id", $product_id, $status)) {            $objQuery =& SC_Query_Ex::getSingletonInstance();            $where = "product_id = ?";            $category_id = $objQuery->getCol("category_id", "dtb_product_categories", "product_id = ?", array($product_id));     * @param integer $category_id カテゴリID     * @param integer $product_id プロダクトID        $sqlval = array("category_id" => $category_id,                        "product_id" => $product_id);        $objQuery =& SC_Query_Ex::getSingletonInstance();        $arrCat = $objQuery->select("product_id, category_id, rank",                                    "dtb_product_categories",        foreach ($arrCat as $val) {            if ($val["product_id"] == $product_id) {            $max = ($max < $val['rank']) ? $val['rank'] : $max;        $sqlval['rank'] = $max + 1;        $objQuery->insert("dtb_product_categories", $sqlval);     * @param integer $category_id カテゴリID     * @param integer $product_id プロダクトID        $sqlval = array("category_id" => $category_id,                        "product_id" => $product_id);        $objQuery =& SC_Query_Ex::getSingletonInstance();        $arrCat = $objQuery->select("product_id, category_id, rank",                                    "dtb_product_categories",        foreach ($arrCat as $val) {            if ($val["product_id"] == $product_id) {            $min = ($min < $val['rank']) ? $val['rank'] : $min;        $objQuery->insert("dtb_product_categories", $sqlval);     * @param integer $category_id カテゴリID     * @param integer $product_id プロダクトID        $objQuery =& SC_Query_Ex::getSingletonInstance();        $objQuery->delete("dtb_product_categories",                          "category_id = ? AND product_id = ?", array($category_id, $product_id));     * @param array $arrCategory_id 登録するカテゴリIDの配列     * @param integer $product_id プロダクトID        $objQuery =& SC_Query_Ex::getSingletonInstance();        $arrCurrentCat = $objQuery->select("product_id, category_id, rank",                                           "dtb_product_categories",        foreach ($arrCurrentCat as $val) {            if (!in_array($val["category_id"], $arrCategory_id)) {        foreach ($arrCategory_id as $category_id) {     * @param SC_Query $objQuery SC_Query インスタンス     * @param boolean $is_force_all_count 全カテゴリの集計を強制する場合 true        $objProduct = new SC_Product_Ex();            $objQuery =& SC_Query_Ex::getSingletonInstance();        if(!$objQuery->inTransaction()){        $sql_where = 'alldtl.del_flg = 0 AND alldtl.status = 1';        if (NOSTOCK_HIDDEN === true) {            $sql_where_dtl = 'stock_max >= 1 OR stock_unlimited_max = 1';            $from = $objProduct->alldtlSQL($sql_where_dtl);            $from = " dtb_products as alldtl ";        // 各カテゴリに所属する商品の数を集計。集計対象には子カテゴリを含まない。        if(!$is_force_all_count) {            $arrCategoryCountOld = $objQuery->select('category_id,product_count','dtb_category_count');            $arrCategoryCountOld = array();            SELECT T1.category_id, count(T2.category_id) as product_count                LEFT JOIN dtb_product_categories AS T2                    ON T1.category_id = T2.category_id                    ON T2.product_id = alldtl.product_id            GROUP BY T1.category_id, T2.category_id        $arrCategoryCountNew = $objQuery->getAll($sql);        // 各カテゴリに所属する商品の数を集計。集計対象には子カテゴリを「含む」。        //差分を取得して、更新対象カテゴリだけを確認する。        //各カテゴリ毎のデータ値において以前との差を見る        foreach($arrCategoryCountOld as $item){            $arrOld[$item['category_id']] = $item['product_count'];        foreach($arrCategoryCountNew as $item){            $arrNew[$item['category_id']] = $item['product_count'];        $arrDiffCategory_id = array();        //新しいカテゴリ一覧から見て商品数が異なるデータが無いか確認        foreach($arrNew as $cid => $count){            if($arrOld[$cid] != $count){                $arrDiffCategory_id[] = $cid;        //削除カテゴリを想定して、古いカテゴリ一覧から見て商品数が異なるデータが無いか確認。        foreach($arrOld as $cid => $count){            if($arrNew[$cid] != $count && $count > 0){                $arrDiffCategory_id[] = $cid;        if(count($arrDiffCategory_id) == 0){        //dtb_category_countの更新 差分のあったカテゴリだけ更新する。        foreach($arrDiffCategory_id as $cid) {            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';            $sqlval['product_count'] = (string)$arrNew[$cid];            if($sqlval['product_count'] =="") {                $sqlval['product_count'] = (string)'0';            if(isset($arrOld[$cid])) {                $objQuery->update('dtb_category_count', $sqlval, 'category_id = ?', array($cid));                if ($is_force_all_count) {                    $ret = $objQuery->update('dtb_category_count', $sqlval, 'category_id = ?', array($cid));                $sqlval['category_id'] = $cid;                $objQuery->insert('dtb_category_count', $sqlval);        //差分があったIDとその親カテゴリIDのリストを取得する        $arrTgtCategory_id = array();        foreach ($arrDiffCategory_id as $parent_category_id) {            $arrTgtCategory_id[] = $parent_category_id;            $arrParentID = $this->sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id);            $arrTgtCategory_id = array_merge($arrTgtCategory_id, $arrParentID);        //dtb_category_total_count 集計処理開始        $arrUpdateData = array();        foreach ($arrTgtCategory_id as $category_id) {            list($tmp_where, $tmp_arrval) = $this->sfGetCatWhere($category_id);                $sql_where_product_ids = "product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")";                $arrval = array_merge( (array)$tmp_arrval, (array)$tmp_arrval);                $sql_where_product_ids = '0<>0'; // 一致させない            $where = "($sql_where) AND ($sql_where_product_ids)";            $from = $objProduct->alldtlSQL($sql_where_product_ids);            $sql = "SELECT count(*) FROM $from WHERE $where ";            $arrUpdateData[ $category_id ] = $objQuery->getOne($sql, $arrval);        foreach($arrUpdateData as $cid => $count) {            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';            $sqlval['product_count'] = $count;            if($sqlval['product_count'] =="") {                $sqlval['product_count'] = (string)'0';            $ret = $objQuery->update('dtb_category_total_count', $sqlval, 'category_id = ?', array($cid));                $sqlval['category_id'] = $cid;                $ret = $objQuery->insert('dtb_category_total_count', $sqlval);     * @param string $table テーブル名     * @param string $pid_name 親ID名     * @param string $id_name ID名     * @param string $table テーブル名     * @param string $pid_name 親ID名     * @param string $id_name ID名     * @param integer $id ID番号        while(count($arrRet) > 0) {            $arrRet = SC_Helper_DB_Ex::sfGetChildrenArraySub($table, $pid_name, $id_name, $arrRet);     * @param array $arrData 親カテゴリの配列     * @param string $pid_name 親ID名     * @param string $id_name ID名     * @param array $arrPID 親IDの配列        $objQuery =& SC_Query_Ex::getSingletonInstance();        $ret = $objQuery->select($id_name, $table, $where, $arrPID);            $arrChildren[] = $val[$id_name];     * @param SC_Query $objQuery SC_Query インスタンス     * @param string $table テーブル名     * @param string $pid_name 親ID名     * @param string $id_name ID名        $arrRet = SC_Helper_DB_Ex::sfGetParentsArray($table, $pid_name, $id_name, $id);     * @param string $table テーブル名     * @param string $pid_name 親ID名     * @param string $id_name ID名        while($ret != "0" && !SC_Utils_Ex::isBlank($ret)) {            $ret = SC_Helper_DB_Ex::sfGetParentsArraySub($table, $pid_name, $id_name, $ret);        if(SC_Utils_Ex::isBlank($child)) {        $objQuery =& SC_Query_Ex::getSingletonInstance();        $parent = $objQuery->get($pid_name, $table, "$id_name = ?", $child);     * カテゴリから商品を検索する場合のWHERE文と値を返す.     * @param integer $category_id カテゴリID     * @return array 商品を検索する場合の配列        $arrRet = SC_Helper_DB_Ex::sfGetChildrenArray("dtb_category", "parent_category_id", "category_id", $category_id);        return array($where, $arrRet);     * @param string $table テーブル名     * @param string $keyname プライマリーキーのカラム名     * @param string $valname データ内容のカラム名     * @param string $where WHERE句     * @param array $arrval プレースホルダ     * @return array SELECT ボックス用リストの配列    function sfGetIDValueList($table, $keyname, $valname, $where = '', $arrVal = array()) {        $objQuery =& SC_Query_Ex::getSingletonInstance();        $col = "$keyname, $valname";        $objQuery->setWhere("del_flg = 0");        $objQuery->setOrder("rank DESC");        $arrList = $objQuery->select($col, $table, $where, $arrVal);        $count = count($arrList);        for($cnt = 0; $cnt < $count; $cnt ++) {            $key = $arrList[$cnt][$keyname];            $val = $arrList[$cnt][$valname];     * @param string $table テーブル名     * @param string $colname カラム名     * @param string|integer$id テーブルのキー     * @param string $andwhere SQL の AND 条件である WHERE 句    function sfRankUp($table, $colname, $id, $andwhere = "") {        $objQuery =& SC_Query_Ex::getSingletonInstance();            $where.= " AND $andwhere";        $rank = $objQuery->get('rank', $table, $where, array($id));        $maxrank = $objQuery->max('rank', $table, $andwhere);                $where.= " AND $andwhere";            $up_id = $objQuery->get($colname, $table, $where, array($uprank));            $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?";                $sqlup.= " AND $andwhere";            $objQuery->exec($sqlup, array($rank + 1, $id));            $objQuery->exec($sqlup, array($rank, $up_id));     * @param string $table テーブル名     * @param string $colname カラム名     * @param string|integer$id テーブルのキー     * @param string $andwhere SQL の AND 条件である WHERE 句    function sfRankDown($table, $colname, $id, $andwhere = "") {        $objQuery =& SC_Query_Ex::getSingletonInstance();            $where.= " AND $andwhere";        $rank = $objQuery->get('rank', $table, $where, array($id));        // ランクが1(最小値)よりも大きい場合に実行する。                $where.= " AND $andwhere";            $down_id = $objQuery->get($colname, $table, $where, array($downrank));            $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?";                $sqlup.= " AND $andwhere";            $objQuery->exec($sqlup, array($rank - 1, $id));            $objQuery->exec($sqlup, array($rank, $down_id));     * @param string $tableName テーブル名     * @param string $keyIdColumn キーを保持するカラム名     * @param string|integer$keyId キーの値     * @param integer $pos 指定順位     * @param string $where SQL の AND 条件である WHERE 句    function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = "") {        $objQuery =& SC_Query_Ex::getSingletonInstance();            $getWhere = "$keyIdColumn = ? AND " . $where;            $getWhere = "$keyIdColumn = ?";        $rank = $objQuery->get('rank', $tableName, $getWhere, array($keyId));        $max = $objQuery->max('rank', $tableName, $where);            $position = $max - $pos + 1;        //入れ替え先の順位が入れ換え元の順位より大きい場合        if( $position > $rank ) $term = "rank - 1";        //入れ替え先の順位が入れ換え元の順位より小さい場合        if( $position < $rank ) $term = "rank + 1";        // XXX 入れ替え先の順位が入れ替え元の順位と同じ場合        if (!isset($term)) $term = 'rank';        // 指定した順位の商品から移動させる商品までのrankを1つずらす        $sql = "UPDATE $tableName SET rank = $term WHERE rank BETWEEN ? AND ?";        if( $position > $rank ) $objQuery->exec( $sql, array( $rank + 1, $position ));        if( $position < $rank ) $objQuery->exec( $sql, array( $position, $rank - 1 ));        $sql  = "UPDATE $tableName SET rank = ? WHERE $keyIdColumn = ? ";        $objQuery->exec( $sql, array( $position, $keyId ) );     * レコードごと削除する場合は、$deleteをtrueにする     * @param string $table テーブル名     * @param string $colname カラム名     * @param string|integer$id テーブルのキー     * @param string $andwhere SQL の AND 条件である WHERE 句     * @param bool $delete レコードごと削除する場合 true,        $objQuery =& SC_Query_Ex::getSingletonInstance();            $where.= " AND $andwhere";        $rank = $objQuery->get('rank', $table, $where, array($id));            $sqlup = "UPDATE $table SET rank = 0, del_flg = 1 ";            $sqlup.= "WHERE $colname = ?";            $objQuery->exec($sqlup, array($id));            $objQuery->delete($table, "$colname = ?", array($id));        // 追加レコードのランクより上のレコードを一つずらす。            $where.= " AND $andwhere";        $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";        $objQuery->exec($sqlup, array($rank));     * @param SC_Query $objQuery SC_Query インスタンス     * @param string $table テーブル名     * @param string $id_name ID名     * @param string $col_name カラム名     * @param array $arrId IDの配列     * @return array 特定のカラムの配列    function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) {        for($cnt = 0; $cnt < $len; $cnt ++) {                $where.= " OR $id_name = ?";        $objQuery->setOrder('level');        $arrRet = $objQuery->select($col, $table, $where, $arrId);     * @param SC_Query $objQuery SC_Query インスタンス     * @param string $table テーブル名     * @param string $id_name ID名     * @param string $cat_name カテゴリ名     * @param integer $old_catid 旧カテゴリID     * @param integer $new_catid 新カテゴリID    function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) {        if ($old_catid == $new_catid) {        $rank = $objQuery->get('rank', $table, $where, array($id));        // 削除レコードのランクより上のレコードを一つ下にずらす。        $where = "rank > ? AND $cat_name = ?";        $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";        $objQuery->exec($sqlup, array($rank, $old_catid));        $max_rank = $objQuery->max('rank', $table, "$cat_name = ?", array($new_catid)) + 1;        $sqlup = "UPDATE $table SET rank = ? WHERE $where";        $objQuery->exec($sqlup, array($max_rank, $id));     * @param integer|array$pref_id 都道府県ID 又は都道府県IDの配列     * @param integer $deliv_id 配送業者ID     * @return string 指定の都道府県, 配送業者の配送料金        $objQuery =& SC_Query_Ex::getSingletonInstance();            $pref_id = array($pref_id);                ON T1.deliv_id = T2.deliv_id        foreach ($pref_id as $pref) {            $result += $objQuery->getOne($sql, array($pref, $deliv_id));     * TODO SC_Query に移行するべきか?     * @param string $table テーブル名     * @param string $col カラム名     * @param array $arrval 要素の配列     * @param array $addwhere SQL の AND 条件である WHERE 句     * @return bool レコードが存在する場合 true    function sfIsRecord($table, $col, $arrval, $addwhere = "") {        $objQuery =& SC_Query_Ex::getSingletonInstance();            $where.= " AND $addwhere";        foreach($arrCol as $val) {                    $where.= " AND $val = ?";        $ret = $objQuery->get($col, $table, $where, $arrval);     * @param SC_Query $objQuery SC_Query インスタンス        $objQuery->query("DELETE FROM dtb_maker_count");        $sql = " INSERT INTO dtb_maker_count(maker_id, product_count, create_date) ";        $sql .= " SELECT T1.maker_id, count(T2.maker_id), CURRENT_TIMESTAMP ";        $sql .= " FROM dtb_maker AS T1 LEFT JOIN dtb_products AS T2";        $sql .= " ON T1.maker_id = T2.maker_id ";        $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 ";        $sql .= " GROUP BY T1.maker_id, T2.maker_id ";     * @param integer $product_id プロダクトID     * @param integer $maker_id メーカーID     * @return array 選択中の商品のメーカーIDの配列    function sfGetMakerId($product_id, $maker_id = 0, $closed = false) {        if (!$this->g_maker_on) {            $this->g_maker_on = true;            $maker_id = (int) $maker_id;            $product_id = (int) $product_id;            if (SC_Utils_Ex::sfIsInt($maker_id) && $maker_id != 0 && $this->sfIsRecord("dtb_maker","maker_id", $maker_id)) {                $this->g_maker_id = array($maker_id);            } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) {                $objQuery =& SC_Query_Ex::getSingletonInstance();                $where = "product_id = ?";                $maker_id = $objQuery->getCol("maker_id", "dtb_products", "product_id = ?", array($product_id));                $this->g_maker_id = $maker_id;                $this->g_maker_id = array();        return $this->g_maker_id;     * $products_check:true商品登録済みのものだけ取得する     * @param string $addwhere 追加する WHERE 句     * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true     * @return array カテゴリツリーの配列        $objQuery =& SC_Query_Ex::getSingletonInstance();            $where.= " AND $addwhere";        $objQuery->setOption("ORDER BY rank DESC");            $col = "T1.maker_id, name";            $from = "dtb_maker AS T1 LEFT JOIN dtb_maker_count AS T2 ON T1.maker_id = T2.maker_id";            $where .= " AND product_count > 0";        $arrRet = $objQuery->select($col, $from, $where);        for($cnt = 0; $cnt < $max; $cnt ++) {            $id = $arrRet[$cnt]['maker_id'];            $name = $arrRet[$cnt]['name'];     * @param integer $price 計算対象の金額        $CONF = SC_Helper_DB_Ex::sfGetBasisData();        return SC_Utils_Ex::sfTax($price, $CONF['tax'], $CONF['tax_rule']);     * @param integer $price 計算対象の金額     * @return integer 税金付与した金額    function sfCalcIncTax($price, $tax = null, $tax_rule = null) {        $CONF = SC_Helper_DB_Ex::sfGetBasisData();        return SC_Utils_Ex::sfCalcIncTax($price, $CONF['tax'], $CONF['tax_rule']);     * @param integer $totalpoint      * @param integer $use_point         $CONF = SC_Helper_DB_Ex::sfGetBasisData();        return SC_Utils_Ex::sfGetAddPoint($totalpoint, $use_point, $CONF['point_rate']);     * 指定ファイルが存在する場合 SQL として実行     * @param string $sqlFilePath SQL ファイルのパス            $objQuery =& SC_Query_Ex::getSingletonInstance();            if ($sqls === false) SC_Utils_Ex::sfDispException('ファイルは存在するが読み込めない');            foreach (explode(';', $sqls) as $sql) {                if (strlen($sql) == 0) continue;     * @param integer $product_id 商品ID     * @return bool 商品規格が存在する場合:true, それ以外:false        if (!SC_Utils_Ex::sfIsInt($product_id)) return false;        $objQuery =& SC_Query_Ex::getSingletonInstance();        $where = 'product_id = ? AND del_flg = 0 AND class_combination_id IS NOT NULL';        $count = $objQuery->count('dtb_products_class', $where, array($product_id)); 
		     Documentation generated on Fri, 24 Feb 2012 14:02:42 +0900 by Seasoft
 |