Changeset 22590


Ignore:
Timestamp:
2013/03/01 10:40:00 (11 years ago)
Author:
pineray
Message:

#2166 親ID配列取得の効率化

Location:
branches/version-2_12-dev/data/class
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php

    r22581 r22590  
    343343        $arrRet = $objQuery->select($col, $from, $where); 
    344344 
    345         $arrParentID = SC_Helper_DB_Ex::sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id); 
     345        $arrParentID = SC_Utils_Ex::getTreeTrail($parent_category_id, 'category_id', 'parent_category_id', $arrRet); 
    346346 
    347347        foreach ($arrRet as $key => $array) { 
  • branches/version-2_12-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php

    r22589 r22590  
    130130    function lfGetCatTree($arrParentCategoryId, $count_check = false) 
    131131    { 
    132         $objDb = new SC_Helper_DB_Ex(); 
    133132        $objCategory = new SC_Helper_Category_Ex($count_check); 
    134133        $arrTree = $objCategory->getTree(); 
     
    136135        $arrCategory = $objCategory->getList(); 
    137136        foreach ($arrParentCategoryId as $category_id) { 
    138             $arrParentID = $objDb->sfGetParents( 
    139                 'dtb_category', 
    140                 'parent_category_id', 
    141                 'category_id', 
    142                 $category_id 
    143             ); 
     137            $arrParentID = SC_Utils_Ex::getTreeTrail($category_id, 'category_id', 'parent_category_id', $arrCategory); 
    144138            $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray( 
    145139                $arrCategory, 
  • branches/version-2_12-dev/data/class/util/SC_Utils.php

    r22589 r22590  
    19331933     * @return array ツリーの配列 
    19341934     */ 
    1935     public static function buildTree($primary_key, $glue_key, $max_depth, $correction = array(), $base_id = 0) 
     1935    public static function buildTree($primary_key, $glue_key, $max_depth, $correction = array(), $root_id = 0) 
    19361936    { 
    19371937        $children = array(); 
     
    19391939            $children[$child[$glue_key]][] = $child; 
    19401940        } 
    1941         $arrTree = $children[$base_id]; 
     1941        $arrTree = $children[$root_id]; 
    19421942        foreach ($arrTree as &$child) { 
    19431943            SC_Utils_Ex::addChild($child, $primary_key, 1, $max_depth, $children); 
     
    19851985        return $return; 
    19861986    } 
     1987 
     1988    /** 
     1989     * 階層情報が含まれている配列から親ID配列を取得する. 
     1990     *  
     1991     * @param integer $start_id 取得起点 
     1992     * @param string $primary_key 主キー名 
     1993     * @param string $glue_key 親IDキー名 
     1994     * @param array $correction 階層構造が含まれている配列 
     1995     * @param integer $root_id ルートID 
     1996     * @return array 親ID配列 
     1997     */ 
     1998    public static function getTreeTrail($start_id, $primary_key, $glue_key, $correction = array(), $root_id = 0) 
     1999    { 
     2000        $arrIDToKay = SC_Utils_Ex::makeArrayIDToKey($primary_key, $correction); 
     2001        $id = $start_id; 
     2002        $arrTrail = array(); 
     2003        while ($id != $root_id && !SC_Utils_Ex::isBlank($id)) { 
     2004            $arrTrail[] = $id; 
     2005            if (isset($arrIDToKay[$id][$glue_key])) { 
     2006                $id = $arrIDToKay[$id][$glue_key]; 
     2007            } else { 
     2008                $id = $root_id; 
     2009            } 
     2010        } 
     2011        return array_reverse($arrTrail); 
     2012    } 
    19872013} 
Note: See TracChangeset for help on using the changeset viewer.