[15518] | 1 | <?php |
---|
[16582] | 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[18701] | 5 | * Copyright(c) 2000-2010 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 | |
---|
[16582] | 24 | // {{{ requires |
---|
[20534] | 25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
| 26 | require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_CSV_Ex.php'; |
---|
[15518] | 27 | |
---|
| 28 | /** |
---|
| 29 | * カテゴリ管理 のページクラス. |
---|
| 30 | * |
---|
| 31 | * @package Page |
---|
| 32 | * @author LOCKON CO.,LTD. |
---|
| 33 | * @version $Id$ |
---|
| 34 | */ |
---|
[20345] | 35 | class LC_Page_Admin_Products_Category extends LC_Page_Admin_Ex { |
---|
[15518] | 36 | |
---|
| 37 | // {{{ properties |
---|
| 38 | |
---|
| 39 | // }}} |
---|
| 40 | // {{{ functions |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * Page を初期化する. |
---|
| 44 | * |
---|
| 45 | * @return void |
---|
| 46 | */ |
---|
| 47 | function init() { |
---|
| 48 | parent::init(); |
---|
| 49 | $this->tpl_subtitle = 'カテゴリー登録'; |
---|
| 50 | $this->tpl_mainpage = 'products/category.tpl'; |
---|
[20210] | 51 | $this->tpl_subnavi = 'products/subnavi.tpl'; |
---|
[15518] | 52 | $this->tpl_mainno = 'products'; |
---|
[20210] | 53 | $this->tpl_subno = 'category'; |
---|
[15518] | 54 | $this->tpl_onload = " fnSetFocus('category_name'); "; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * Page のプロセス. |
---|
| 59 | * |
---|
| 60 | * @return void |
---|
| 61 | */ |
---|
| 62 | function process() { |
---|
[19661] | 63 | $this->action(); |
---|
| 64 | $this->sendResponse(); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | /** |
---|
| 68 | * Page のアクション. |
---|
| 69 | * |
---|
| 70 | * @return void |
---|
| 71 | */ |
---|
| 72 | function action() { |
---|
[20210] | 73 | $objDb = new SC_Helper_DB_Ex(); |
---|
[20501] | 74 | $objFormParam = new SC_FormParam_Ex(); |
---|
[15518] | 75 | |
---|
[20210] | 76 | // 入力パラメータ初期化 |
---|
| 77 | $this->initParam($objFormParam); |
---|
| 78 | $objFormParam->setParam($_POST); |
---|
| 79 | $objFormParam->convParam(); |
---|
[15518] | 80 | |
---|
[20041] | 81 | switch($this->getMode()) { |
---|
[20210] | 82 | // カテゴリ登録/編集実行 |
---|
[15518] | 83 | case 'edit': |
---|
[20210] | 84 | $category_id = $objFormParam->getValue('category_id'); |
---|
| 85 | if ($category_id == '') { |
---|
| 86 | $this->doRegister($objFormParam); |
---|
[15518] | 87 | } else { |
---|
[20210] | 88 | $this->doEdit($objFormParam); |
---|
[15518] | 89 | } |
---|
| 90 | break; |
---|
[20210] | 91 | // 入力ボックスへ編集対象のカテゴリ名をセット |
---|
[15518] | 92 | case 'pre_edit': |
---|
[20210] | 93 | $this->doPreEdit($objFormParam); |
---|
[15518] | 94 | break; |
---|
[20210] | 95 | // カテゴリ削除 |
---|
[15518] | 96 | case 'delete': |
---|
[20210] | 97 | $this->doDelete($objFormParam, $objDb); |
---|
[15518] | 98 | break; |
---|
[20210] | 99 | // 表示順を上へ |
---|
[15518] | 100 | case 'up': |
---|
[20210] | 101 | $this->doUp($objFormParam); |
---|
[15518] | 102 | break; |
---|
[20210] | 103 | // 表示順を下へ |
---|
[15518] | 104 | case 'down': |
---|
[20210] | 105 | $this->doDown($objFormParam); |
---|
[15518] | 106 | break; |
---|
[20210] | 107 | // XXX 使われていないコード? |
---|
[17872] | 108 | case 'moveByDnD': |
---|
| 109 | // DnDしたカテゴリと移動先のセットを分解する |
---|
| 110 | $keys = explode("-", $_POST['keySet']); |
---|
| 111 | if ($keys[0] && $keys[1]) { |
---|
[20507] | 112 | $objQuery = new SC_Query_Ex(); |
---|
[17872] | 113 | $objQuery->begin(); |
---|
[20041] | 114 | |
---|
[17872] | 115 | // 移動したデータのrank、level、parent_category_idを取得 |
---|
[20538] | 116 | $rank = $objQuery->get('rank', "dtb_category", "category_id = ?", array($keys[0])); |
---|
| 117 | $level = $objQuery->get('level', "dtb_category", "category_id = ?", array($keys[0])); |
---|
[19729] | 118 | $parent = $objQuery->get("parent_category_id", "dtb_category", "category_id = ?", array($keys[0])); |
---|
[17872] | 119 | |
---|
| 120 | // 同一level内のrank配列を作成 |
---|
[18675] | 121 | $objQuery->setOption("ORDER BY rank DESC"); |
---|
[17872] | 122 | if ($level == 1) { |
---|
| 123 | // 第1階層の時 |
---|
[20538] | 124 | $arrRet = $objQuery->select('rank', "dtb_category", "level = ?", array($level)); |
---|
[17872] | 125 | } else { |
---|
| 126 | // 第2階層以下の時 |
---|
[20538] | 127 | $arrRet = $objQuery->select('rank', "dtb_category", "level = ? AND parent_category_id = ?", array($level, $parent)); |
---|
[17872] | 128 | } |
---|
| 129 | for ($i = 0; $i < sizeof($arrRet); $i++) { |
---|
| 130 | $rankAry[$i + 1] = $arrRet[$i]['rank']; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | // 移動したデータのグループ内データ数 |
---|
| 134 | $my_count = $this->lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $keys[0]); |
---|
| 135 | if ($rankAry[$keys[1]] > $rank) { |
---|
| 136 | // データが今の位置より上がった時 |
---|
| 137 | $up_count = $rankAry[$keys[1]] - $rank; |
---|
| 138 | $decAry = $objQuery->select("category_id", "dtb_category", "level = ? AND rank > ? AND rank <= ?", array($level, $rank, $rankAry[$keys[1]])); |
---|
| 139 | foreach($decAry as $value){ |
---|
| 140 | // 上のグループから減算 |
---|
| 141 | $this->lfDownRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $value["category_id"], $my_count); |
---|
| 142 | } |
---|
| 143 | // 自分のグループに加算 |
---|
| 144 | $this->lfUpRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $keys[0], $up_count); |
---|
| 145 | } else if($rankAry[$keys[1]] < $rank) { |
---|
| 146 | // データが今の位置より下がった時 |
---|
| 147 | $down_count = 0; |
---|
| 148 | $incAry = $objQuery->select("category_id", "dtb_category", "level = ? AND rank < ? AND rank >= ?", array($level, $rank, $rankAry[$keys[1]])); |
---|
| 149 | foreach ($incAry as $value) { |
---|
| 150 | // 下のグループに加算 |
---|
| 151 | $this->lfUpRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $value["category_id"], $my_count); |
---|
| 152 | // 合計減算値 |
---|
| 153 | $down_count += $this->lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $value["category_id"]); |
---|
| 154 | } |
---|
| 155 | // 自分のグループから減算 |
---|
| 156 | $this->lfDownRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $keys[0], $down_count); |
---|
| 157 | } |
---|
| 158 | $objQuery->commit(); |
---|
| 159 | } |
---|
| 160 | break; |
---|
[20210] | 161 | // カテゴリツリークリック時 |
---|
[15518] | 162 | case 'tree': |
---|
| 163 | break; |
---|
[20210] | 164 | // CSVダウンロード |
---|
[17156] | 165 | case 'csv': |
---|
[20210] | 166 | // CSVを送信する。正常終了の場合、終了。 |
---|
[17156] | 167 | $objCSV = new SC_Helper_CSV_Ex(); |
---|
[17799] | 168 | $objCSV->sfDownloadCategoryCsv() && exit; |
---|
[17156] | 169 | break; |
---|
[15518] | 170 | default: |
---|
| 171 | break; |
---|
| 172 | } |
---|
| 173 | |
---|
[20210] | 174 | $parent_category_id = $objFormParam->getValue('parent_category_id'); |
---|
| 175 | // 空の場合は親カテゴリを0にする |
---|
| 176 | if (empty($parent_category_id)) { |
---|
| 177 | $parent_category_id = 0; |
---|
| 178 | } |
---|
| 179 | // 親カテゴリIDの保持 |
---|
| 180 | $this->arrForm['parent_category_id'] = $parent_category_id; |
---|
| 181 | // カテゴリ一覧を取得 |
---|
| 182 | $this->arrList = $this->findCategoiesByParentCategoryId($parent_category_id); |
---|
| 183 | // カテゴリツリーを取得 |
---|
| 184 | $this->arrTree = $objDb->sfGetCatTree($parent_category_id); |
---|
| 185 | // ぱんくずの生成 |
---|
[19909] | 186 | $arrBread = array(); |
---|
[20210] | 187 | $objDb->findTree($this->arrTree, $parent_category_id, $arrBread); |
---|
[20688] | 188 | $this->tpl_bread_crumbs = SC_Utils_Ex::jsonEncode($arrBread); |
---|
[15518] | 189 | } |
---|
| 190 | |
---|
| 191 | /** |
---|
[20210] | 192 | * カテゴリの削除を実行する. |
---|
[15518] | 193 | * |
---|
[20210] | 194 | * 下記の場合は削除を実施せず、エラーメッセージを表示する. |
---|
| 195 | * |
---|
| 196 | * - 削除対象のカテゴリに、子カテゴリが1つ以上ある場合 |
---|
| 197 | * - 削除対象のカテゴリを、登録商品が使用している場合 |
---|
| 198 | * |
---|
| 199 | * カテゴリの削除は、物理削除で行う. |
---|
| 200 | * |
---|
| 201 | * @param SC_FormParam $objFormParam |
---|
| 202 | * @param SC_Helper_Db $objDb |
---|
[15518] | 203 | * @return void |
---|
| 204 | */ |
---|
[20210] | 205 | function doDelete(&$objFormParam, &$objDb) { |
---|
| 206 | $category_id = $objFormParam->getValue('category_id'); |
---|
[20507] | 207 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20210] | 208 | |
---|
| 209 | // 子カテゴリのチェック |
---|
| 210 | $where = "parent_category_id = ? AND del_flg = 0"; |
---|
| 211 | $count = $objQuery->count("dtb_category", $where, array($category_id)); |
---|
| 212 | if ($count > 0) { |
---|
| 213 | $this->arrErr['category_name'] = "※ 子カテゴリが存在するため削除できません。<br/>"; |
---|
| 214 | return; |
---|
| 215 | } |
---|
| 216 | // 登録商品のチェック |
---|
| 217 | $table = "dtb_product_categories AS T1 LEFT JOIN dtb_products AS T2 ON T1.product_id = T2.product_id"; |
---|
| 218 | $where = "T1.category_id = ? AND T2.del_flg = 0"; |
---|
| 219 | $count = $objQuery->count($table, $where, array($category_id)); |
---|
| 220 | if ($count > 0) { |
---|
| 221 | $this->arrErr['category_name'] = "※ カテゴリ内に商品が存在するため削除できません。<br/>"; |
---|
| 222 | return; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | // ランク付きレコードの削除(※処理負荷を考慮してレコードごと削除する。) |
---|
| 226 | $objDb->sfDeleteRankRecord("dtb_category", "category_id", $category_id, "", true); |
---|
[15518] | 227 | } |
---|
| 228 | |
---|
[20210] | 229 | /** |
---|
| 230 | * 編集対象のカテゴリ名を, 入力ボックスへ表示する. |
---|
| 231 | * |
---|
| 232 | * @param SC_FormParam $objFormParam |
---|
| 233 | * @return void |
---|
| 234 | */ |
---|
| 235 | function doPreEdit(&$objFormParam) { |
---|
| 236 | $category_id = $objFormParam->getValue('category_id'); |
---|
[15518] | 237 | |
---|
[20507] | 238 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[15518] | 239 | |
---|
[20210] | 240 | // 編集対象のカテゴリ名をDBより取得する |
---|
| 241 | $where = "category_id = ?"; |
---|
| 242 | $category_name = $objQuery->get("category_name", "dtb_category", $where, array($category_id)); |
---|
[15518] | 243 | |
---|
[20210] | 244 | // 入力ボックスへカテゴリ名を保持する. |
---|
| 245 | $this->arrForm['category_name'] = $category_name; |
---|
| 246 | // カテゴリIDを保持する. |
---|
| 247 | $this->arrForm['category_id'] = $category_id; |
---|
| 248 | } |
---|
[15518] | 249 | |
---|
[20210] | 250 | /** |
---|
| 251 | * カテゴリの編集を実行する. |
---|
| 252 | * |
---|
| 253 | * 下記の場合は, 編集を実行せず、エラーメッセージを表示する |
---|
| 254 | * |
---|
| 255 | * - カテゴリ名がすでに使用されている場合 |
---|
| 256 | * |
---|
| 257 | * @param SC_FormParam $objFormParam |
---|
| 258 | * @return void |
---|
| 259 | */ |
---|
| 260 | function doEdit(&$objFormParam) { |
---|
| 261 | // 入力項目チェック |
---|
| 262 | $arrErr = $objFormParam->checkError(); |
---|
| 263 | if (count($arrErr) > 0) { |
---|
| 264 | $this->arrErr = $arrErr; |
---|
| 265 | $this->arrForm['category_id'] = $objFormParam->getValue('category_id'); |
---|
| 266 | $this->arrForm['category_name'] = $objFormParam->getValue('category_name'); |
---|
| 267 | return; |
---|
| 268 | } |
---|
[15518] | 269 | |
---|
[20210] | 270 | // 重複チェック |
---|
[20507] | 271 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20210] | 272 | $where = "parent_category_id = ? AND category_id <> ? AND category_name = ?"; |
---|
| 273 | $count = $objQuery->count("dtb_category", |
---|
| 274 | $where, |
---|
| 275 | array($objFormParam->getValue('parent_category_id'), |
---|
| 276 | $objFormParam->getValue('category_id'), |
---|
| 277 | $objFormParam->getValue('category_name'))); |
---|
| 278 | if ($count > 0) { |
---|
| 279 | $this->arrErr['category_name'] = "※ 既に同じ内容の登録が存在します。<br/>"; |
---|
| 280 | $this->arrForm['category_id'] = $objFormParam->getValue('category_id'); |
---|
| 281 | $this->arrForm['category_name'] = $objFormParam->getValue('category_name'); |
---|
| 282 | return; |
---|
[15518] | 283 | } |
---|
| 284 | |
---|
[20210] | 285 | // カテゴリ更新 |
---|
| 286 | $arrCategory = array(); |
---|
| 287 | $arrCategory['category_name'] = $objFormParam->getValue('category_name'); |
---|
| 288 | $arrCategory['update_date'] = 'NOW()'; |
---|
| 289 | $this->updateCategory($objFormParam->getValue('category_id'), $arrCategory); |
---|
| 290 | } |
---|
[15518] | 291 | |
---|
[20210] | 292 | /** |
---|
| 293 | * カテゴリの登録を実行する. |
---|
| 294 | * |
---|
| 295 | * 下記の場合は, 登録を実行せず、エラーメッセージを表示する |
---|
| 296 | * |
---|
| 297 | * - カテゴリ登録数の上限を超える場合 |
---|
| 298 | * - 階層登録数の上限を超える場合 |
---|
| 299 | * - カテゴリ名がすでに使用されている場合 |
---|
| 300 | * |
---|
| 301 | * @param SC_FormParam $objFormParam |
---|
| 302 | * @return void |
---|
| 303 | */ |
---|
| 304 | function doRegister(&$objFormParam) { |
---|
| 305 | // 入力項目チェック |
---|
| 306 | $arrErr = $objFormParam->checkError(); |
---|
| 307 | if (count($arrErr) > 0) { |
---|
| 308 | $this->arrErr = $arrErr; |
---|
| 309 | $this->arrForm['category_name'] = $objFormParam->getValue('category_name'); |
---|
| 310 | return; |
---|
| 311 | } |
---|
[15518] | 312 | |
---|
[20210] | 313 | // 登録数上限チェック |
---|
[20507] | 314 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20210] | 315 | $where = "del_flg = 0"; |
---|
| 316 | $count = $objQuery->count("dtb_category", $where); |
---|
| 317 | if ($count >= CATEGORY_MAX) { |
---|
| 318 | $this->arrErr['category_name'] = "※ カテゴリの登録最大数を超えました。<br/>"; |
---|
| 319 | $this->arrForm['category_name'] = $objFormParam->getValue('category_name'); |
---|
| 320 | return; |
---|
| 321 | } |
---|
[15518] | 322 | |
---|
[20210] | 323 | // 階層上限チェック |
---|
[20279] | 324 | if ($this->isOverLevel($objFormParam->getValue('parent_category_id'))) { |
---|
[20210] | 325 | $this->arrErr['category_name'] = "※ " . LEVEL_MAX . "階層以上の登録はできません。<br/>"; |
---|
| 326 | $this->arrForm['category_name'] = $objFormParam->getValue('category_name'); |
---|
| 327 | return; |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | // 重複チェック |
---|
| 331 | $where = "parent_category_id = ? AND category_name = ?"; |
---|
| 332 | $count = $objQuery->count("dtb_category", |
---|
| 333 | $where, |
---|
| 334 | array($objFormParam->getValue('parent_category_id'), |
---|
| 335 | $objFormParam->getValue('category_name'))); |
---|
| 336 | if ($count > 0) { |
---|
| 337 | $this->arrErr['category_name'] = "※ 既に同じ内容の登録が存在します。<br/>"; |
---|
| 338 | $this->arrForm['category_name'] = $objFormParam->getValue('category_name'); |
---|
| 339 | return; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | // カテゴリ登録 |
---|
| 343 | $this->registerCategory($objFormParam->getValue('parent_category_id'), |
---|
| 344 | $objFormParam->getValue('category_name'), |
---|
| 345 | $_SESSION['member_id']); |
---|
[15518] | 346 | } |
---|
[20540] | 347 | |
---|
[20210] | 348 | /** |
---|
| 349 | * カテゴリの表示順序を上へ移動する. |
---|
| 350 | * |
---|
| 351 | * @param SC_FormParam $objFormParam |
---|
| 352 | * @return void |
---|
| 353 | */ |
---|
| 354 | function doUp(&$objFormParam) { |
---|
| 355 | $category_id = $objFormParam->getValue('category_id'); |
---|
[15518] | 356 | |
---|
[20507] | 357 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20210] | 358 | $objQuery->begin(); |
---|
| 359 | $up_id = $this->lfGetUpRankID($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); |
---|
| 360 | if ($up_id != "") { |
---|
| 361 | // 上のグループのrankから減算する数 |
---|
| 362 | $my_count = $this->lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); |
---|
| 363 | // 自分のグループのrankに加算する数 |
---|
| 364 | $up_count = $this->lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $up_id); |
---|
| 365 | if ($my_count > 0 && $up_count > 0) { |
---|
| 366 | // 自分のグループに加算 |
---|
| 367 | $this->lfUpRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id, $up_count); |
---|
| 368 | // 上のグループから減算 |
---|
| 369 | $this->lfDownRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $up_id, $my_count); |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | $objQuery->commit(); |
---|
[15518] | 373 | } |
---|
| 374 | |
---|
[20210] | 375 | /** |
---|
| 376 | * カテゴリの表示順序を下へ移動する. |
---|
| 377 | * |
---|
| 378 | * @param SC_FormParam $objFormParam |
---|
| 379 | * @return void |
---|
| 380 | */ |
---|
| 381 | function doDown(&$objFormParam) { |
---|
| 382 | $category_id = $objFormParam->getValue('category_id'); |
---|
[15518] | 383 | |
---|
[20507] | 384 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20210] | 385 | $objQuery->begin(); |
---|
| 386 | $down_id = $this->lfGetDownRankID($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); |
---|
| 387 | if ($down_id != "") { |
---|
| 388 | // 下のグループのrankに加算する数 |
---|
| 389 | $my_count = $this->lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); |
---|
| 390 | // 自分のグループのrankから減算する数 |
---|
| 391 | $down_count = $this->lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $down_id); |
---|
| 392 | if ($my_count > 0 && $down_count > 0) { |
---|
| 393 | // 自分のグループから減算 |
---|
| 394 | $this->lfUpRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $down_id, $my_count); |
---|
| 395 | // 下のグループに加算 |
---|
| 396 | $this->lfDownRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id, $down_count); |
---|
| 397 | } |
---|
[15518] | 398 | } |
---|
[20210] | 399 | $objQuery->commit(); |
---|
| 400 | } |
---|
[15518] | 401 | |
---|
[20210] | 402 | /** |
---|
| 403 | * パラメータの初期化を行う |
---|
| 404 | * |
---|
| 405 | * @param SC_FormParam $objFormParam |
---|
| 406 | * @return void |
---|
| 407 | */ |
---|
| 408 | function initParam(&$objFormParam) { |
---|
| 409 | $objFormParam->addParam("親カテゴリID", "parent_category_id", null, null, array()); |
---|
| 410 | $objFormParam->addParam("カテゴリID", "category_id", null, null, array()); |
---|
[20538] | 411 | $objFormParam->addParam("カテゴリ名", "category_name", STEXT_LEN, 'KVa', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
[20210] | 412 | } |
---|
[20540] | 413 | |
---|
[20210] | 414 | /** |
---|
| 415 | * 親カテゴリIDでカテゴリを検索する. |
---|
| 416 | * |
---|
| 417 | * - 表示順の降順でソートする |
---|
| 418 | * - 有効なカテゴリを返す(del_flag = 0) |
---|
| 419 | * |
---|
| 420 | * @param SC_Query $objQuery |
---|
| 421 | * @param int $parent_category_id 親カテゴリID |
---|
| 422 | * @return array カテゴリの配列 |
---|
| 423 | */ |
---|
| 424 | function findCategoiesByParentCategoryId($parent_category_id) { |
---|
| 425 | if (!$parent_category_id) { |
---|
| 426 | $parent_category_id = 0; |
---|
| 427 | } |
---|
[20507] | 428 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20210] | 429 | $col = "category_id, category_name, level, rank"; |
---|
[15518] | 430 | $where = "del_flg = 0 AND parent_category_id = ?"; |
---|
[18675] | 431 | $objQuery->setOption("ORDER BY rank DESC"); |
---|
[20210] | 432 | return $objQuery->select($col, "dtb_category", $where, array($parent_category_id)); |
---|
[15518] | 433 | } |
---|
| 434 | |
---|
[20210] | 435 | /** |
---|
| 436 | * カテゴリを更新する |
---|
| 437 | * |
---|
| 438 | * @param integer $category_id 更新対象のカテゴリID |
---|
| 439 | * @param array 更新する カラム名 => 値 の連想配列 |
---|
| 440 | * @return void |
---|
| 441 | */ |
---|
| 442 | function updateCategory($category_id, $arrCategory) { |
---|
[20507] | 443 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20210] | 444 | $objQuery->begin(); |
---|
| 445 | $where = "category_id = ?"; |
---|
| 446 | $objQuery->update("dtb_category", $arrCategory, $where, array($category_id)); |
---|
| 447 | $objQuery->commit(); |
---|
[15518] | 448 | } |
---|
| 449 | |
---|
[20210] | 450 | /** |
---|
| 451 | * カテゴリを登録する |
---|
| 452 | * |
---|
| 453 | * @param integer 親カテゴリID |
---|
| 454 | * @param string カテゴリ名 |
---|
| 455 | * @param integer 作成者のID |
---|
| 456 | * @return void |
---|
| 457 | */ |
---|
| 458 | function registerCategory($parent_category_id, $category_name, $creator_id) { |
---|
[20507] | 459 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20210] | 460 | $objQuery->begin(); |
---|
[15518] | 461 | |
---|
[20210] | 462 | $rank = null; |
---|
| 463 | if ($parent_category_id == 0) { |
---|
| 464 | // ROOT階層で最大のランクを取得する。 |
---|
| 465 | $where = "parent_category_id = ?"; |
---|
[20538] | 466 | $rank = $objQuery->max('rank', "dtb_category", $where, array($parent_category_id)) + 1; |
---|
[20210] | 467 | } else { |
---|
| 468 | // 親のランクを自分のランクとする。 |
---|
| 469 | $where = "category_id = ?"; |
---|
[20538] | 470 | $rank = $objQuery->get('rank', "dtb_category", $where, array($parent_category_id)); |
---|
[20210] | 471 | // 追加レコードのランク以上のレコードを一つあげる。 |
---|
| 472 | $sqlup = "UPDATE dtb_category SET rank = (rank + 1) WHERE rank >= ?"; |
---|
| 473 | $objQuery->exec($sqlup, array($rank)); |
---|
[15518] | 474 | } |
---|
| 475 | |
---|
[20210] | 476 | $where = "category_id = ?"; |
---|
| 477 | // 自分のレベルを取得する(親のレベル + 1) |
---|
[20538] | 478 | $level = $objQuery->get('level', "dtb_category", $where, array($parent_category_id)) + 1; |
---|
[15518] | 479 | |
---|
[20210] | 480 | $arrCategory = array(); |
---|
| 481 | $arrCategory['category_name'] = $category_name; |
---|
| 482 | $arrCategory['parent_category_id'] = $parent_category_id; |
---|
| 483 | $arrCategory['create_date'] = "Now()"; |
---|
| 484 | $arrCategory['update_date'] = "Now()"; |
---|
| 485 | $arrCategory['creator_id'] = $creator_id; |
---|
| 486 | $arrCategory['rank'] = $rank; |
---|
| 487 | $arrCategory['level'] = $level; |
---|
| 488 | $arrCategory['category_id'] = $objQuery->nextVal('dtb_category_category_id'); |
---|
| 489 | $objQuery->insert("dtb_category", $arrCategory); |
---|
[15518] | 490 | |
---|
[20210] | 491 | $objQuery->commit(); // トランザクションの終了 |
---|
| 492 | } |
---|
[20540] | 493 | |
---|
[20210] | 494 | /** |
---|
| 495 | * カテゴリの階層が上限を超えているかを判定する |
---|
| 496 | * |
---|
| 497 | * @param integer 親カテゴリID |
---|
| 498 | * @param 超えている場合 true |
---|
| 499 | */ |
---|
| 500 | function isOverLevel($parent_category_id) { |
---|
[20507] | 501 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20538] | 502 | $level = $objQuery->get('level', "dtb_category", "category_id = ?", array($parent_category_id)); |
---|
[20210] | 503 | return $level >= LEVEL_MAX; |
---|
| 504 | } |
---|
[15518] | 505 | |
---|
[20210] | 506 | /** |
---|
| 507 | * デストラクタ. |
---|
| 508 | * |
---|
| 509 | * @return void |
---|
| 510 | */ |
---|
| 511 | function destroy() { |
---|
| 512 | parent::destroy(); |
---|
[15518] | 513 | } |
---|
| 514 | |
---|
| 515 | // 並びが1つ下のIDを取得する。 |
---|
| 516 | function lfGetDownRankID($objQuery, $table, $pid_name, $id_name, $id) { |
---|
| 517 | // 親IDを取得する。 |
---|
| 518 | $col = "$pid_name"; |
---|
| 519 | $where = "$id_name = ?"; |
---|
[19729] | 520 | $pid = $objQuery->get($col, $table, $where, $id); |
---|
[15518] | 521 | // すべての子を取得する。 |
---|
| 522 | $col = "$id_name"; |
---|
| 523 | $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; |
---|
| 524 | $arrRet = $objQuery->select($col, $table, $where, array($pid)); |
---|
| 525 | $max = count($arrRet); |
---|
| 526 | $down_id = ""; |
---|
| 527 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
| 528 | if($arrRet[$cnt][$id_name] == $id) { |
---|
| 529 | $down_id = $arrRet[($cnt + 1)][$id_name]; |
---|
| 530 | break; |
---|
| 531 | } |
---|
| 532 | } |
---|
| 533 | return $down_id; |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | // 並びが1つ上のIDを取得する。 |
---|
| 537 | function lfGetUpRankID($objQuery, $table, $pid_name, $id_name, $id) { |
---|
| 538 | // 親IDを取得する。 |
---|
| 539 | $col = "$pid_name"; |
---|
| 540 | $where = "$id_name = ?"; |
---|
[19729] | 541 | $pid = $objQuery->get($col, $table, $where, $id); |
---|
[15518] | 542 | // すべての子を取得する。 |
---|
| 543 | $col = "$id_name"; |
---|
| 544 | $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; |
---|
| 545 | $arrRet = $objQuery->select($col, $table, $where, array($pid)); |
---|
| 546 | $max = count($arrRet); |
---|
| 547 | $up_id = ""; |
---|
| 548 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
| 549 | if($arrRet[$cnt][$id_name] == $id) { |
---|
| 550 | $up_id = $arrRet[($cnt - 1)][$id_name]; |
---|
| 551 | break; |
---|
| 552 | } |
---|
| 553 | } |
---|
| 554 | return $up_id; |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | function lfCountChilds($objQuery, $table, $pid_name, $id_name, $id) { |
---|
| 558 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 559 | // 子ID一覧を取得 |
---|
| 560 | $arrRet = $objDb->sfGetChildrenArray($table, $pid_name, $id_name, $id); |
---|
| 561 | return count($arrRet); |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | function lfUpRankChilds($objQuery, $table, $pid_name, $id_name, $id, $count) { |
---|
| 565 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 566 | // 子ID一覧を取得 |
---|
| 567 | $arrRet = $objDb->sfGetChildrenArray($table, $pid_name, $id_name, $id); |
---|
| 568 | $line = SC_Utils_Ex::sfGetCommaList($arrRet); |
---|
| 569 | $sql = "UPDATE $table SET rank = (rank + $count) WHERE $id_name IN ($line) "; |
---|
| 570 | $sql.= "AND del_flg = 0"; |
---|
| 571 | $ret = $objQuery->exec($sql); |
---|
| 572 | return $ret; |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | function lfDownRankChilds($objQuery, $table, $pid_name, $id_name, $id, $count) { |
---|
| 576 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 577 | // 子ID一覧を取得 |
---|
| 578 | $arrRet = $objDb->sfGetChildrenArray($table, $pid_name, $id_name, $id); |
---|
| 579 | $line = SC_Utils_Ex::sfGetCommaList($arrRet); |
---|
| 580 | $sql = "UPDATE $table SET rank = (rank - $count) WHERE $id_name IN ($line) "; |
---|
| 581 | $sql.= "AND del_flg = 0"; |
---|
| 582 | $ret = $objQuery->exec($sql); |
---|
| 583 | return $ret; |
---|
| 584 | } |
---|
| 585 | } |
---|