Changeset 15548


Ignore:
Timestamp:
2007/09/01 19:22:34 (17 years ago)
Author:
nanasess
Message:

リファクタリング

  • DB 関連の関数を移動
Location:
branches/feature-module-update/data/class
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-module-update/data/class/helper/SC_Helper_DB.php

    r15532 r15548  
    1111 * @package Helper 
    1212 * @author LOCKON CO.,LTD. 
    13  * @version $Id$ 
     13 * @version $Id:SC_Helper_DB.php 15532 2007-08-31 14:39:46Z nanasess $ 
    1414 */ 
    1515class SC_Helper_DB { 
     
    10091009 
    10101010    /** 
     1011     * 親IDの配列を元に特定のカラムを取得する. 
     1012     * 
     1013     * @param SC_Query $objQuery SC_Query インスタンス 
     1014     * @param string $table テーブル名 
     1015     * @param string $id_name ID名 
     1016     * @param string $col_name カラム名 
     1017     * @param array $arrId IDの配列 
     1018     * @return array 特定のカラムの配列 
     1019     */ 
     1020    function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) { 
     1021        $col = $col_name; 
     1022        $len = count($arrId); 
     1023        $where = ""; 
     1024 
     1025        for($cnt = 0; $cnt < $len; $cnt++) { 
     1026            if($where == "") { 
     1027                $where = "$id_name = ?"; 
     1028            } else { 
     1029                $where.= " OR $id_name = ?"; 
     1030            } 
     1031        } 
     1032 
     1033        $objQuery->setorder("level"); 
     1034        $arrRet = $objQuery->select($col, $table, $where, $arrId); 
     1035        return $arrRet; 
     1036    } 
     1037 
     1038    /** 
     1039     * カテゴリ変更時の移動処理を行う. 
     1040     * 
     1041     * @param SC_Query $objQuery SC_Query インスタンス 
     1042     * @param string $table テーブル名 
     1043     * @param string $id_name ID名 
     1044     * @param string $cat_name カテゴリ名 
     1045     * @param integer $old_catid 旧カテゴリID 
     1046     * @param integer $new_catid 新カテゴリID 
     1047     * @param integer $id ID 
     1048     * @return void 
     1049     */ 
     1050    function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) { 
     1051        if ($old_catid == $new_catid) { 
     1052            return; 
     1053        } 
     1054        // 旧カテゴリでのランク削除処理 
     1055        // 移動レコードのランクを取得する。 
     1056        $where = "$id_name = ?"; 
     1057        $rank = $objQuery->get($table, "rank", $where, array($id)); 
     1058        // 削除レコードのランクより上のレコードを一つ下にずらす。 
     1059        $where = "rank > ? AND $cat_name = ?"; 
     1060        $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; 
     1061        $objQuery->exec($sqlup, array($rank, $old_catid)); 
     1062        // 新カテゴリでの登録処理 
     1063        // 新カテゴリの最大ランクを取得する。 
     1064        $max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1; 
     1065        $where = "$id_name = ?"; 
     1066        $sqlup = "UPDATE $table SET rank = ? WHERE $where"; 
     1067        $objQuery->exec($sqlup, array($max_rank, $id)); 
     1068    } 
     1069 
     1070    /** 
    10111071     * レコードの存在チェックを行う. 
    10121072     * 
  • branches/feature-module-update/data/class/util/SC_Utils.php

    r15544 r15548  
    734734        $ret = ereg_replace("[  \n\r]*$", "", $ret); 
    735735        return $ret; 
    736     } 
    737  
    738     /* 親IDの配列を元に特定のカラムを取得する。*/ 
    739     function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) { 
    740         $col = $col_name; 
    741         $len = count($arrId); 
    742         $where = ""; 
    743  
    744         for($cnt = 0; $cnt < $len; $cnt++) { 
    745             if($where == "") { 
    746                 $where = "$id_name = ?"; 
    747             } else { 
    748                 $where.= " OR $id_name = ?"; 
    749             } 
    750         } 
    751  
    752         $objQuery->setorder("level"); 
    753         $arrRet = $objQuery->select($col, $table, $where, $arrId); 
    754         return $arrRet; 
    755     } 
    756  
    757     /* カテゴリ変更時の移動処理 */ 
    758     function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) { 
    759         if ($old_catid == $new_catid) { 
    760             return; 
    761         } 
    762         // 旧カテゴリでのランク削除処理 
    763         // 移動レコードのランクを取得する。 
    764         $where = "$id_name = ?"; 
    765         $rank = $objQuery->get($table, "rank", $where, array($id)); 
    766         // 削除レコードのランクより上のレコードを一つ下にずらす。 
    767         $where = "rank > ? AND $cat_name = ?"; 
    768         $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; 
    769         $objQuery->exec($sqlup, array($rank, $old_catid)); 
    770         // 新カテゴリでの登録処理 
    771         // 新カテゴリの最大ランクを取得する。 
    772         $max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1; 
    773         $where = "$id_name = ?"; 
    774         $sqlup = "UPDATE $table SET rank = ? WHERE $where"; 
    775         $objQuery->exec($sqlup, array($max_rank, $id)); 
    776736    } 
    777737 
Note: See TracChangeset for help on using the changeset viewer.