[15518] | 1 | <?php |
---|
[16582] | 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[22206] | 5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
[16582] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
| 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 22 | */ |
---|
[15518] | 23 | |
---|
[20534] | 24 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
[15518] | 25 | |
---|
| 26 | /** |
---|
| 27 | * カテゴリ管理 のページクラス. |
---|
| 28 | * |
---|
| 29 | * @package Page |
---|
| 30 | * @author LOCKON CO.,LTD. |
---|
| 31 | * @version $Id$ |
---|
| 32 | */ |
---|
[22856] | 33 | class LC_Page_Admin_Products_Category extends LC_Page_Admin_Ex |
---|
[22567] | 34 | { |
---|
[15518] | 35 | /** |
---|
| 36 | * Page を初期化する. |
---|
| 37 | * |
---|
| 38 | * @return void |
---|
| 39 | */ |
---|
[23124] | 40 | public function init() |
---|
[22567] | 41 | { |
---|
[15518] | 42 | parent::init(); |
---|
[20911] | 43 | $this->tpl_maintitle = '商品管理'; |
---|
[21317] | 44 | $this->tpl_subtitle = 'カテゴリ登録'; |
---|
[15518] | 45 | $this->tpl_mainpage = 'products/category.tpl'; |
---|
| 46 | $this->tpl_mainno = 'products'; |
---|
[20210] | 47 | $this->tpl_subno = 'category'; |
---|
[23066] | 48 | $this->tpl_onload = " eccube.setFocus('category_name'); "; |
---|
[15518] | 49 | } |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * Page のプロセス. |
---|
| 53 | * |
---|
| 54 | * @return void |
---|
| 55 | */ |
---|
[23124] | 56 | public function process() |
---|
[22567] | 57 | { |
---|
[19661] | 58 | $this->action(); |
---|
| 59 | $this->sendResponse(); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * Page のアクション. |
---|
| 64 | * |
---|
| 65 | * @return void |
---|
| 66 | */ |
---|
[23124] | 67 | public function action() |
---|
[22567] | 68 | { |
---|
[20501] | 69 | $objFormParam = new SC_FormParam_Ex(); |
---|
[22596] | 70 | $objCategory = new SC_Helper_Category_Ex(); |
---|
[15518] | 71 | |
---|
[20970] | 72 | // 入力パラメーター初期化 |
---|
[20210] | 73 | $this->initParam($objFormParam); |
---|
| 74 | $objFormParam->setParam($_POST); |
---|
| 75 | $objFormParam->convParam(); |
---|
[21478] | 76 | |
---|
[21441] | 77 | switch ($this->getMode()) { |
---|
[21526] | 78 | // カテゴリ登録/編集実行 |
---|
| 79 | case 'edit': |
---|
| 80 | $this->doEdit($objFormParam); |
---|
| 81 | break; |
---|
| 82 | // 入力ボックスへ編集対象のカテゴリ名をセット |
---|
| 83 | case 'pre_edit': |
---|
| 84 | $this->doPreEdit($objFormParam); |
---|
| 85 | break; |
---|
| 86 | // カテゴリ削除 |
---|
| 87 | case 'delete': |
---|
[23435] | 88 | $this->doDelete($objFormParam); |
---|
[21526] | 89 | break; |
---|
| 90 | // 表示順を上へ |
---|
| 91 | case 'up': |
---|
| 92 | $this->doUp($objFormParam); |
---|
| 93 | break; |
---|
| 94 | // 表示順を下へ |
---|
| 95 | case 'down': |
---|
| 96 | $this->doDown($objFormParam); |
---|
| 97 | break; |
---|
| 98 | // FIXME r19909 によってテンプレートが削除されている |
---|
| 99 | case 'moveByDnD': |
---|
| 100 | // DnDしたカテゴリと移動先のセットを分解する |
---|
| 101 | $keys = explode('-', $_POST['keySet']); |
---|
| 102 | if ($keys[0] && $keys[1]) { |
---|
[21750] | 103 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21526] | 104 | $objQuery->begin(); |
---|
[20041] | 105 | |
---|
[21526] | 106 | // 移動したデータのrank、level、parent_category_idを取得 |
---|
| 107 | $rank = $objQuery->get('rank', 'dtb_category', 'category_id = ?', array($keys[0])); |
---|
| 108 | $level = $objQuery->get('level', 'dtb_category', 'category_id = ?', array($keys[0])); |
---|
| 109 | $parent = $objQuery->get('parent_category_id', 'dtb_category', 'category_id = ?', array($keys[0])); |
---|
[17872] | 110 | |
---|
[21526] | 111 | // 同一level内のrank配列を作成 |
---|
| 112 | $objQuery->setOption('ORDER BY rank DESC'); |
---|
| 113 | if ($level == 1) { |
---|
| 114 | // 第1階層の時 |
---|
| 115 | $arrRet = $objQuery->select('rank', 'dtb_category', 'level = ?', array($level)); |
---|
| 116 | } else { |
---|
| 117 | // 第2階層以下の時 |
---|
| 118 | $arrRet = $objQuery->select('rank', 'dtb_category', 'level = ? AND parent_category_id = ?', array($level, $parent)); |
---|
| 119 | } |
---|
| 120 | for ($i = 0; $i < sizeof($arrRet); $i++) { |
---|
| 121 | $rankAry[$i + 1] = $arrRet[$i]['rank']; |
---|
| 122 | } |
---|
[17872] | 123 | |
---|
[21526] | 124 | // 移動したデータのグループ内データ数 |
---|
| 125 | $my_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $keys[0]); |
---|
| 126 | if ($rankAry[$keys[1]] > $rank) { |
---|
| 127 | // データが今の位置より上がった時 |
---|
| 128 | $up_count = $rankAry[$keys[1]] - $rank; |
---|
| 129 | $decAry = $objQuery->select('category_id', 'dtb_category', 'level = ? AND rank > ? AND rank <= ?', array($level, $rank, $rankAry[$keys[1]])); |
---|
| 130 | foreach ($decAry as $value) { |
---|
| 131 | // 上のグループから減算 |
---|
| 132 | $this->lfDownRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $value['category_id'], $my_count); |
---|
| 133 | } |
---|
| 134 | // 自分のグループに加算 |
---|
| 135 | $this->lfUpRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $keys[0], $up_count); |
---|
[23124] | 136 | } elseif ($rankAry[$keys[1]] < $rank) { |
---|
[21526] | 137 | // データが今の位置より下がった時 |
---|
| 138 | $down_count = 0; |
---|
| 139 | $incAry = $objQuery->select('category_id', 'dtb_category', 'level = ? AND rank < ? AND rank >= ?', array($level, $rank, $rankAry[$keys[1]])); |
---|
| 140 | foreach ($incAry as $value) { |
---|
| 141 | // 下のグループに加算 |
---|
| 142 | $this->lfUpRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $value['category_id'], $my_count); |
---|
| 143 | // 合計減算値 |
---|
| 144 | $down_count += $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $value['category_id']); |
---|
| 145 | } |
---|
| 146 | // 自分のグループから減算 |
---|
| 147 | $this->lfDownRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $keys[0], $down_count); |
---|
[17872] | 148 | } |
---|
[21526] | 149 | $objQuery->commit(); |
---|
[17872] | 150 | } |
---|
[21526] | 151 | break; |
---|
| 152 | // カテゴリツリークリック時 |
---|
| 153 | case 'tree': |
---|
| 154 | break; |
---|
[21527] | 155 | // CSVダウンロード |
---|
[21526] | 156 | case 'csv': |
---|
| 157 | // CSVを送信する |
---|
| 158 | $objCSV = new SC_Helper_CSV_Ex(); |
---|
[21592] | 159 | |
---|
[21526] | 160 | $objCSV->sfDownloadCsv('5', '', array(), '', true); |
---|
[21743] | 161 | SC_Response_Ex::actionExit(); |
---|
[21526] | 162 | break; |
---|
| 163 | default: |
---|
| 164 | break; |
---|
[15518] | 165 | } |
---|
| 166 | |
---|
[20210] | 167 | $parent_category_id = $objFormParam->getValue('parent_category_id'); |
---|
| 168 | // 空の場合は親カテゴリを0にする |
---|
| 169 | if (empty($parent_category_id)) { |
---|
| 170 | $parent_category_id = 0; |
---|
| 171 | } |
---|
| 172 | // 親カテゴリIDの保持 |
---|
| 173 | $this->arrForm['parent_category_id'] = $parent_category_id; |
---|
| 174 | // カテゴリ一覧を取得 |
---|
| 175 | $this->arrList = $this->findCategoiesByParentCategoryId($parent_category_id); |
---|
| 176 | // カテゴリツリーを取得 |
---|
[22596] | 177 | $this->arrTree = $objCategory->getTree(); |
---|
| 178 | $this->arrParentID = $objCategory->getTreeTrail($parent_category_id); |
---|
[20210] | 179 | // ぱんくずの生成 |
---|
[22597] | 180 | $arrBread = $objCategory->getTreeTrail($this->arrForm['parent_category_id'], FALSE); |
---|
| 181 | $this->tpl_bread_crumbs = SC_Utils_Ex::jsonEncode(array_reverse($arrBread)); |
---|
[15518] | 182 | } |
---|
| 183 | |
---|
| 184 | /** |
---|
[20210] | 185 | * カテゴリの削除を実行する. |
---|
[15518] | 186 | * |
---|
[20210] | 187 | * 下記の場合は削除を実施せず、エラーメッセージを表示する. |
---|
| 188 | * |
---|
| 189 | * - 削除対象のカテゴリに、子カテゴリが1つ以上ある場合 |
---|
| 190 | * - 削除対象のカテゴリを、登録商品が使用している場合 |
---|
| 191 | * |
---|
| 192 | * カテゴリの削除は、物理削除で行う. |
---|
| 193 | * |
---|
[23124] | 194 | * @param SC_FormParam $objFormParam |
---|
[15518] | 195 | * @return void |
---|
| 196 | */ |
---|
[23435] | 197 | public function doDelete(&$objFormParam) |
---|
[22567] | 198 | { |
---|
[23435] | 199 | $objCategory = new SC_Helper_Category_Ex(false); |
---|
[20210] | 200 | $category_id = $objFormParam->getValue('category_id'); |
---|
| 201 | |
---|
| 202 | // 子カテゴリのチェック |
---|
[23435] | 203 | $arrBranch = $objCategory->getTreeBranch($category_id); |
---|
| 204 | if (count($arrBranch) > 0) { |
---|
[21527] | 205 | $this->arrErr['category_name'] = '※ 子カテゴリが存在するため削除できません。<br/>'; |
---|
| 206 | return; |
---|
[20210] | 207 | } |
---|
| 208 | // 登録商品のチェック |
---|
[23435] | 209 | $arrCategory = $objCategory->get($category_id); |
---|
| 210 | if ($arrCategory['product_count'] > 0) { |
---|
[21514] | 211 | $this->arrErr['category_name'] = '※ カテゴリ内に商品が存在するため削除できません。<br/>'; |
---|
[20210] | 212 | return; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | // ランク付きレコードの削除(※処理負荷を考慮してレコードごと削除する。) |
---|
[23435] | 216 | $objCategory->delete($category_id); |
---|
[15518] | 217 | } |
---|
| 218 | |
---|
[20210] | 219 | /** |
---|
| 220 | * 編集対象のカテゴリ名を, 入力ボックスへ表示する. |
---|
| 221 | * |
---|
[23124] | 222 | * @param SC_FormParam $objFormParam |
---|
[20210] | 223 | * @return void |
---|
| 224 | */ |
---|
[23124] | 225 | public function doPreEdit(&$objFormParam) |
---|
[22567] | 226 | { |
---|
[20210] | 227 | $category_id = $objFormParam->getValue('category_id'); |
---|
[15518] | 228 | |
---|
[22595] | 229 | $objCategory = new SC_Helper_Category_Ex(); |
---|
| 230 | $arrRes = $objCategory->get($category_id); |
---|
[15518] | 231 | |
---|
[21356] | 232 | $objFormParam->setParam($arrRes); |
---|
| 233 | |
---|
| 234 | $this->arrForm = $objFormParam->getHashArray(); |
---|
[20210] | 235 | } |
---|
[15518] | 236 | |
---|
[20210] | 237 | /** |
---|
[21356] | 238 | * カテゴリの登録・編集を実行する. |
---|
[20210] | 239 | * |
---|
[21356] | 240 | * 下記の場合は, 登録・編集を実行せず、エラーメッセージを表示する |
---|
[20210] | 241 | * |
---|
| 242 | * - カテゴリ名がすでに使用されている場合 |
---|
[21356] | 243 | * - 階層登録数の上限を超える場合 (登録時のみ評価) |
---|
| 244 | * - カテゴリ名がすでに使用されている場合 (登録時のみ評価) |
---|
[20210] | 245 | * |
---|
[23124] | 246 | * @param SC_FormParam $objFormParam |
---|
[20210] | 247 | * @return void |
---|
| 248 | */ |
---|
[23124] | 249 | public function doEdit(&$objFormParam) |
---|
[22567] | 250 | { |
---|
[21357] | 251 | $category_id = $objFormParam->getValue('category_id'); |
---|
| 252 | |
---|
| 253 | // 追加か |
---|
| 254 | $add = strlen($category_id) === 0; |
---|
| 255 | |
---|
| 256 | // エラーチェック |
---|
| 257 | $this->arrErr = $this->checkError($objFormParam, $add); |
---|
| 258 | |
---|
| 259 | // エラーがない場合、追加・更新処理 |
---|
| 260 | if (empty($this->arrErr)) { |
---|
| 261 | $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 | } |
---|
| 272 | } |
---|
| 273 | // エラーがある場合、入力値の再表示 |
---|
| 274 | else { |
---|
| 275 | $this->arrForm = $objFormParam->getHashArray(); |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | /** |
---|
| 280 | * エラーチェック |
---|
| 281 | * |
---|
[23124] | 282 | * @param SC_FormParam $objFormParam |
---|
| 283 | * @param boolean $add 追加か |
---|
[21357] | 284 | * @return void |
---|
| 285 | */ |
---|
[23124] | 286 | public function checkError(&$objFormParam, $add) |
---|
[22567] | 287 | { |
---|
[21356] | 288 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 289 | |
---|
[20210] | 290 | // 入力項目チェック |
---|
| 291 | $arrErr = $objFormParam->checkError(); |
---|
[21357] | 292 | if (!empty($arrErr)) { |
---|
| 293 | return $arrErr; |
---|
[20210] | 294 | } |
---|
[15518] | 295 | |
---|
[21356] | 296 | $category_id = $objFormParam->getValue('category_id'); |
---|
| 297 | $parent_category_id = $objFormParam->getValue('parent_category_id'); |
---|
| 298 | $category_name = $objFormParam->getValue('category_name'); |
---|
[15518] | 299 | |
---|
[21356] | 300 | // 追加の場合に固有のチェック |
---|
| 301 | if ($add) { |
---|
| 302 | // 登録数上限チェック |
---|
[21514] | 303 | $where = 'del_flg = 0'; |
---|
[21481] | 304 | $count = $objQuery->count('dtb_category', $where); |
---|
[21356] | 305 | if ($count >= CATEGORY_MAX) { |
---|
[21514] | 306 | $arrErr['category_name'] = '※ カテゴリの登録最大数を超えました。<br/>'; |
---|
[23124] | 307 | |
---|
[21357] | 308 | return $arrErr; |
---|
[21356] | 309 | } |
---|
[15518] | 310 | |
---|
[21356] | 311 | // 階層上限チェック |
---|
| 312 | if ($this->isOverLevel($parent_category_id)) { |
---|
[21515] | 313 | $arrErr['category_name'] = '※ ' . LEVEL_MAX . '階層以上の登録はできません。<br/>'; |
---|
[23124] | 314 | |
---|
[21357] | 315 | return $arrErr; |
---|
[21356] | 316 | } |
---|
[20210] | 317 | } |
---|
[15518] | 318 | |
---|
[21356] | 319 | // 重複チェック |
---|
| 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; |
---|
[20210] | 328 | } |
---|
[21376] | 329 | $exists = $objQuery->exists('dtb_category', $where, $arrWhereVal); |
---|
| 330 | if ($exists) { |
---|
[21514] | 331 | $arrErr['category_name'] = '※ 既に同じ内容の登録が存在します。<br/>'; |
---|
[23124] | 332 | |
---|
[21357] | 333 | return $arrErr; |
---|
[20210] | 334 | } |
---|
| 335 | |
---|
[21357] | 336 | return $arrErr; |
---|
[15518] | 337 | } |
---|
[20540] | 338 | |
---|
[20210] | 339 | /** |
---|
| 340 | * カテゴリの表示順序を上へ移動する. |
---|
| 341 | * |
---|
[23124] | 342 | * @param SC_FormParam $objFormParam |
---|
[20210] | 343 | * @return void |
---|
| 344 | */ |
---|
[23124] | 345 | public function doUp(&$objFormParam) |
---|
[22567] | 346 | { |
---|
[20210] | 347 | $category_id = $objFormParam->getValue('category_id'); |
---|
[15518] | 348 | |
---|
[20507] | 349 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20210] | 350 | $objQuery->begin(); |
---|
[21481] | 351 | $up_id = $this->lfGetUpRankID($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); |
---|
[21514] | 352 | if ($up_id != '') { |
---|
[20210] | 353 | // 上のグループのrankから減算する数 |
---|
[21481] | 354 | $my_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); |
---|
[20210] | 355 | // 自分のグループのrankに加算する数 |
---|
[21481] | 356 | $up_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $up_id); |
---|
[20210] | 357 | if ($my_count > 0 && $up_count > 0) { |
---|
| 358 | // 自分のグループに加算 |
---|
[21481] | 359 | $this->lfUpRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id, $up_count); |
---|
[20210] | 360 | // 上のグループから減算 |
---|
[21481] | 361 | $this->lfDownRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $up_id, $my_count); |
---|
[20210] | 362 | } |
---|
| 363 | } |
---|
| 364 | $objQuery->commit(); |
---|
[15518] | 365 | } |
---|
| 366 | |
---|
[20210] | 367 | /** |
---|
| 368 | * カテゴリの表示順序を下へ移動する. |
---|
| 369 | * |
---|
[23124] | 370 | * @param SC_FormParam $objFormParam |
---|
[20210] | 371 | * @return void |
---|
| 372 | */ |
---|
[23124] | 373 | public function doDown(&$objFormParam) |
---|
[22567] | 374 | { |
---|
[20210] | 375 | $category_id = $objFormParam->getValue('category_id'); |
---|
[15518] | 376 | |
---|
[20507] | 377 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20210] | 378 | $objQuery->begin(); |
---|
[21481] | 379 | $down_id = $this->lfGetDownRankID($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); |
---|
[21514] | 380 | if ($down_id != '') { |
---|
[20210] | 381 | // 下のグループのrankに加算する数 |
---|
[21481] | 382 | $my_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); |
---|
[20210] | 383 | // 自分のグループのrankから減算する数 |
---|
[21481] | 384 | $down_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $down_id); |
---|
[20210] | 385 | if ($my_count > 0 && $down_count > 0) { |
---|
| 386 | // 自分のグループから減算 |
---|
[21481] | 387 | $this->lfUpRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $down_id, $my_count); |
---|
[20210] | 388 | // 下のグループに加算 |
---|
[21481] | 389 | $this->lfDownRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id, $down_count); |
---|
[20210] | 390 | } |
---|
[15518] | 391 | } |
---|
[20210] | 392 | $objQuery->commit(); |
---|
| 393 | } |
---|
[15518] | 394 | |
---|
[20210] | 395 | /** |
---|
[20970] | 396 | * パラメーターの初期化を行う |
---|
[20210] | 397 | * |
---|
[23124] | 398 | * @param SC_FormParam $objFormParam |
---|
[20210] | 399 | * @return void |
---|
| 400 | */ |
---|
[23124] | 401 | public function initParam(&$objFormParam) |
---|
[22567] | 402 | { |
---|
[21514] | 403 | $objFormParam->addParam('親カテゴリID', 'parent_category_id', null, null, array()); |
---|
| 404 | $objFormParam->addParam('カテゴリID', 'category_id', null, null, array()); |
---|
| 405 | $objFormParam->addParam('カテゴリ名', 'category_name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
[20210] | 406 | } |
---|
[20540] | 407 | |
---|
[20210] | 408 | /** |
---|
| 409 | * 親カテゴリIDでカテゴリを検索する. |
---|
| 410 | * |
---|
| 411 | * - 表示順の降順でソートする |
---|
| 412 | * - 有効なカテゴリを返す(del_flag = 0) |
---|
| 413 | * |
---|
[23124] | 414 | * @param SC_Query $objQuery |
---|
| 415 | * @param int $parent_category_id 親カテゴリID |
---|
| 416 | * @return array カテゴリの配列 |
---|
[20210] | 417 | */ |
---|
[23124] | 418 | public function findCategoiesByParentCategoryId($parent_category_id) |
---|
[22567] | 419 | { |
---|
[20210] | 420 | if (!$parent_category_id) { |
---|
| 421 | $parent_category_id = 0; |
---|
| 422 | } |
---|
[20507] | 423 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21514] | 424 | $col = 'category_id, category_name, level, rank'; |
---|
| 425 | $where = 'del_flg = 0 AND parent_category_id = ?'; |
---|
| 426 | $objQuery->setOption('ORDER BY rank DESC'); |
---|
[22856] | 427 | |
---|
[21481] | 428 | return $objQuery->select($col, 'dtb_category', $where, array($parent_category_id)); |
---|
[15518] | 429 | } |
---|
| 430 | |
---|
[20210] | 431 | /** |
---|
| 432 | * カテゴリを更新する |
---|
| 433 | * |
---|
[23124] | 434 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
[20210] | 435 | * @return void |
---|
| 436 | */ |
---|
[23124] | 437 | public function updateCategory($category_id, $arrCategory) |
---|
[22567] | 438 | { |
---|
[20507] | 439 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21356] | 440 | |
---|
| 441 | $arrCategory['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
| 442 | |
---|
[20210] | 443 | $objQuery->begin(); |
---|
[21514] | 444 | $where = 'category_id = ?'; |
---|
[21481] | 445 | $objQuery->update('dtb_category', $arrCategory, $where, array($category_id)); |
---|
[20210] | 446 | $objQuery->commit(); |
---|
[15518] | 447 | } |
---|
| 448 | |
---|
[20210] | 449 | /** |
---|
| 450 | * カテゴリを登録する |
---|
| 451 | * |
---|
[23124] | 452 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
[20210] | 453 | * @return void |
---|
| 454 | */ |
---|
[23124] | 455 | public function registerCategory($arrCategory) |
---|
[22567] | 456 | { |
---|
[20507] | 457 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21356] | 458 | |
---|
| 459 | $parent_category_id = $arrCategory['parent_category_id']; |
---|
| 460 | |
---|
[20210] | 461 | $objQuery->begin(); |
---|
[15518] | 462 | |
---|
[20210] | 463 | $rank = null; |
---|
| 464 | if ($parent_category_id == 0) { |
---|
| 465 | // ROOT階層で最大のランクを取得する。 |
---|
[21514] | 466 | $where = 'parent_category_id = ?'; |
---|
[21481] | 467 | $rank = $objQuery->max('rank', 'dtb_category', $where, array($parent_category_id)) + 1; |
---|
[20210] | 468 | } else { |
---|
| 469 | // 親のランクを自分のランクとする。 |
---|
[21514] | 470 | $where = 'category_id = ?'; |
---|
[21481] | 471 | $rank = $objQuery->get('rank', 'dtb_category', $where, array($parent_category_id)); |
---|
[20210] | 472 | // 追加レコードのランク以上のレコードを一つあげる。 |
---|
[22012] | 473 | $where = 'rank >= ?'; |
---|
| 474 | $arrRawSql = array( |
---|
| 475 | 'rank' => '(rank + 1)', |
---|
| 476 | ); |
---|
| 477 | $objQuery->update('dtb_category', array(), $where, array($rank), $arrRawSql); |
---|
[15518] | 478 | } |
---|
| 479 | |
---|
[21514] | 480 | $where = 'category_id = ?'; |
---|
[20210] | 481 | // 自分のレベルを取得する(親のレベル + 1) |
---|
[21481] | 482 | $level = $objQuery->get('level', 'dtb_category', $where, array($parent_category_id)) + 1; |
---|
[15518] | 483 | |
---|
[21185] | 484 | $arrCategory['create_date'] = 'CURRENT_TIMESTAMP'; |
---|
| 485 | $arrCategory['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
[21356] | 486 | $arrCategory['creator_id'] = $_SESSION['member_id']; |
---|
[20210] | 487 | $arrCategory['rank'] = $rank; |
---|
| 488 | $arrCategory['level'] = $level; |
---|
| 489 | $arrCategory['category_id'] = $objQuery->nextVal('dtb_category_category_id'); |
---|
[21356] | 490 | |
---|
[21481] | 491 | $objQuery->insert('dtb_category', $arrCategory); |
---|
[15518] | 492 | |
---|
[20210] | 493 | $objQuery->commit(); // トランザクションの終了 |
---|
| 494 | } |
---|
[20540] | 495 | |
---|
[20210] | 496 | /** |
---|
| 497 | * カテゴリの階層が上限を超えているかを判定する |
---|
| 498 | * |
---|
| 499 | * @param integer 親カテゴリID |
---|
| 500 | * @param 超えている場合 true |
---|
| 501 | */ |
---|
[23124] | 502 | public function isOverLevel($parent_category_id) |
---|
[22567] | 503 | { |
---|
[20507] | 504 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21515] | 505 | $level = $objQuery->get('level', 'dtb_category', 'category_id = ?', array($parent_category_id)); |
---|
[22856] | 506 | |
---|
[20210] | 507 | return $level >= LEVEL_MAX; |
---|
| 508 | } |
---|
[15518] | 509 | |
---|
| 510 | // 並びが1つ下のIDを取得する。 |
---|
[23124] | 511 | public function lfGetDownRankID($objQuery, $table, $pid_name, $id_name, $id) |
---|
[22567] | 512 | { |
---|
[15518] | 513 | // 親IDを取得する。 |
---|
| 514 | $col = "$pid_name"; |
---|
| 515 | $where = "$id_name = ?"; |
---|
[19729] | 516 | $pid = $objQuery->get($col, $table, $where, $id); |
---|
[22960] | 517 | // 全ての子を取得する。 |
---|
[15518] | 518 | $col = "$id_name"; |
---|
| 519 | $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; |
---|
| 520 | $arrRet = $objQuery->select($col, $table, $where, array($pid)); |
---|
| 521 | $max = count($arrRet); |
---|
[21514] | 522 | $down_id = ''; |
---|
[21441] | 523 | for ($cnt = 0; $cnt < $max; $cnt++) { |
---|
| 524 | if ($arrRet[$cnt][$id_name] == $id) { |
---|
[15518] | 525 | $down_id = $arrRet[($cnt + 1)][$id_name]; |
---|
| 526 | break; |
---|
| 527 | } |
---|
| 528 | } |
---|
[22856] | 529 | |
---|
[15518] | 530 | return $down_id; |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | // 並びが1つ上のIDを取得する。 |
---|
[23124] | 534 | public function lfGetUpRankID($objQuery, $table, $pid_name, $id_name, $id) |
---|
[22567] | 535 | { |
---|
[15518] | 536 | // 親IDを取得する。 |
---|
| 537 | $col = "$pid_name"; |
---|
| 538 | $where = "$id_name = ?"; |
---|
[19729] | 539 | $pid = $objQuery->get($col, $table, $where, $id); |
---|
[22960] | 540 | // 全ての子を取得する。 |
---|
[15518] | 541 | $col = "$id_name"; |
---|
| 542 | $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; |
---|
| 543 | $arrRet = $objQuery->select($col, $table, $where, array($pid)); |
---|
| 544 | $max = count($arrRet); |
---|
[21514] | 545 | $up_id = ''; |
---|
[21441] | 546 | for ($cnt = 0; $cnt < $max; $cnt++) { |
---|
| 547 | if ($arrRet[$cnt][$id_name] == $id) { |
---|
[15518] | 548 | $up_id = $arrRet[($cnt - 1)][$id_name]; |
---|
| 549 | break; |
---|
| 550 | } |
---|
| 551 | } |
---|
[22856] | 552 | |
---|
[15518] | 553 | return $up_id; |
---|
| 554 | } |
---|
| 555 | |
---|
[23124] | 556 | public function lfCountChilds($objQuery, $table, $pid_name, $id_name, $id) |
---|
[22567] | 557 | { |
---|
[15518] | 558 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 559 | // 子ID一覧を取得 |
---|
| 560 | $arrRet = $objDb->sfGetChildrenArray($table, $pid_name, $id_name, $id); |
---|
[22856] | 561 | |
---|
[15518] | 562 | return count($arrRet); |
---|
| 563 | } |
---|
| 564 | |
---|
[23124] | 565 | public function lfUpRankChilds($objQuery, $table, $pid_name, $id_name, $id, $count) |
---|
[22567] | 566 | { |
---|
[15518] | 567 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 568 | // 子ID一覧を取得 |
---|
| 569 | $arrRet = $objDb->sfGetChildrenArray($table, $pid_name, $id_name, $id); |
---|
| 570 | $line = SC_Utils_Ex::sfGetCommaList($arrRet); |
---|
[22012] | 571 | $where = "$id_name IN ($line) AND del_flg = 0"; |
---|
| 572 | $arrRawVal = array( |
---|
| 573 | 'rank' => "(rank + $count)", |
---|
| 574 | ); |
---|
[22856] | 575 | |
---|
[22012] | 576 | return $objQuery->update($table, array(), $where, array(), $arrRawVal); |
---|
[15518] | 577 | } |
---|
| 578 | |
---|
[23124] | 579 | public function lfDownRankChilds($objQuery, $table, $pid_name, $id_name, $id, $count) |
---|
[22567] | 580 | { |
---|
[15518] | 581 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 582 | // 子ID一覧を取得 |
---|
| 583 | $arrRet = $objDb->sfGetChildrenArray($table, $pid_name, $id_name, $id); |
---|
| 584 | $line = SC_Utils_Ex::sfGetCommaList($arrRet); |
---|
[22012] | 585 | $where = "$id_name IN ($line) AND del_flg = 0"; |
---|
| 586 | $arrRawVal = array( |
---|
| 587 | 'rank' => "(rank - $count)", |
---|
| 588 | ); |
---|
[22856] | 589 | |
---|
[22012] | 590 | return $objQuery->update($table, array(), $where, array(), $arrRawVal); |
---|
[15518] | 591 | } |
---|
| 592 | } |
---|