Ignore:
Timestamp:
2014/10/12 15:17:12 (10 years ago)
Author:
kim
Message:

#2554 r23436 r23437 r23438 をリバート

既存ローカル関数の削除、検証不十分のため。2.13.3では実装を見送りとします。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13_3/data/class/helper/SC_Helper_Category.php

    r23649 r23650  
    6767     * カテゴリー一覧の取得. 
    6868     * 
    69      * @param bool $cid_to_key 配列のキーをカテゴリーIDにする場合はtrue 
    70      * @param bool $reset スタティック変数をリセットする場合はtrue 
     69     * @param  boolean $cid_to_key 配列のキーをカテゴリーIDにする場合はtrue 
    7170     * @return array   カテゴリー一覧の配列 
    7271     */ 
    73     public function getList($cid_to_key = FALSE, $reset = FALSE) 
     72    public function getList($cid_to_key = FALSE) 
    7473    { 
    7574        static $arrCategory = array(), $cidIsKey = array(); 
    76  
    77         if ($reset) { 
    78             $arrCategory = array(); 
    79             $cidIsKey = array(); 
    80         } 
    8175 
    8276        if (!isset($arrCategory[$this->count_check])) { 
     
    111105     * カテゴリーツリーの取得. 
    112106     * 
    113      * @param bool $reset スタティック変数をリセットする場合はtrue 
    114      * @return array 
     107     * @return type 
    115108     */ 
    116     public function getTree($reset = false) 
     109    public function getTree() 
    117110    { 
    118111        static $arrTree = array(); 
    119  
    120         if ($reset) { 
    121             $arrTree = array(); 
    122         } 
    123  
    124112        if (!isset($arrTree[$this->count_check])) { 
    125             $arrList = $this->getList(false, $reset); 
     113            $arrList = $this->getList(); 
    126114            $arrTree[$this->count_check] = SC_Utils_Ex::buildTree('category_id', 'parent_category_id', LEVEL_MAX, $arrList); 
    127115        } 
     
    151139     * @return array 
    152140     */ 
    153     public function getTreeBranch($category_id) 
    154     { 
     141    public function getTreeBranch($category_id) { 
    155142        $arrTree = $this->getTree(); 
    156143        $arrTrail = $this->getTreeTrail($category_id, true); 
    157144 
    158         // 指定カテゴリーがルートの場合は、ツリーをそのまま返す. 
    159         if ($category_id == 0) { 
    160             return $arrTree; 
    161         } else { 
    162             // ルートから指定カテゴリーまでたどる. 
    163             foreach ($arrTrail as $parent_id) { 
    164                 $nextTree = array(); 
    165                 foreach ($arrTree as $branch) { 
    166                     if ($branch['category_id'] == $parent_id && isset($branch['children'])) { 
    167                         $nextTree = $branch['children']; 
    168                     } 
     145        // ルートから指定カテゴリーまでたどる. 
     146        foreach ($arrTrail as $parent_id) { 
     147            $nextTree = array(); 
     148            foreach ($arrTree as $branch) { 
     149                if ($branch['category_id'] == $parent_id && isset($branch['children'])) { 
     150                    $nextTree = $branch['children']; 
    169151                } 
    170                 $arrTree = $nextTree; 
    171152            } 
    172             return $arrTree; 
    173         } 
    174     } 
    175  
    176     /** 
    177      * カテゴリーの登録. 
    178      * 
    179      * @param array $data 
    180      * @return void 
    181      */ 
    182     public function save($data) 
    183     { 
    184         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    185  
    186         $category_id = $data['category_id']; 
    187         $query = array('update_date' => 'CURRENT_TIMESTAMP'); 
    188         $objQuery->begin(); 
    189  
    190         if ($category_id == '') { 
    191             // 新規登録 
    192             $parent_category_id = $data['parent_category_id']; 
    193             $rank = null; 
    194             if ($parent_category_id == 0) { 
    195                 // ROOT階層で最大のランクを取得する。 
    196                 $where = 'parent_category_id = ?'; 
    197                 $rank = $objQuery->max('rank', 'dtb_category', $where, array($parent_category_id)) + 1; 
    198             } else { 
    199                 // 親のランクを自分のランクとする。 
    200                 $where = 'category_id = ?'; 
    201                 $rank = $objQuery->get('rank', 'dtb_category', $where, array($parent_category_id)); 
    202                 // 追加レコードのランク以上のレコードを一つあげる。 
    203                 $where = 'rank >= ?'; 
    204                 $arrRawSql = array( 
    205                     'rank' => '(rank + 1)', 
    206                 ); 
    207                 $objQuery->update('dtb_category', array(), $where, array($rank), $arrRawSql); 
    208             } 
    209  
    210             $where = 'category_id = ?'; 
    211             // 自分のレベルを取得する(親のレベル + 1) 
    212             $level = $objQuery->get('level', 'dtb_category', $where, array($parent_category_id)) + 1; 
    213  
    214             $query['category_id'] = $objQuery->nextVal('dtb_category_category_id'); 
    215             $query['category_name'] = $data['category_name']; 
    216             $query['parent_category_id'] = $data['parent_category_id']; 
    217             $query['create_date'] = 'CURRENT_TIMESTAMP'; 
    218             $query['creator_id']  = $_SESSION['member_id']; 
    219             $query['rank']        = $rank; 
    220             $query['level']       = $level; 
    221  
    222             $objQuery->insert('dtb_category', $query); 
    223         } else { 
    224             // 既存編集 
    225             $query['parent_category_id'] = $data['parent_category_id']; 
    226             $query['category_name'] = $data['category_name']; 
    227             $where = 'category_id = ?'; 
    228             $objQuery->update('dtb_category', $query, $where, array($category_id)); 
     153            $arrTree = $nextTree; 
    229154        } 
    230155 
    231         $objQuery->commit(); 
     156        return $arrTree; 
    232157    } 
    233158 
     
    238163     * @return void 
    239164     */ 
    240     public function delete($category_id) 
    241     { 
     165    public function delete($category_id) { 
    242166        $objDb = new SC_Helper_DB_Ex(); 
    243167        // ランク付きレコードの削除(※処理負荷を考慮してレコードごと削除する。) 
    244168        $objDb->sfDeleteRankRecord('dtb_category', 'category_id', $category_id, '', true); 
    245     } 
    246  
    247     /** 
    248      * カテゴリーの表示順をひとつ上げる. 
    249      * 
    250      * @param int $category_id カテゴリーID 
    251      * @return void 
    252      */ 
    253     public function rankUp($category_id) 
    254     { 
    255         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    256         $objQuery->begin(); 
    257         $up_id = $this->getNeighborRankId('upper', $category_id); 
    258         if ($up_id != '') { 
    259             // 上のグループのrankから減算する数 
    260             $my_count = $this->countAllBranches($category_id); 
    261             // 自分のグループのrankに加算する数 
    262             $up_count = $this->countAllBranches($up_id); 
    263             if ($my_count > 0 && $up_count > 0) { 
    264                 // 自分のグループに加算 
    265                 $this->raiseBranchRank($objQuery, $category_id, $up_count); 
    266                 // 上のグループから減算 
    267                 $this->reduceBranchRank($objQuery, $up_id, $my_count); 
    268             } 
    269         } 
    270         $objQuery->commit(); 
    271     } 
    272  
    273     /** 
    274      * カテゴリーの表示順をひとつ下げる. 
    275      * 
    276      * @param int $category_id カテゴリーID 
    277      * @return void 
    278      */ 
    279     public function rankDown($category_id) 
    280     { 
    281         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    282         $objQuery->begin(); 
    283         $down_id = $this->getNeighborRankId('lower', $category_id); 
    284         if ($down_id != '') { 
    285             // 下のグループのrankに加算する数 
    286             $my_count = $this->countAllBranches($category_id); 
    287             // 自分のグループのrankから減算する数 
    288             $down_count = $this->countAllBranches($down_id); 
    289             if ($my_count > 0 && $down_count > 0) { 
    290                 // 自分のグループから減算 
    291                 $this->raiseBranchRank($objQuery, $down_id, $my_count); 
    292                 // 下のグループに加算 
    293                 $this->reduceBranchRank($objQuery, $category_id, $down_count); 
    294             } 
    295         } 
    296         $objQuery->commit(); 
    297     } 
    298  
    299     /** 
    300      * 並びがとなりのIDを取得する。 
    301      * 
    302      * @param string $side 上 upper か下 down か 
    303      * @param int $category_id カテゴリーID 
    304      * @return int 
    305      */ 
    306     private function getNeighborRankId($side, $category_id) 
    307     { 
    308         $arrCategory = $this->get($category_id); 
    309         $parent_id = $arrCategory['parent_category_id']; 
    310  
    311         if ($parent_id == 0) { 
    312             $arrBrother = $this->getTree(); 
    313         } else { 
    314             $arrBrother = $this->getTreeBranch($parent_id); 
    315         } 
    316  
    317         // 全ての子を取得する。 
    318         $max = count($arrBrother); 
    319         $upper_id = ''; 
    320         for ($cnt = 0; $cnt < $max; $cnt++) { 
    321             if ($arrBrother[$cnt]['category_id'] == $category_id) { 
    322                 if ($side == 'upper') { 
    323                     $index = $cnt - 1; 
    324                 } else { 
    325                     $index = $cnt + 1; 
    326                 } 
    327                 $upper_id = $arrBrother[$index]['category_id']; 
    328                 break; 
    329             } 
    330         } 
    331  
    332         return $upper_id; 
    333     } 
    334  
    335     /** 
    336      * 指定カテゴリーを含めた子孫カテゴリーの数を取得する. 
    337      * 
    338      * @param int $category_id カテゴリーID 
    339      * @return int 
    340      */ 
    341     private function countAllBranches($category_id) 
    342     { 
    343         $objDb = new SC_Helper_DB_Ex(); 
    344         // 子ID一覧を取得 
    345         $arrRet = $objDb->sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $category_id); 
    346  
    347         return count($arrRet); 
    348     } 
    349  
    350     /** 
    351      * 子孫カテゴリーの表示順を一括して上げる. 
    352      * 
    353      * @param SC_Query $objQuery 
    354      * @param int $category_id 
    355      * @param int $count 
    356      * @return array|bool 
    357      */ 
    358     private function raiseBranchRank(SC_Query $objQuery, $category_id, $count) 
    359     { 
    360         $table = 'dtb_category'; 
    361         $objDb = new SC_Helper_DB_Ex(); 
    362         // 子ID一覧を取得 
    363         $arrRet = $objDb->sfGetChildrenArray($table, 'parent_category_id', 'category_id', $category_id); 
    364         $line = SC_Utils_Ex::sfGetCommaList($arrRet); 
    365         $where = "category_id IN ($line) AND del_flg = 0"; 
    366         $arrRawVal = array( 
    367             'rank' => "(rank + $count)", 
    368         ); 
    369  
    370         return $objQuery->update($table, array(), $where, array(), $arrRawVal); 
    371     } 
    372  
    373     /** 
    374      * 子孫カテゴリーの表示順を一括して下げる. 
    375      * 
    376      * @param SC_Query $objQuery 
    377      * @param int $category_id 
    378      * @param int $count 
    379      * @return array|bool 
    380      */ 
    381     private function reduceBranchRank(SC_Query $objQuery, $category_id, $count) 
    382     { 
    383         $table = 'dtb_category'; 
    384         $objDb = new SC_Helper_DB_Ex(); 
    385         // 子ID一覧を取得 
    386         $arrRet = $objDb->sfGetChildrenArray($table, 'parent_category_id', 'category_id', $category_id); 
    387         $line = SC_Utils_Ex::sfGetCommaList($arrRet); 
    388         $where = "category_id IN ($line) AND del_flg = 0"; 
    389         $arrRawVal = array( 
    390             'rank' => "(rank - $count)", 
    391         ); 
    392  
    393         return $objQuery->update($table, array(), $where, array(), $arrRawVal); 
    394169    } 
    395170 
Note: See TracChangeset for help on using the changeset viewer.