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/pages/admin/products/LC_Page_Admin_Products_Category.php

    r23605 r23650  
    172172        // 親カテゴリIDの保持 
    173173        $this->arrForm['parent_category_id'] = $parent_category_id; 
     174        // カテゴリ一覧を取得 
     175        $this->arrList = $this->findCategoiesByParentCategoryId($parent_category_id); 
    174176        // カテゴリツリーを取得 
    175         $this->arrTree = $objCategory->getTree(true); 
     177        $this->arrTree = $objCategory->getTree(); 
    176178        $this->arrParentID = $objCategory->getTreeTrail($parent_category_id); 
    177         // カテゴリ一覧を取得 
    178         $this->arrList = $objCategory->getTreeBranch($parent_category_id); 
    179179        // ぱんくずの生成 
    180180        $arrBread = $objCategory->getTreeTrail($this->arrForm['parent_category_id'], FALSE); 
     
    249249    public function doEdit(&$objFormParam) 
    250250    { 
     251        $category_id = $objFormParam->getValue('category_id'); 
     252 
     253        // 追加か 
     254        $add = strlen($category_id) === 0; 
     255 
    251256        // エラーチェック 
    252         $this->arrErr = $this->checkError($objFormParam); 
     257        $this->arrErr = $this->checkError($objFormParam, $add); 
    253258 
    254259        // エラーがない場合、追加・更新処理 
    255260        if (empty($this->arrErr)) { 
    256261            $arrCategory = $objFormParam->getDbArray(); 
    257             $objCategory = new SC_Helper_Category_Ex(); 
    258             $objCategory->save($arrCategory); 
     262 
     263            // 追加 
     264            if ($add) { 
     265                $this->registerCategory($arrCategory); 
     266            } 
     267            // 更新 
     268            else { 
     269                unset($arrCategory['category_id']); 
     270                $this->updateCategory($category_id, $arrCategory); 
     271            } 
    259272        // エラーがある場合、入力値の再表示 
    260273        } else { 
     
    267280     * 
    268281     * @param  SC_FormParam $objFormParam 
    269      * @return array 
    270      */ 
    271     public function checkError(&$objFormParam) 
    272     { 
    273         $objCategory = new SC_Helper_Category_Ex(); 
     282     * @param  boolean      $add          追加か 
     283     * @return void 
     284     */ 
     285    public function checkError(&$objFormParam, $add) 
     286    { 
     287        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    274288 
    275289        // 入力項目チェック 
     
    284298 
    285299        // 追加の場合に固有のチェック 
    286         if (!$category_id) { 
     300        if ($add) { 
    287301            // 登録数上限チェック 
    288             $count = count($objCategory->getList()); 
     302            $where = 'del_flg = 0'; 
     303            $count = $objQuery->count('dtb_category', $where); 
    289304            if ($count >= CATEGORY_MAX) { 
    290305                $arrErr['category_name'] = '※ カテゴリの登録最大数を超えました。<br/>'; 
     
    294309 
    295310            // 階層上限チェック 
    296             $arrParent = $objCategory->get($parent_category_id); 
    297             if ($arrParent['level'] >= LEVEL_MAX) { 
     311            if ($this->isOverLevel($parent_category_id)) { 
    298312                $arrErr['category_name'] = '※ ' . LEVEL_MAX . '階層以上の登録はできません。<br/>'; 
    299313 
     
    303317 
    304318        // 重複チェック 
    305         $exists = false; 
    306         $arrBrother = $objCategory->getTreeBranch($parent_category_id); 
    307         foreach ($arrBrother as $brother) { 
    308             if ($brother['category_name'] == $category_name && $brother['category_id'] != $category_id) { 
    309                 $exists = true; 
    310             } 
    311         } 
     319        $arrWhereVal = array(); 
     320        $where = 'del_flg = 0 AND parent_category_id = ? AND category_name = ?'; 
     321        $arrWhereVal[] = $parent_category_id; 
     322        $arrWhereVal[] = $category_name; 
     323        // 更新の場合、抽出対象から自己を除外する 
     324        if (!$add) { 
     325            $where .= ' AND category_id <> ?'; 
     326            $arrWhereVal[] = $category_id; 
     327        } 
     328        $exists = $objQuery->exists('dtb_category', $where, $arrWhereVal); 
    312329        if ($exists) { 
    313330            $arrErr['category_name'] = '※ 既に同じ内容の登録が存在します。<br/>'; 
     
    327344    public function doUp(&$objFormParam) 
    328345    { 
    329         $objCategory = new SC_Helper_Category_Ex(false); 
    330346        $category_id = $objFormParam->getValue('category_id'); 
    331         $objCategory->rankUp($category_id); 
     347 
     348        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     349        $objQuery->begin(); 
     350        $up_id = $this->lfGetUpRankID($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); 
     351        if ($up_id != '') { 
     352            // 上のグループのrankから減算する数 
     353            $my_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); 
     354                // 自分のグループのrankに加算する数 
     355                $up_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $up_id); 
     356                if ($my_count > 0 && $up_count > 0) { 
     357                    // 自分のグループに加算 
     358                    $this->lfUpRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id, $up_count); 
     359                    // 上のグループから減算 
     360                    $this->lfDownRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $up_id, $my_count); 
     361                } 
     362        } 
     363        $objQuery->commit(); 
    332364    } 
    333365 
     
    340372    public function doDown(&$objFormParam) 
    341373    { 
    342         $objCategory = new SC_Helper_Category_Ex(false); 
    343374        $category_id = $objFormParam->getValue('category_id'); 
    344         $objCategory->rankDown($category_id); 
     375 
     376        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     377        $objQuery->begin(); 
     378        $down_id = $this->lfGetDownRankID($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); 
     379        if ($down_id != '') { 
     380            // 下のグループのrankに加算する数 
     381            $my_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); 
     382            // 自分のグループのrankから減算する数 
     383            $down_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $down_id); 
     384            if ($my_count > 0 && $down_count > 0) { 
     385                // 自分のグループから減算 
     386                $this->lfUpRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $down_id, $my_count); 
     387                // 下のグループに加算 
     388                $this->lfDownRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id, $down_count); 
     389            } 
     390        } 
     391        $objQuery->commit(); 
    345392    } 
    346393 
     
    359406 
    360407    /** 
    361      * @param SC_Query $objQuery 
    362      * @param string $table 
    363      * @param string $pid_name 
    364      * @param string $id_name 
    365      */ 
     408     * 親カテゴリIDでカテゴリを検索する. 
     409     * 
     410     * - 表示順の降順でソートする 
     411     * - 有効なカテゴリを返す(del_flag = 0) 
     412     * 
     413     * @param  SC_Query $objQuery 
     414     * @param  int      $parent_category_id 親カテゴリID 
     415     * @return array    カテゴリの配列 
     416     */ 
     417    public function findCategoiesByParentCategoryId($parent_category_id) 
     418    { 
     419        if (!$parent_category_id) { 
     420            $parent_category_id = 0; 
     421        } 
     422        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     423        $col   = 'category_id, category_name, level, rank'; 
     424        $where = 'del_flg = 0 AND parent_category_id = ?'; 
     425        $objQuery->setOption('ORDER BY rank DESC'); 
     426 
     427        return $objQuery->select($col, 'dtb_category', $where, array($parent_category_id)); 
     428    } 
     429 
     430    /** 
     431     * カテゴリを更新する 
     432     * 
     433     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス 
     434     * @return void 
     435     */ 
     436    public function updateCategory($category_id, $arrCategory) 
     437    { 
     438        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     439 
     440        $arrCategory['update_date']   = 'CURRENT_TIMESTAMP'; 
     441 
     442        $objQuery->begin(); 
     443        $where = 'category_id = ?'; 
     444        $objQuery->update('dtb_category', $arrCategory, $where, array($category_id)); 
     445        $objQuery->commit(); 
     446    } 
     447 
     448    /** 
     449     * カテゴリを登録する 
     450     * 
     451     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス 
     452     * @return void 
     453     */ 
     454    public function registerCategory($arrCategory) 
     455    { 
     456        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     457 
     458        $parent_category_id = $arrCategory['parent_category_id']; 
     459 
     460        $objQuery->begin(); 
     461 
     462        $rank = null; 
     463        if ($parent_category_id == 0) { 
     464            // ROOT階層で最大のランクを取得する。 
     465            $where = 'parent_category_id = ?'; 
     466            $rank = $objQuery->max('rank', 'dtb_category', $where, array($parent_category_id)) + 1; 
     467        } else { 
     468            // 親のランクを自分のランクとする。 
     469            $where = 'category_id = ?'; 
     470            $rank = $objQuery->get('rank', 'dtb_category', $where, array($parent_category_id)); 
     471            // 追加レコードのランク以上のレコードを一つあげる。 
     472            $where = 'rank >= ?'; 
     473            $arrRawSql = array( 
     474                'rank' => '(rank + 1)', 
     475            ); 
     476            $objQuery->update('dtb_category', array(), $where, array($rank), $arrRawSql); 
     477        } 
     478 
     479        $where = 'category_id = ?'; 
     480        // 自分のレベルを取得する(親のレベル + 1) 
     481        $level = $objQuery->get('level', 'dtb_category', $where, array($parent_category_id)) + 1; 
     482 
     483        $arrCategory['create_date'] = 'CURRENT_TIMESTAMP'; 
     484        $arrCategory['update_date'] = 'CURRENT_TIMESTAMP'; 
     485        $arrCategory['creator_id']  = $_SESSION['member_id']; 
     486        $arrCategory['rank']        = $rank; 
     487        $arrCategory['level']       = $level; 
     488        $arrCategory['category_id'] = $objQuery->nextVal('dtb_category_category_id'); 
     489 
     490        $objQuery->insert('dtb_category', $arrCategory); 
     491 
     492        $objQuery->commit();    // トランザクションの終了 
     493    } 
     494 
     495    /** 
     496     * カテゴリの階層が上限を超えているかを判定する 
     497     * 
     498     * @param integer 親カテゴリID 
     499     * @param 超えている場合 true 
     500     */ 
     501    public function isOverLevel($parent_category_id) 
     502    { 
     503        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     504        $level = $objQuery->get('level', 'dtb_category', 'category_id = ?', array($parent_category_id)); 
     505 
     506        return $level >= LEVEL_MAX; 
     507    } 
     508 
     509    // 並びが1つ下のIDを取得する。 
     510    public function lfGetDownRankID($objQuery, $table, $pid_name, $id_name, $id) 
     511    { 
     512        // 親IDを取得する。 
     513        $col = "$pid_name"; 
     514        $where = "$id_name = ?"; 
     515        $pid = $objQuery->get($col, $table, $where, $id); 
     516        // 全ての子を取得する。 
     517        $col = "$id_name"; 
     518        $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; 
     519        $arrRet = $objQuery->select($col, $table, $where, array($pid)); 
     520        $max = count($arrRet); 
     521        $down_id = ''; 
     522        for ($cnt = 0; $cnt < $max; $cnt++) { 
     523            if ($arrRet[$cnt][$id_name] == $id) { 
     524                $down_id = $arrRet[($cnt + 1)][$id_name]; 
     525                break; 
     526            } 
     527        } 
     528 
     529        return $down_id; 
     530    } 
     531 
     532    // 並びが1つ上のIDを取得する。 
     533    public function lfGetUpRankID($objQuery, $table, $pid_name, $id_name, $id) 
     534    { 
     535        // 親IDを取得する。 
     536        $col = "$pid_name"; 
     537        $where = "$id_name = ?"; 
     538        $pid = $objQuery->get($col, $table, $where, $id); 
     539        // 全ての子を取得する。 
     540        $col = "$id_name"; 
     541        $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; 
     542        $arrRet = $objQuery->select($col, $table, $where, array($pid)); 
     543        $max = count($arrRet); 
     544        $up_id = ''; 
     545        for ($cnt = 0; $cnt < $max; $cnt++) { 
     546            if ($arrRet[$cnt][$id_name] == $id) { 
     547                $up_id = $arrRet[($cnt - 1)][$id_name]; 
     548                break; 
     549            } 
     550        } 
     551 
     552        return $up_id; 
     553    } 
     554 
    366555    public function lfCountChilds($objQuery, $table, $pid_name, $id_name, $id) 
    367556    { 
Note: See TracChangeset for help on using the changeset viewer.