Changeset 20076 for branches/version-2_5-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php
- Timestamp:
- 2011/02/03 18:40:05 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php
r20038 r20076 63 63 */ 64 64 function action() { 65 if(Net_UserAgent_Mobile::isMobile() === true) { 66 $this->lfGetMainCat(true, $this); 65 // モバイル判定 66 if (SC_Display::detectDevice() === true) { 67 // --- モバイルの場合 68 // メインカテゴリーの取得 69 $this->arrCat = $this->lfGetMainCat(true); 67 70 } else { 68 $objDb = new SC_Helper_DB_Ex(); 69 70 // 選択中のカテゴリIDを判定する 71 $arrCategory_id = $objDb->sfGetCategoryId($_GET['product_id'], $_GET['category_id']); 72 71 // --- PCの場合 73 72 // 選択中のカテゴリID 74 $this->tpl_category_id = empty($arrCategory_id) ? array(0) : $arrCategory_id;; 75 $this->lfGetCatTree($this->tpl_category_id, true, $this); 73 $this->tpl_category_id = $this->lfGetSelectedCategoryId(); 74 // カテゴリツリーの取得 75 $this->arrTree = $this->lfGetCatTree($this->tpl_category_id, true); 76 76 } 77 77 } … … 86 86 } 87 87 88 // カテゴリツリーの取得 89 function lfGetCatTree($arrParent_category_id, $count_check = false) { 88 /** 89 * 選択中のカテゴリIDを取得する. 90 * 91 * @return array $arrCategoryId 選択中のカテゴリID 92 */ 93 function lfGetSelectedCategoryId() { 94 // 商品ID取得 95 if ( !isset($_GET['product_id']) || $_GET['product_id'] == '' || !is_numeric($_GET['product_id']) ) { 96 return array(0); 97 } 98 $product_id = $_GET['product_id']; 99 // カテゴリID取得 100 if ( !isset($_GET['category_id']) || $_GET['category_id'] == '' || !is_numeric($_GET['category_id']) ) { 101 return array(0); 102 } 103 $category_id = $_GET['category_id']; 104 // 選択中のカテゴリIDを判定する 105 $objDb = new SC_Helper_DB_Ex(); 106 $arrCategoryId = $objDb->sfGetCategoryId($product_id, $category_id); 107 if (empty($arrCategoryId)) { 108 $arrCategoryId = array(0); 109 } 110 return $arrCategoryId; 111 } 112 113 /** 114 * カテゴリツリーの取得. 115 * 116 * @param array $arrParentCategoryId 親カテゴリの配列 117 * @param boolean $count_check 登録商品数をチェックする場合はtrue 118 * @return array $arrRet カテゴリーツリーの配列を返す 119 */ 120 function lfGetCatTree($arrParentCategoryId, $count_check = false) { 90 121 $objQuery = new SC_Query(); 91 122 $objDb = new SC_Helper_DB_Ex(); 92 $col = "*";93 $from = "dtb_category left join dtb_category_total_count using (category_id)";123 $col = '*'; 124 $from = 'dtb_category left join dtb_category_total_count using (category_id)'; 94 125 // 登録商品数のチェック 95 126 if($count_check) { 96 $where = "del_flg = 0 AND product_count > 0";127 $where = 'del_flg = 0 AND product_count > 0'; 97 128 } else { 98 $where = "del_flg = 0";99 } 100 $objQuery->setOption( "ORDER BY rank DESC");129 $where = 'del_flg = 0'; 130 } 131 $objQuery->setOption('ORDER BY rank DESC'); 101 132 $arrRet = $objQuery->select($col, $from, $where); 102 103 foreach ($arrParent_category_id as $category_id) { 104 $arrParentID = $objDb->sfGetParents('dtb_category', 'parent_category_id', 'category_id', $category_id); 105 $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray($arrRet, 'parent_category_id', 'category_id', $arrParentID); 106 $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $category_id); 107 133 foreach ($arrParentCategoryId as $category_id) { 134 $arrParentID = $objDb->sfGetParents( 135 'dtb_category', 136 'parent_category_id', 137 'category_id', 138 $category_id 139 ); 140 $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray( 141 $arrRet, 142 'parent_category_id', 143 'category_id', 144 $arrParentID 145 ); 146 $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray( 147 $arrRet, 148 'parent_category_id', 149 'category_id', 150 $category_id 151 ); 108 152 $this->root_parent_id[] = $arrParentID[0]; 109 110 153 $arrDispID = array_merge($arrBrothersID, $arrChildrenID); 111 112 154 foreach($arrRet as $key => $array) { 113 155 foreach($arrDispID as $val) { … … 119 161 } 120 162 } 121 122 $this->arrTree = $arrRet; 123 } 124 125 // メインカテゴリーの取得 126 function lfGetMainCat($count_check = false, &$objSubPage) { 163 return $arrRet; 164 } 165 166 /** 167 * メインカテゴリーの取得. 168 * 169 * @param boolean $count_check 登録商品数をチェックする場合はtrue 170 * @return array $arrMainCat メインカテゴリーの配列を返す 171 */ 172 function lfGetMainCat($count_check = false) { 127 173 $objQuery = new SC_Query(); 128 $col = "*";129 $from = "dtb_category left join dtb_category_total_count using (category_id)";174 $col = '*'; 175 $from = 'dtb_category left join dtb_category_total_count using (category_id)'; 130 176 // メインカテゴリーとその直下のカテゴリーを取得する。 131 177 $where = 'level <= 2 AND del_flg = 0'; 132 178 // 登録商品数のチェック 133 179 if($count_check) { 134 $where .= " AND product_count > 0";135 } 136 $objQuery->setOption( "ORDER BY rank DESC");180 $where .= ' AND product_count > 0'; 181 } 182 $objQuery->setOption('ORDER BY rank DESC'); 137 183 $arrRet = $objQuery->select($col, $from, $where); 138 139 184 // メインカテゴリーを抽出する。 140 185 $arrMainCat = array(); … … 143 188 continue; 144 189 } 145 146 190 // 子カテゴリーを持つかどうかを調べる。 147 $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $cat['category_id']); 191 $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray( 192 $arrRet, 193 'parent_category_id', 194 'category_id', 195 $cat['category_id'] 196 ); 148 197 $cat['has_children'] = count($arrChildrenID) > 0; 149 198 $arrMainCat[] = $cat; 150 199 } 151 152 $objSubPage->arrCat = $arrMainCat; 153 return $objSubPage; 200 return $arrMainCat; 154 201 } 155 202 }
Note: See TracChangeset
for help on using the changeset viewer.