Warning: Can't use blame annotator:
svn blame failed on branches/feature-module-update/data/class/helper/SC_Helper_DB.php: バイナリファイル 'file:///home/svn/open/branches/feature-module-update/data/class/helper/SC_Helper_DB.php' に対しては blame で各行の最終変更者を計算できません 195004

source: branches/feature-module-update/data/class/helper/SC_Helper_DB.php @ 15295

Revision 15295, 25.1 KB checked in by nanasess, 17 years ago (diff)

DB 関連の関数を SC_Helper_DB クラスへ移動(r15293)

  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to application/x-httpd-php
RevLine 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8/**
9 * DB関連のヘルパークラス.
10 *
11 * @package Helper
12 * @author LOCKON CO.,LTD.
13 * @version $Id$
14 */
15class SC_Helper_DB {
16
17    // {{{ properties
18
19    /** ルートカテゴリ取得フラグ */
20    var $g_root_on;
21
22    /** ルートカテゴリID */
23    var $g_root_id;
24
25    // }}}
26    // {{{ functions
27
28    /**
29     * データベースのバージョンを所得する.
30     *
31     * @param string $dsn データソース名
32     * @return string データベースのバージョン
33     */
34    function sfGetDBVersion($dsn = "") {
35        $dbFactory = SC_DB_DBFactory::getInstance();
36        return $dbFactory->sfGetDBVersion($dsn);
37    }
38
39    /**
40     * テーブルの存在をチェックする.
41     *
42     * @param string $table_name チェック対象のテーブル名
43     * @param string $dsn データソース名
44     * @return テーブルが存在する場合 true
45     */
46    function sfTabaleExists($table_name, $dsn = "") {
47        $dbFactory = SC_DB_DBFactory::getInstance();
48        $dsn = $dbFactory->getDSN($dsn);
49
50        $objQuery = new SC_Query($dsn, true, true);
51        // 正常に接続されている場合
52        if(!$objQuery->isError()) {
53            list($db_type) = split(":", $dsn);
54            $sql = $dbFactory->getTableExistsSql();
55            $arrRet = $objQuery->getAll($sql, array($table_name));
56            if(count($arrRet) > 0) {
57                return true;
58            }
59        }
60        return false;
61    }
62
63    /**
64     * カラムの存在チェックと作成を行う.
65     *
66     * チェック対象のテーブルに, 該当のカラムが存在するかチェックする.
67     * 引数 $add が true の場合, 該当のカラムが存在しない場合は, カラムの生成を行う.
68     * カラムの生成も行う場合は, $col_type も必須となる.
69     *
70     * @param string $table_name テーブル名
71     * @param string $column_name カラム名
72     * @param string $col_type カラムのデータ型
73     * @param string $dsn データソース名
74     * @param bool $add カラムの作成も行う場合 true
75     * @return bool カラムが存在する場合とカラムの生成に成功した場合 true,
76     *               テーブルが存在しない場合 false,
77     *               引数 $add == false でカラムが存在しない場合 false
78     */
79    function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) {
80        $dbFactory = SC_DB_DBFactory::getInstance();
81        $dsn = $dbFactory->getDSN($dsn);
82
83        // テーブルが無ければエラー
84        if(!$this->sfTabaleExists($table_name, $dsn)) return false;
85
86        $objQuery = new SC_Query($dsn, true, true);
87        // 正常に接続されている場合
88        if(!$objQuery->isError()) {
89            list($db_type) = split(":", $dsn);
90
91            // カラムリストを取得
92            $arrRet = $dbFactory->sfGetColumnList($table_name);
93            if(count($arrRet) > 0) {
94                if(in_array($col_name, $arrRet)){
95                    return true;
96                }
97            }
98        }
99
100        // カラムを追加する
101        if($add){
102            $objQuery->query("ALTER TABLE $table_name ADD $col_name $col_type ");
103            return true;
104        }
105        return false;
106    }
107
108    /**
109     * インデックスの存在チェックと作成を行う.
110     *
111     * チェック対象のテーブルに, 該当のインデックスが存在するかチェックする.
112     * 引数 $add が true の場合, 該当のインデックスが存在しない場合は, インデックスの生成を行う.
113     * インデックスの生成も行う場合で, DB_TYPE が mysql の場合は, $length も必須となる.
114     *
115     * @param string $table_name テーブル名
116     * @param string $column_name カラム名
117     * @param string $index_name インデックス名
118     * @param integer|string $length インデックスを作成するデータ長
119     * @param string $dsn データソース名
120     * @param bool $add インデックスの生成もする場合 true
121     * @return bool インデックスが存在する場合とインデックスの生成に成功した場合 true,
122     *               テーブルが存在しない場合 false,
123     *               引数 $add == false でインデックスが存在しない場合 false
124     */
125    function sfIndexExists($table_name, $col_name, $index_name, $length = "", $dsn = "", $add = false) {
126        $dbFactory = SC_DB_DBFactory::getInstance();
127        $dsn = $dbFactory->getDSN($dsn);
128
129        // テーブルが無ければエラー
130        if (!$this->sfTabaleExists($table_name, $dsn)) return false;
131
132        $objQuery = new SC_Query($dsn, true, true);
133        $arrRet = $dbFactory->getTableIndex($index_name, $table_name);
134
135        // すでにインデックスが存在する場合
136        if(count($arrRet) > 0) {
137            return true;
138        }
139
140        // インデックスを作成する
141        if($add){
142            $dbFactory->createTableIndex($index_name, $table_name, $col_name, $length());
143            return true;
144        }
145        return false;
146    }
147
148    /**
149     * データの存在チェックを行う.
150     *
151     * @param string $table_name テーブル名
152     * @param string $where データを検索する WHERE 句
153     * @param string $dsn データソース名
154     * @param string $sql データの追加を行う場合の SQL文
155     * @param bool $add データの追加も行う場合 true
156     * @return bool データが存在する場合 true, データの追加に成功した場合 true,
157     *               $add == false で, データが存在しない場合 false
158     */
159    function sfDataExists($table_name, $where, $arrval, $dsn = "", $sql = "", $add = false) {
160        $dbFactory = SC_DB_DBFactory::getInstance();
161        $dsn = $dbFactory->getDSN($dsn);
162
163        $objQuery = new SC_Query($dsn, true, true);
164        $count = $objQuery->count($table_name, $where, $arrval);
165
166        if($count > 0) {
167            $ret = true;
168        } else {
169            $ret = false;
170        }
171        // データを追加する
172        if(!$ret && $add) {
173            $objQuery->exec($sql);
174        }
175        return $ret;
176    }
177
178    /**
179     * 店舗基本情報を取得する.
180     *
181     * @return array 店舗基本情報の配列
182     */
183    function sf_getBasisData() {
184        //DBから設定情報を取得
185        $objConn = new SC_DbConn();
186        $result = $objConn->getAll("SELECT * FROM dtb_baseinfo");
187        if(is_array($result[0])) {
188            foreach ( $result[0] as $key=>$value ){
189                $CONF["$key"] = $value;
190            }
191        }
192        return $CONF;
193    }
194
195    /* 選択中のアイテムのルートカテゴリIDを取得する */
196    function sfGetRootId() {
197
198        if(!$this->g_root_on)   {
199            $this->g_root_on = true;
200            $objQuery = new SC_Query();
201
202            if (!isset($_GET['product_id'])) $_GET['product_id'] = "";
203            if (!isset($_GET['category_id'])) $_GET['category_id'] = "";
204
205            if(!empty($_GET['product_id']) || !empty($_GET['category_id'])) {
206                // 選択中のカテゴリIDを判定する
207                $category_id = SC_Utils_Ex::sfGetCategoryId($_GET['product_id'], $_GET['category_id']);
208                // ROOTカテゴリIDの取得
209                $arrRet = SC_Utils_Ex::sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
210                $root_id = $arrRet[0];
211            } else {
212                // ROOTカテゴリIDをなしに設定する
213                $root_id = "";
214            }
215            $this->g_root_id = $root_id;
216        }
217        return $this->g_root_id;
218    }
219
220    /**
221     * 商品規格情報を取得する.
222     *
223     * @param array $arrID 規格ID
224     * @return array 規格情報の配列
225     */
226    function sfGetProductsClass($arrID) {
227        list($product_id, $classcategory_id1, $classcategory_id2) = $arrID;
228
229        if($classcategory_id1 == "") {
230            $classcategory_id1 = '0';
231        }
232        if($classcategory_id2 == "") {
233            $classcategory_id2 = '0';
234        }
235
236        // 商品規格取得
237        $objQuery = new SC_Query();
238        $col = "product_id, deliv_fee, name, product_code, main_list_image, main_image, price01, price02, point_rate, product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited, sale_limit, sale_unlimited";
239        $table = "vw_product_class AS prdcls";
240        $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?";
241        $objQuery->setorder("rank1 DESC, rank2 DESC");
242        $arrRet = $objQuery->select($col, $table, $where, array($product_id, $classcategory_id1, $classcategory_id2));
243        return $arrRet[0];
244    }
245
246    /**
247     * カート内商品の集計処理を行う.
248     *
249     * @param LC_Page $objPage ページクラスのインスタンス
250     * @param SC_CartSession $objCartSess カートセッションのインスタンス
251     * @param array $arrInfo 商品情報の配列
252     * @return LC_Page 集計処理後のページクラスインスタンス
253     */
254    function sfTotalCart($objPage, $objCartSess, $arrInfo) {
255        // 規格名一覧
256        $arrClassName = SC_Utils_Ex::sfGetIDValueList("dtb_class", "class_id", "name");
257        // 規格分類名一覧
258        $arrClassCatName = SC_Utils_Ex::sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
259
260        $objPage->tpl_total_pretax = 0;     // 費用合計(税込み)
261        $objPage->tpl_total_tax = 0;        // 消費税合計
262        $objPage->tpl_total_point = 0;      // ポイント合計
263
264        // カート内情報の取得
265        $arrCart = $objCartSess->getCartList();
266        $max = count($arrCart);
267        $cnt = 0;
268
269        for ($i = 0; $i < $max; $i++) {
270            // 商品規格情報の取得
271            $arrData = $this->sfGetProductsClass($arrCart[$i]['id']);
272            $limit = "";
273            // DBに存在する商品
274            if (count($arrData) > 0) {
275
276                // 購入制限数を求める。
277                if ($arrData['stock_unlimited'] != '1' && $arrData['sale_unlimited'] != '1') {
278                    if($arrData['sale_limit'] < $arrData['stock']) {
279                        $limit = $arrData['sale_limit'];
280                    } else {
281                        $limit = $arrData['stock'];
282                    }
283                } else {
284                    if ($arrData['sale_unlimited'] != '1') {
285                        $limit = $arrData['sale_limit'];
286                    }
287                    if ($arrData['stock_unlimited'] != '1') {
288                        $limit = $arrData['stock'];
289                    }
290                }
291
292                if($limit != "" && $limit < $arrCart[$i]['quantity']) {
293                    // カート内商品数を制限に合わせる
294                    $objCartSess->setProductValue($arrCart[$i]['id'], 'quantity', $limit);
295                    $quantity = $limit;
296                    $objPage->tpl_message = "※「" . $arrData['name'] . "」は販売制限しております、一度にこれ以上の購入はできません。";
297                } else {
298                    $quantity = $arrCart[$i]['quantity'];
299                }
300
301                $objPage->arrProductsClass[$cnt] = $arrData;
302                $objPage->arrProductsClass[$cnt]['quantity'] = $quantity;
303                $objPage->arrProductsClass[$cnt]['cart_no'] = $arrCart[$i]['cart_no'];
304                $objPage->arrProductsClass[$cnt]['class_name1'] = $arrClassName[$arrData['class_id1']];
305                $objPage->arrProductsClass[$cnt]['class_name2'] = $arrClassName[$arrData['class_id2']];
306                $objPage->arrProductsClass[$cnt]['classcategory_name1'] = $arrClassCatName[$arrData['classcategory_id1']];
307                $objPage->arrProductsClass[$cnt]['classcategory_name2'] = $arrClassCatName[$arrData['classcategory_id2']];
308
309                // 画像サイズ
310                list($image_width, $image_height) = getimagesize(IMAGE_SAVE_DIR . basename($objPage->arrProductsClass[$cnt]["main_image"]));
311                $objPage->arrProductsClass[$cnt]["tpl_image_width"] = $image_width + 60;
312                $objPage->arrProductsClass[$cnt]["tpl_image_height"] = $image_height + 80;
313
314                // 価格の登録
315                if ($arrData['price02'] != "") {
316                    $objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price02']);
317                    $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price02'];
318                } else {
319                    $objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price01']);
320                    $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price01'];
321                }
322                // ポイント付与率の登録
323                $objCartSess->setProductValue($arrCart[$i]['id'], 'point_rate', $arrData['point_rate']);
324                // 商品ごとの合計金額
325                $objPage->arrProductsClass[$cnt]['total_pretax'] = $objCartSess->getProductTotal($arrInfo, $arrCart[$i]['id']);
326                // 送料の合計を計算する
327                $objPage->tpl_total_deliv_fee+= ($arrData['deliv_fee'] * $arrCart[$i]['quantity']);
328                $cnt++;
329            } else {
330                // DBに商品が見つからない場合はカート商品の削除
331                $objCartSess->delProductKey('id', $arrCart[$i]['id']);
332            }
333        }
334
335        // 全商品合計金額(税込み)
336        $objPage->tpl_total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
337        // 全商品合計消費税
338        $objPage->tpl_total_tax = $objCartSess->getAllProductsTax($arrInfo);
339        // 全商品合計ポイント
340        $objPage->tpl_total_point = $objCartSess->getAllProductsPoint();
341
342        return $objPage;
343    }
344
345    /**
346     * 受注一時テーブルへの書き込み処理を行う.
347     *
348     * @param string $uniqid ユニークID
349     * @param array $sqlval SQLの値の配列
350     * @return void
351     */
352    function sfRegistTempOrder($uniqid, $sqlval) {
353        if($uniqid != "") {
354            // 既存データのチェック
355            $objQuery = new SC_Query();
356            $where = "order_temp_id = ?";
357            $cnt = $objQuery->count("dtb_order_temp", $where, array($uniqid));
358            // 既存データがない場合
359            if ($cnt == 0) {
360                // 初回書き込み時に会員の登録済み情報を取り込む
361                $sqlval = $this->sfGetCustomerSqlVal($uniqid, $sqlval);
362                $sqlval['create_date'] = "now()";
363                $objQuery->insert("dtb_order_temp", $sqlval);
364            } else {
365                $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid));
366            }
367        }
368    }
369
370    /**
371     * 会員情報から SQL文の値を生成する.
372     *
373     * @param string $uniqid ユニークID
374     * @param array $sqlval SQL の値の配列
375     * @return array 会員情報を含んだ SQL の値の配列
376     */
377    function sfGetCustomerSqlVal($uniqid, $sqlval) {
378        $objCustomer = new SC_Customer();
379        // 会員情報登録処理
380        if ($objCustomer->isLoginSuccess()) {
381            // 登録データの作成
382            $sqlval['order_temp_id'] = $uniqid;
383            $sqlval['update_date'] = 'Now()';
384            $sqlval['customer_id'] = $objCustomer->getValue('customer_id');
385            $sqlval['order_name01'] = $objCustomer->getValue('name01');
386            $sqlval['order_name02'] = $objCustomer->getValue('name02');
387            $sqlval['order_kana01'] = $objCustomer->getValue('kana01');
388            $sqlval['order_kana02'] = $objCustomer->getValue('kana02');
389            $sqlval['order_sex'] = $objCustomer->getValue('sex');
390            $sqlval['order_zip01'] = $objCustomer->getValue('zip01');
391            $sqlval['order_zip02'] = $objCustomer->getValue('zip02');
392            $sqlval['order_pref'] = $objCustomer->getValue('pref');
393            $sqlval['order_addr01'] = $objCustomer->getValue('addr01');
394            $sqlval['order_addr02'] = $objCustomer->getValue('addr02');
395            $sqlval['order_tel01'] = $objCustomer->getValue('tel01');
396            $sqlval['order_tel02'] = $objCustomer->getValue('tel02');
397            $sqlval['order_tel03'] = $objCustomer->getValue('tel03');
398            if (defined('MOBILE_SITE')) {
399                $sqlval['order_email'] = $objCustomer->getValue('email_mobile');
400            } else {
401                $sqlval['order_email'] = $objCustomer->getValue('email');
402            }
403            $sqlval['order_job'] = $objCustomer->getValue('job');
404            $sqlval['order_birth'] = $objCustomer->getValue('birth');
405        }
406        return $sqlval;
407    }
408
409    /**
410     * 受注一時テーブルから情報を取得する.
411     *
412     * @param integer $order_temp_id 受注一時ID
413     * @return array 受注一時情報の配列
414     */
415    function sfGetOrderTemp($order_temp_id) {
416        $objQuery = new SC_Query();
417        $where = "order_temp_id = ?";
418        $arrRet = $objQuery->select("*", "dtb_order_temp", $where, array($order_temp_id));
419        return $arrRet[0];
420    }
421
422    /**
423     * SELECTボックス用リストを作成する.
424     *
425     * @param string $table テーブル名
426     * @param string $keyname プライマリーキーのカラム名
427     * @param string $valname データ内容のカラム名
428     * @return array SELECT ボックス用リストの配列
429     */
430    function sfGetIDValueList($table, $keyname, $valname) {
431        $objQuery = new SC_Query();
432        $col = "$keyname, $valname";
433        $objQuery->setwhere("del_flg = 0");
434        $objQuery->setorder("rank DESC");
435        $arrList = $objQuery->select($col, $table);
436        $count = count($arrList);
437        for($cnt = 0; $cnt < $count; $cnt++) {
438            $key = $arrList[$cnt][$keyname];
439            $val = $arrList[$cnt][$valname];
440            $arrRet[$key] = $val;
441        }
442        return $arrRet;
443    }
444
445    /**
446     * ランキングを上げる.
447     *
448     * @param string $table テーブル名
449     * @param string $colname カラム名
450     * @param string|integer $id テーブルのキー
451     * @param string $andwhere SQL の AND 条件である WHERE 句
452     * @return void
453     */
454    function sfRankUp($table, $colname, $id, $andwhere = "") {
455        $objQuery = new SC_Query();
456        $objQuery->begin();
457        $where = "$colname = ?";
458        if($andwhere != "") {
459            $where.= " AND $andwhere";
460        }
461        // 対象項目のランクを取得
462        $rank = $objQuery->get($table, "rank", $where, array($id));
463        // ランクの最大値を取得
464        $maxrank = $objQuery->max($table, "rank", $andwhere);
465        // ランクが最大値よりも小さい場合に実行する。
466        if($rank < $maxrank) {
467            // ランクが一つ上のIDを取得する。
468            $where = "rank = ?";
469            if($andwhere != "") {
470                $where.= " AND $andwhere";
471            }
472            $uprank = $rank + 1;
473            $up_id = $objQuery->get($table, $colname, $where, array($uprank));
474            // ランク入れ替えの実行
475            $sqlup = "UPDATE $table SET rank = ?, update_date = Now() WHERE $colname = ?";
476            $objQuery->exec($sqlup, array($rank + 1, $id));
477            $objQuery->exec($sqlup, array($rank, $up_id));
478        }
479        $objQuery->commit();
480    }
481
482    /**
483     * ランキングを下げる.
484     *
485     * @param string $table テーブル名
486     * @param string $colname カラム名
487     * @param string|integer $id テーブルのキー
488     * @param string $andwhere SQL の AND 条件である WHERE 句
489     * @return void
490     */
491    function sfRankDown($table, $colname, $id, $andwhere = "") {
492        $objQuery = new SC_Query();
493        $objQuery->begin();
494        $where = "$colname = ?";
495        if($andwhere != "") {
496            $where.= " AND $andwhere";
497        }
498        // 対象項目のランクを取得
499        $rank = $objQuery->get($table, "rank", $where, array($id));
500
501        // ランクが1(最小値)よりも大きい場合に実行する。
502        if($rank > 1) {
503            // ランクが一つ下のIDを取得する。
504            $where = "rank = ?";
505            if($andwhere != "") {
506                $where.= " AND $andwhere";
507            }
508            $downrank = $rank - 1;
509            $down_id = $objQuery->get($table, $colname, $where, array($downrank));
510            // ランク入れ替えの実行
511            $sqlup = "UPDATE $table SET rank = ?, update_date = Now() WHERE $colname = ?";
512            $objQuery->exec($sqlup, array($rank - 1, $id));
513            $objQuery->exec($sqlup, array($rank, $down_id));
514        }
515        $objQuery->commit();
516    }
517
518    /**
519     * 指定順位へ移動する.
520     *
521     * @param string $tableName テーブル名
522     * @param string $keyIdColumn キーを保持するカラム名
523     * @param string|integer $keyId キーの値
524     * @param integer $pos 指定順位
525     * @param string $where SQL の AND 条件である WHERE 句
526     * @return void
527     */
528    function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = "") {
529        $objQuery = new SC_Query();
530        $objQuery->begin();
531
532        // 自身のランクを取得する
533        $rank = $objQuery->get($tableName, "rank", "$keyIdColumn = ?", array($keyId));
534        $max = $objQuery->max($tableName, "rank", $where);
535
536        // 値の調整(逆順)
537        if($pos > $max) {
538            $position = 1;
539        } else if($pos < 1) {
540            $position = $max;
541        } else {
542            $position = $max - $pos + 1;
543        }
544
545        if( $position > $rank ) $term = "rank - 1"; //入れ替え先の順位が入れ換え元の順位より大きい場合
546        if( $position < $rank ) $term = "rank + 1"; //入れ替え先の順位が入れ換え元の順位より小さい場合
547
548        // 指定した順位の商品から移動させる商品までのrankを1つずらす
549        $sql = "UPDATE $tableName SET rank = $term, update_date = NOW() WHERE rank BETWEEN ? AND ? AND del_flg = 0";
550        if($where != "") {
551            $sql.= " AND $where";
552        }
553
554        if( $position > $rank ) $objQuery->exec( $sql, array( $rank + 1, $position ));
555        if( $position < $rank ) $objQuery->exec( $sql, array( $position, $rank - 1 ));
556
557        // 指定した順位へrankを書き換える。
558        $sql  = "UPDATE $tableName SET rank = ?, update_date = NOW() WHERE $keyIdColumn = ? AND del_flg = 0 ";
559        if($where != "") {
560            $sql.= " AND $where";
561        }
562
563        $objQuery->exec( $sql, array( $position, $keyId ) );
564        $objQuery->commit();
565    }
566
567    /**
568     * ランクを含むレコードを削除する.
569     *
570     * レコードごと削除する場合は、$deleteをtrueにする
571     *
572     * @param string $table テーブル名
573     * @param string $colname カラム名
574     * @param string|integer $id テーブルのキー
575     * @param string $andwhere SQL の AND 条件である WHERE 句
576     * @param bool $delete レコードごと削除する場合 true,
577     *                     レコードごと削除しない場合 false
578     * @return void
579     */
580    function sfDeleteRankRecord($table, $colname, $id, $andwhere = "",
581                                $delete = false) {
582        $objQuery = new SC_Query();
583        $objQuery->begin();
584        // 削除レコードのランクを取得する。
585        $where = "$colname = ?";
586        if($andwhere != "") {
587            $where.= " AND $andwhere";
588        }
589        $rank = $objQuery->get($table, "rank", $where, array($id));
590
591        if(!$delete) {
592            // ランクを最下位にする、DELフラグON
593            $sqlup = "UPDATE $table SET rank = 0, del_flg = 1, update_date = Now() ";
594            $sqlup.= "WHERE $colname = ?";
595            // UPDATEの実行
596            $objQuery->exec($sqlup, array($id));
597        } else {
598            $objQuery->delete($table, "$colname = ?", array($id));
599        }
600
601        // 追加レコードのランクより上のレコードを一つずらす。
602        $where = "rank > ?";
603        if($andwhere != "") {
604            $where.= " AND $andwhere";
605        }
606        $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
607        $objQuery->exec($sqlup, array($rank));
608        $objQuery->commit();
609    }
610
611    /**
612     * レコードの存在チェックを行う.
613     *
614     * @param string $table テーブル名
615     * @param string $col カラム名
616     * @param array $arrval 要素の配列
617     * @param array $addwhere SQL の AND 条件である WHERE 句
618     * @return bool レコードが存在する場合 true
619     */
620    function sfIsRecord($table, $col, $arrval, $addwhere = "") {
621        $objQuery = new SC_Query();
622        $arrCol = split("[, ]", $col);
623
624        $where = "del_flg = 0";
625
626        if($addwhere != "") {
627            $where.= " AND $addwhere";
628        }
629
630        foreach($arrCol as $val) {
631            if($val != "") {
632                if($where == "") {
633                    $where = "$val = ?";
634                } else {
635                    $where.= " AND $val = ?";
636                }
637            }
638        }
639        $ret = $objQuery->get($table, $col, $where, $arrval);
640
641        if($ret != "") {
642            return true;
643        }
644        return false;
645    }
646}
647?>
Note: See TracBrowser for help on using the repository browser.