Changeset 23438
- Timestamp:
- 2014/05/21 14:05:46 (10 years ago)
- Location:
- branches/version-2_13-dev/data/class
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/class/helper/SC_Helper_Category.php
r23437 r23438 156 156 $arrTrail = $this->getTreeTrail($category_id, true); 157 157 158 // ルートから指定カテゴリーまでたどる. 159 foreach ($arrTrail as $parent_id) { 160 $nextTree = array(); 161 foreach ($arrTree as $branch) { 162 if ($branch['category_id'] == $parent_id && isset($branch['children'])) { 163 $nextTree = $branch['children']; 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 } 164 169 } 165 } 166 $arrTree = $nextTree; 167 } 168 169 return $arrTree; 170 $arrTree = $nextTree; 171 } 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)); 229 } 230 231 $objQuery->commit(); 170 232 } 171 233 -
branches/version-2_13-dev/data/class/pages/admin/products/LC_Page_Admin_Products_Category.php
r23437 r23438 249 249 public function doEdit(&$objFormParam) 250 250 { 251 $category_id = $objFormParam->getValue('category_id');252 253 // 追加か254 $add = strlen($category_id) === 0;255 256 251 // エラーチェック 257 $this->arrErr = $this->checkError($objFormParam , $add);252 $this->arrErr = $this->checkError($objFormParam); 258 253 259 254 // エラーがない場合、追加・更新処理 260 255 if (empty($this->arrErr)) { 261 256 $arrCategory = $objFormParam->getDbArray(); 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 } 257 $objCategory = new SC_Helper_Category_Ex(); 258 $objCategory->save($arrCategory); 272 259 } 273 260 // エラーがある場合、入力値の再表示 … … 281 268 * 282 269 * @param SC_FormParam $objFormParam 283 * @param boolean $add 追加か 284 * @return void 285 */ 286 public function checkError(&$objFormParam, $add) 287 { 288 $objQuery =& SC_Query_Ex::getSingletonInstance(); 270 * @return array 271 */ 272 public function checkError(&$objFormParam) 273 { 274 $objCategory = new SC_Helper_Category_Ex(); 289 275 290 276 // 入力項目チェック … … 299 285 300 286 // 追加の場合に固有のチェック 301 if ( $add) {287 if (!$category_id) { 302 288 // 登録数上限チェック 303 $where = 'del_flg = 0'; 304 $count = $objQuery->count('dtb_category', $where); 289 $count = count($objCategory->getList()); 305 290 if ($count >= CATEGORY_MAX) { 306 291 $arrErr['category_name'] = '※ カテゴリの登録最大数を超えました。<br/>'; … … 310 295 311 296 // 階層上限チェック 312 if ($this->isOverLevel($parent_category_id)) { 297 $arrParent = $objCategory->get($parent_category_id); 298 if ($arrParent['level'] >= LEVEL_MAX) { 313 299 $arrErr['category_name'] = '※ ' . LEVEL_MAX . '階層以上の登録はできません。<br/>'; 314 300 … … 318 304 319 305 // 重複チェック 320 $arrWhereVal = array(); 321 $where = 'del_flg = 0 AND parent_category_id = ? AND category_name = ?'; 322 $arrWhereVal[] = $parent_category_id; 323 $arrWhereVal[] = $category_name; 324 // 更新の場合、抽出対象から自己を除外する 325 if (!$add) { 326 $where .= ' AND category_id <> ?'; 327 $arrWhereVal[] = $category_id; 328 } 329 $exists = $objQuery->exists('dtb_category', $where, $arrWhereVal); 306 $exists = false; 307 $arrBrother = $objCategory->getTreeBranch($parent_category_id); 308 foreach($arrBrother as $brother) { 309 if ($brother['category_name'] == $category_name && $brother['category_id'] != $category_id) { 310 $exists = true; 311 } 312 } 330 313 if ($exists) { 331 314 $arrErr['category_name'] = '※ 既に同じ内容の登録が存在します。<br/>'; … … 374 357 $objFormParam->addParam('カテゴリID', 'category_id', null, null, array()); 375 358 $objFormParam->addParam('カテゴリ名', 'category_name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK')); 376 }377 378 /**379 * カテゴリを更新する380 *381 * @param SC_FormParam $objFormParam SC_FormParam インスタンス382 * @return void383 */384 public function updateCategory($category_id, $arrCategory)385 {386 $objQuery =& SC_Query_Ex::getSingletonInstance();387 388 $arrCategory['update_date'] = 'CURRENT_TIMESTAMP';389 390 $objQuery->begin();391 $where = 'category_id = ?';392 $objQuery->update('dtb_category', $arrCategory, $where, array($category_id));393 $objQuery->commit();394 }395 396 /**397 * カテゴリを登録する398 *399 * @param SC_FormParam $objFormParam SC_FormParam インスタンス400 * @return void401 */402 public function registerCategory($arrCategory)403 {404 $objQuery =& SC_Query_Ex::getSingletonInstance();405 406 $parent_category_id = $arrCategory['parent_category_id'];407 408 $objQuery->begin();409 410 $rank = null;411 if ($parent_category_id == 0) {412 // ROOT階層で最大のランクを取得する。413 $where = 'parent_category_id = ?';414 $rank = $objQuery->max('rank', 'dtb_category', $where, array($parent_category_id)) + 1;415 } else {416 // 親のランクを自分のランクとする。417 $where = 'category_id = ?';418 $rank = $objQuery->get('rank', 'dtb_category', $where, array($parent_category_id));419 // 追加レコードのランク以上のレコードを一つあげる。420 $where = 'rank >= ?';421 $arrRawSql = array(422 'rank' => '(rank + 1)',423 );424 $objQuery->update('dtb_category', array(), $where, array($rank), $arrRawSql);425 }426 427 $where = 'category_id = ?';428 // 自分のレベルを取得する(親のレベル + 1)429 $level = $objQuery->get('level', 'dtb_category', $where, array($parent_category_id)) + 1;430 431 $arrCategory['create_date'] = 'CURRENT_TIMESTAMP';432 $arrCategory['update_date'] = 'CURRENT_TIMESTAMP';433 $arrCategory['creator_id'] = $_SESSION['member_id'];434 $arrCategory['rank'] = $rank;435 $arrCategory['level'] = $level;436 $arrCategory['category_id'] = $objQuery->nextVal('dtb_category_category_id');437 438 $objQuery->insert('dtb_category', $arrCategory);439 440 $objQuery->commit(); // トランザクションの終了441 }442 443 /**444 * カテゴリの階層が上限を超えているかを判定する445 *446 * @param int $parent_category_id 親カテゴリID447 * @return bool 超えている場合 true448 */449 public function isOverLevel($parent_category_id)450 {451 $objCategory = new SC_Helper_Category_Ex();452 $arrCategory = $objCategory->get($parent_category_id);453 454 return $arrCategory['level'] >= LEVEL_MAX;455 359 } 456 360
Note: See TracChangeset
for help on using the changeset viewer.