[15472] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[22206] | 5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
[15472] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
[16582] | 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. |
---|
[15472] | 22 | */ |
---|
| 23 | |
---|
| 24 | // {{{ requires |
---|
[20534] | 25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
[15472] | 26 | |
---|
| 27 | /** |
---|
[17362] | 28 | * 商品登録CSVのページクラス. |
---|
[15472] | 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
[15551] | 32 | * @version $Id:LC_Page_Admin_Products_UploadCSV.php 15532 2007-08-31 14:39:46Z nanasess $ |
---|
[17985] | 33 | * |
---|
| 34 | * FIXME 同一商品IDで商品規格違いを登録できない。(更新は可能) |
---|
[15472] | 35 | */ |
---|
[20345] | 36 | class LC_Page_Admin_Products_UploadCSV extends LC_Page_Admin_Ex { |
---|
[15472] | 37 | |
---|
| 38 | // }}} |
---|
| 39 | // {{{ functions |
---|
| 40 | |
---|
[19752] | 41 | /** TAGエラーチェックフィールド情報 */ |
---|
| 42 | var $arrTagCheckItem; |
---|
[20041] | 43 | |
---|
[19752] | 44 | /** 商品テーブルカラム情報 (登録処理用) **/ |
---|
| 45 | var $arrProductColumn; |
---|
[20041] | 46 | |
---|
[19752] | 47 | /** 商品規格テーブルカラム情報 (登録処理用) **/ |
---|
| 48 | var $arrProductClassColumn; |
---|
[15472] | 49 | |
---|
[19752] | 50 | /** 登録フォームカラム情報 **/ |
---|
| 51 | var $arrFormKeyList; |
---|
| 52 | |
---|
[20346] | 53 | var $arrRowErr; |
---|
| 54 | |
---|
| 55 | var $arrRowResult; |
---|
[20540] | 56 | |
---|
[15472] | 57 | /** |
---|
| 58 | * Page を初期化する. |
---|
| 59 | * |
---|
| 60 | * @return void |
---|
| 61 | */ |
---|
| 62 | function init() { |
---|
| 63 | parent::init(); |
---|
| 64 | $this->tpl_mainpage = 'products/upload_csv.tpl'; |
---|
| 65 | $this->tpl_mainno = 'products'; |
---|
| 66 | $this->tpl_subno = 'upload_csv'; |
---|
[20911] | 67 | $this->tpl_maintitle = '商品管理'; |
---|
[17362] | 68 | $this->tpl_subtitle = '商品登録CSV'; |
---|
[19752] | 69 | $this->csv_id = '1'; |
---|
| 70 | |
---|
| 71 | $masterData = new SC_DB_MasterData_Ex(); |
---|
[21481] | 72 | $this->arrDISP = $masterData->getMasterData('mtb_disp'); |
---|
| 73 | $this->arrSTATUS = $masterData->getMasterData('mtb_status'); |
---|
| 74 | $this->arrDELIVERYDATE = $masterData->getMasterData('mtb_delivery_date'); |
---|
| 75 | $this->arrProductType = $masterData->getMasterData('mtb_product_type'); |
---|
| 76 | $this->arrMaker = SC_Helper_DB_Ex::sfGetIDValueList('dtb_maker', 'maker_id', 'name'); |
---|
| 77 | $this->arrPayments = SC_Helper_DB_Ex::sfGetIDValueList('dtb_payment', 'payment_id', 'payment_method'); |
---|
[20369] | 78 | $this->arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[21481] | 79 | $this->arrAllowedTag = $masterData->getMasterData('mtb_allowed_tag'); |
---|
[19752] | 80 | $this->arrTagCheckItem = array(); |
---|
[15472] | 81 | } |
---|
| 82 | |
---|
| 83 | /** |
---|
| 84 | * Page のプロセス. |
---|
| 85 | * |
---|
| 86 | * @return void |
---|
| 87 | */ |
---|
| 88 | function process() { |
---|
[19661] | 89 | $this->action(); |
---|
| 90 | $this->sendResponse(); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | /** |
---|
| 94 | * Page のアクション. |
---|
| 95 | * |
---|
| 96 | * @return void |
---|
| 97 | */ |
---|
| 98 | function action() { |
---|
[21591] | 99 | |
---|
[19752] | 100 | $this->objDb = new SC_Helper_DB_Ex(); |
---|
[20540] | 101 | |
---|
[19752] | 102 | // CSV管理ヘルパー |
---|
[20368] | 103 | $objCSV = new SC_Helper_CSV_Ex(); |
---|
[19752] | 104 | // CSV構造読み込み |
---|
[20368] | 105 | $arrCSVFrame = $objCSV->sfGetCsvOutput($this->csv_id); |
---|
[20041] | 106 | |
---|
[19752] | 107 | // CSV構造がインポート可能かのチェック |
---|
[21442] | 108 | if (!$objCSV->sfIsImportCSVFrame($arrCSVFrame)) { |
---|
[19752] | 109 | // 無効なフォーマットなので初期状態に強制変更 |
---|
[20368] | 110 | $arrCSVFrame = $objCSV->sfGetCsvOutput($this->csv_id, '', array(), 'no'); |
---|
[19752] | 111 | $this->tpl_is_format_default = true; |
---|
| 112 | } |
---|
| 113 | // CSV構造は更新可能なフォーマットかのフラグ取得 |
---|
[20368] | 114 | $this->tpl_is_update = $objCSV->sfIsUpdateCSVFrame($arrCSVFrame); |
---|
[19752] | 115 | |
---|
| 116 | // CSVファイルアップロード情報の初期化 |
---|
[20497] | 117 | $objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR); |
---|
[20369] | 118 | $this->lfInitFile($objUpFile); |
---|
| 119 | |
---|
[20970] | 120 | // パラメーター情報の初期化 |
---|
[20501] | 121 | $objFormParam = new SC_FormParam_Ex(); |
---|
[20369] | 122 | $this->lfInitParam($objFormParam, $arrCSVFrame); |
---|
[20346] | 123 | |
---|
[20369] | 124 | $objFormParam->setHtmlDispNameArray(); |
---|
| 125 | $this->arrTitle = $objFormParam->getHtmlDispNameArray(); |
---|
[15472] | 126 | |
---|
[21441] | 127 | switch ($this->getMode()) { |
---|
[21526] | 128 | case 'csv_upload': |
---|
| 129 | $this->doUploadCsv($objFormParam, $objUpFile); |
---|
| 130 | break; |
---|
| 131 | default: |
---|
| 132 | break; |
---|
[20346] | 133 | } |
---|
[21743] | 134 | |
---|
[20346] | 135 | } |
---|
[20041] | 136 | |
---|
[20346] | 137 | /** |
---|
| 138 | * 登録/編集結果のメッセージをプロパティへ追加する |
---|
| 139 | * |
---|
| 140 | * @param integer $line_count 行数 |
---|
| 141 | * @param stirng $message メッセージ |
---|
| 142 | * @return void |
---|
| 143 | */ |
---|
| 144 | function addRowResult($line_count, $message) { |
---|
[21514] | 145 | $this->arrRowResult[] = $line_count . '行目:' . $message; |
---|
[20346] | 146 | } |
---|
[15472] | 147 | |
---|
[20346] | 148 | /** |
---|
| 149 | * 登録/編集結果のエラーメッセージをプロパティへ追加する |
---|
| 150 | * |
---|
| 151 | * @param integer $line_count 行数 |
---|
| 152 | * @param stirng $message メッセージ |
---|
| 153 | * @return void |
---|
| 154 | */ |
---|
| 155 | function addRowErr($line_count, $message) { |
---|
[21514] | 156 | $this->arrRowErr[] = $line_count . '行目:' . $message; |
---|
[20346] | 157 | } |
---|
[15472] | 158 | |
---|
[20346] | 159 | /** |
---|
| 160 | * CSVアップロードを実行します. |
---|
[20738] | 161 | * |
---|
[20346] | 162 | * @return void |
---|
| 163 | */ |
---|
[20369] | 164 | function doUploadCsv(&$objFormParam, &$objUpFile) { |
---|
[20346] | 165 | // ファイルアップロードのチェック |
---|
[21399] | 166 | $this->arrErr['csv_file'] = $objUpFile->makeTempFile('csv_file'); |
---|
| 167 | if (strlen($this->arrErr['csv_file']) >= 1) { |
---|
| 168 | return; |
---|
| 169 | } |
---|
[20369] | 170 | $arrErr = $objUpFile->checkExists(); |
---|
[20346] | 171 | if (count($arrErr) > 0) { |
---|
| 172 | $this->arrErr = $arrErr; |
---|
| 173 | return; |
---|
| 174 | } |
---|
| 175 | // 一時ファイル名の取得 |
---|
[20369] | 176 | $filepath = $objUpFile->getTempFilePath('csv_file'); |
---|
[20346] | 177 | // CSVファイルの文字コード変換 |
---|
| 178 | $enc_filepath = SC_Utils_Ex::sfEncodeFile($filepath, CHAR_CODE, CSV_TEMP_REALDIR); |
---|
| 179 | // CSVファイルのオープン |
---|
[20538] | 180 | $fp = fopen($enc_filepath, 'r'); |
---|
[20346] | 181 | // 失敗した場合はエラー表示 |
---|
| 182 | if (!$fp) { |
---|
[21527] | 183 | SC_Utils_Ex::sfDispError(''); |
---|
[20346] | 184 | } |
---|
[20540] | 185 | |
---|
[20346] | 186 | // 登録先テーブル カラム情報の初期化 |
---|
| 187 | $this->lfInitTableInfo(); |
---|
[20540] | 188 | |
---|
[20346] | 189 | // 登録フォーム カラム情報 |
---|
[20369] | 190 | $this->arrFormKeyList = $objFormParam->getKeyList(); |
---|
[18546] | 191 | |
---|
[20346] | 192 | // 登録対象の列数 |
---|
[20369] | 193 | $col_max_count = $objFormParam->getCount(); |
---|
[20346] | 194 | // 行数 |
---|
| 195 | $line_count = 0; |
---|
[15472] | 196 | |
---|
[20507] | 197 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20346] | 198 | $objQuery->begin(); |
---|
[15472] | 199 | |
---|
[20346] | 200 | $errFlag = false; |
---|
[20740] | 201 | $all_line_checked = false; |
---|
[18508] | 202 | |
---|
[20370] | 203 | while (!feof($fp)) { |
---|
[20346] | 204 | $arrCSV = fgetcsv($fp, CSV_LINE_MAX); |
---|
[20740] | 205 | |
---|
| 206 | // 全行入力チェック後に、ファイルポインターを先頭に戻す |
---|
| 207 | if (feof($fp) && !$all_line_checked) { |
---|
| 208 | rewind($fp); |
---|
| 209 | $line_count = 0; |
---|
| 210 | $all_line_checked = true; |
---|
| 211 | continue; |
---|
| 212 | } |
---|
| 213 | |
---|
[20346] | 214 | // 行カウント |
---|
| 215 | $line_count++; |
---|
| 216 | // ヘッダ行はスキップ |
---|
| 217 | if ($line_count == 1) { |
---|
| 218 | continue; |
---|
| 219 | } |
---|
| 220 | // 空行はスキップ |
---|
| 221 | if (empty($arrCSV)) { |
---|
| 222 | continue; |
---|
| 223 | } |
---|
| 224 | // 列数が異なる場合はエラー |
---|
[20368] | 225 | $col_count = count($arrCSV); |
---|
[20371] | 226 | if ($col_max_count != $col_count) { |
---|
[21515] | 227 | $this->addRowErr($line_count, '※ 項目数が' . $col_count . '個検出されました。項目数は' . $col_max_count . '個になります。'); |
---|
[20346] | 228 | $errFlag = true; |
---|
| 229 | break; |
---|
| 230 | } |
---|
| 231 | // シーケンス配列を格納する。 |
---|
[20369] | 232 | $objFormParam->setParam($arrCSV, true); |
---|
| 233 | $arrRet = $objFormParam->getHashArray(); |
---|
| 234 | $objFormParam->setParam($arrRet); |
---|
[20346] | 235 | // 入力値の変換 |
---|
[20369] | 236 | $objFormParam->convParam(); |
---|
[20346] | 237 | // <br>なしでエラー取得する。 |
---|
[20369] | 238 | $arrCSVErr = $this->lfCheckError($objFormParam); |
---|
[20346] | 239 | |
---|
| 240 | // 入力エラーチェック |
---|
| 241 | if (count($arrCSVErr) > 0) { |
---|
| 242 | foreach ($arrCSVErr as $err) { |
---|
| 243 | $this->addRowErr($line_count, $err); |
---|
[19752] | 244 | } |
---|
[20346] | 245 | $errFlag = true; |
---|
| 246 | break; |
---|
| 247 | } |
---|
[15472] | 248 | |
---|
[20740] | 249 | if ($all_line_checked) { |
---|
| 250 | $this->lfRegistProduct($objQuery, $line_count, $objFormParam); |
---|
| 251 | $arrParam = $objFormParam->getHashArray(); |
---|
[15472] | 252 | |
---|
[21515] | 253 | $this->addRowResult($line_count, '商品ID:'.$arrParam['product_id'] . ' / 商品名:' . $arrParam['name']); |
---|
[20740] | 254 | } |
---|
[21425] | 255 | SC_Utils_Ex::extendTimeOut(); |
---|
[20346] | 256 | } |
---|
[15472] | 257 | |
---|
[20346] | 258 | // 実行結果画面を表示 |
---|
| 259 | $this->tpl_mainpage = 'products/upload_csv_complete.tpl'; |
---|
[15472] | 260 | |
---|
[20738] | 261 | fclose($fp); |
---|
| 262 | |
---|
[20346] | 263 | if ($errFlag) { |
---|
| 264 | $objQuery->rollback(); |
---|
| 265 | return; |
---|
| 266 | } |
---|
[15472] | 267 | |
---|
[20346] | 268 | $objQuery->commit(); |
---|
[15472] | 269 | |
---|
[20346] | 270 | // 商品件数カウント関数の実行 |
---|
| 271 | $this->objDb->sfCountCategory($objQuery); |
---|
| 272 | $this->objDb->sfCountMaker($objQuery); |
---|
[15472] | 273 | } |
---|
[20540] | 274 | |
---|
[15472] | 275 | /** |
---|
| 276 | * デストラクタ. |
---|
| 277 | * |
---|
| 278 | * @return void |
---|
| 279 | */ |
---|
| 280 | function destroy() { |
---|
| 281 | parent::destroy(); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /** |
---|
| 285 | * ファイル情報の初期化を行う. |
---|
| 286 | * |
---|
| 287 | * @return void |
---|
| 288 | */ |
---|
[20369] | 289 | function lfInitFile(&$objUpFile) { |
---|
[21514] | 290 | $objUpFile->addFile('CSVファイル', 'csv_file', array('csv'), CSV_SIZE, true, 0, 0, false); |
---|
[15472] | 291 | } |
---|
| 292 | |
---|
| 293 | /** |
---|
| 294 | * 入力情報の初期化を行う. |
---|
| 295 | * |
---|
[19752] | 296 | * @param array CSV構造設定配列 |
---|
[15472] | 297 | * @return void |
---|
| 298 | */ |
---|
[20369] | 299 | function lfInitParam(&$objFormParam, &$arrCSVFrame) { |
---|
[19752] | 300 | // 固有の初期値調整 |
---|
| 301 | $arrCSVFrame = $this->lfSetParamDefaultValue($arrCSVFrame); |
---|
| 302 | // CSV項目毎の処理 |
---|
[21441] | 303 | foreach ($arrCSVFrame as $item) { |
---|
[21684] | 304 | if ($item['status'] == CSV_COLUMN_STATUS_FLG_DISABLE) continue; |
---|
[19752] | 305 | //サブクエリ構造の場合は AS名 を使用 |
---|
[21441] | 306 | if (preg_match_all('/\(.+\)\s+as\s+(.+)$/i', $item['col'], $match, PREG_SET_ORDER)) { |
---|
[19752] | 307 | $col = $match[0][1]; |
---|
[21441] | 308 | } else { |
---|
[19752] | 309 | $col = $item['col']; |
---|
| 310 | } |
---|
| 311 | // HTML_TAG_CHECKは別途実行なので除去し、別保存しておく |
---|
[21441] | 312 | if (strpos(strtoupper($item['error_check_types']), 'HTML_TAG_CHECK') !== FALSE) { |
---|
[19752] | 313 | $this->arrTagCheckItem[] = $item; |
---|
| 314 | $error_check_types = str_replace('HTML_TAG_CHECK', '', $item['error_check_types']); |
---|
[21441] | 315 | } else { |
---|
[19752] | 316 | $error_check_types = $item['error_check_types']; |
---|
| 317 | } |
---|
| 318 | $arrErrorCheckTypes = explode(',', $error_check_types); |
---|
[21441] | 319 | foreach ($arrErrorCheckTypes as $key => $val) { |
---|
[21514] | 320 | if (trim($val) == '') { |
---|
[19752] | 321 | unset($arrErrorCheckTypes[$key]); |
---|
[21441] | 322 | } else { |
---|
[19752] | 323 | $arrErrorCheckTypes[$key] = trim($val); |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | // パラメーター登録 |
---|
[20369] | 327 | $objFormParam->addParam( |
---|
[19752] | 328 | $item['disp_name'] |
---|
| 329 | , $col |
---|
| 330 | , constant($item['size_const_type']) |
---|
| 331 | , $item['mb_convert_kana_option'] |
---|
| 332 | , $arrErrorCheckTypes |
---|
| 333 | , $item['default'] |
---|
[19950] | 334 | , ($item['rw_flg'] != CSV_COLUMN_RW_FLG_READ_ONLY) ? true : false |
---|
[19752] | 335 | ); |
---|
[15472] | 336 | } |
---|
| 337 | } |
---|
[20041] | 338 | |
---|
[19752] | 339 | /** |
---|
| 340 | * 入力チェックを行う. |
---|
| 341 | * |
---|
| 342 | * @return void |
---|
| 343 | */ |
---|
[20369] | 344 | function lfCheckError(&$objFormParam) { |
---|
[19752] | 345 | // 入力データを渡す。 |
---|
[20369] | 346 | $arrRet = $objFormParam->getHashArray(); |
---|
[20503] | 347 | $objErr = new SC_CheckError_Ex($arrRet); |
---|
[20369] | 348 | $objErr->arrErr = $objFormParam->checkError(false); |
---|
[19752] | 349 | // HTMLタグチェックの実行 |
---|
[21441] | 350 | foreach ($this->arrTagCheckItem as $item) { |
---|
[21480] | 351 | $objErr->doFunc(array($item['disp_name'], $item['col'], $this->arrAllowedTag), array('HTML_TAG_CHECK')); |
---|
[19752] | 352 | } |
---|
| 353 | // このフォーム特有の複雑系のエラーチェックを行う |
---|
[21441] | 354 | if (count($objErr->arrErr) == 0) { |
---|
[19752] | 355 | $objErr->arrErr = $this->lfCheckErrorDetail($arrRet, $objErr->arrErr); |
---|
| 356 | } |
---|
| 357 | return $objErr->arrErr; |
---|
| 358 | } |
---|
[15472] | 359 | |
---|
| 360 | /** |
---|
[19752] | 361 | * 保存先テーブル情報の初期化を行う. |
---|
| 362 | * |
---|
| 363 | * @return void |
---|
| 364 | */ |
---|
| 365 | function lfInitTableInfo() { |
---|
[20507] | 366 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[19752] | 367 | $this->arrProductColumn = $objQuery->listTableFields('dtb_products'); |
---|
| 368 | $this->arrProductClassColumn = $objQuery->listTableFields('dtb_products_class'); |
---|
| 369 | } |
---|
[20041] | 370 | |
---|
[19752] | 371 | /** |
---|
[15472] | 372 | * 商品登録を行う. |
---|
| 373 | * |
---|
[19752] | 374 | * FIXME: 商品登録の実処理自体は、LC_Page_Admin_Products_Productと共通化して欲しい。 |
---|
| 375 | * |
---|
[15472] | 376 | * @param SC_Query $objQuery SC_Queryインスタンス |
---|
| 377 | * @param string|integer $line 処理中の行数 |
---|
| 378 | * @return void |
---|
| 379 | */ |
---|
[21514] | 380 | function lfRegistProduct($objQuery, $line = '', &$objFormParam) { |
---|
[20487] | 381 | $objProduct = new SC_Product_Ex(); |
---|
[19752] | 382 | // 登録データ対象取得 |
---|
[20369] | 383 | $arrList = $objFormParam->getHashArray(); |
---|
[21185] | 384 | // 登録時間を生成(DBのCURRENT_TIMESTAMPだとcommitした際、すべて同一の時間になってしまう) |
---|
[19752] | 385 | $arrList['update_date'] = $this->lfGetDbFormatTimeWithLine($line); |
---|
[15472] | 386 | |
---|
[19752] | 387 | // 商品登録情報を生成する。 |
---|
| 388 | // 商品テーブルのカラムに存在しているもののうち、Form投入設定されていないデータは上書きしない。 |
---|
| 389 | $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $this->arrProductColumn); |
---|
[15551] | 390 | |
---|
[19752] | 391 | // 必須入力では無い項目だが、空文字では問題のある特殊なカラム値の初期値設定 |
---|
| 392 | $sqlval = $this->lfSetProductDefaultData($sqlval); |
---|
[15472] | 393 | |
---|
[21514] | 394 | if ($sqlval['product_id'] != '') { |
---|
[20829] | 395 | // 同じidが存在すればupdate存在しなければinsert |
---|
[21514] | 396 | $where = 'product_id = ?'; |
---|
[21481] | 397 | $product_exists = $objQuery->exists('dtb_products', $where, array($sqlval['product_id'])); |
---|
[21376] | 398 | if ($product_exists) { |
---|
[21481] | 399 | $objQuery->update('dtb_products', $sqlval, $where, array($sqlval['product_id'])); |
---|
[21376] | 400 | } else { |
---|
[20829] | 401 | $sqlval['create_date'] = $arrList['update_date']; |
---|
| 402 | // INSERTの実行 |
---|
[21481] | 403 | $objQuery->insert('dtb_products', $sqlval); |
---|
[20829] | 404 | // シーケンスの調整 |
---|
| 405 | $seq_count = $objQuery->currVal('dtb_products_product_id'); |
---|
[21441] | 406 | if ($seq_count < $sqlval['product_id']) { |
---|
[20829] | 407 | $objQuery->setVal('dtb_products_product_id', $sqlval['product_id'] + 1); |
---|
| 408 | } |
---|
| 409 | } |
---|
[17852] | 410 | $product_id = $sqlval['product_id']; |
---|
[15472] | 411 | } else { |
---|
[17852] | 412 | // 新規登録 |
---|
[18788] | 413 | $sqlval['product_id'] = $objQuery->nextVal('dtb_products_product_id'); |
---|
| 414 | $product_id = $sqlval['product_id']; |
---|
[19752] | 415 | $sqlval['create_date'] = $arrList['update_date']; |
---|
[15472] | 416 | // INSERTの実行 |
---|
[21481] | 417 | $objQuery->insert('dtb_products', $sqlval); |
---|
[15472] | 418 | } |
---|
| 419 | |
---|
[21317] | 420 | // カテゴリ登録 |
---|
[21421] | 421 | if (isset($arrList['category_ids'])) { |
---|
[19752] | 422 | $arrCategory_id = explode(',', $arrList['category_ids']); |
---|
| 423 | $this->objDb->updateProductCategories($arrCategory_id, $product_id); |
---|
| 424 | } |
---|
[21182] | 425 | // 商品ステータス登録 |
---|
[21421] | 426 | if (isset($arrList['product_statuses'])) { |
---|
[19752] | 427 | $arrStatus_id = explode(',', $arrList['product_statuses']); |
---|
| 428 | $objProduct->setProductStatus($product_id, $arrStatus_id); |
---|
| 429 | } |
---|
[20041] | 430 | |
---|
[19752] | 431 | // 商品規格情報を登録する |
---|
| 432 | $this->lfRegistProductClass($objQuery, $arrList, $product_id, $arrList['product_class_id']); |
---|
[16559] | 433 | |
---|
[17455] | 434 | // 関連商品登録 |
---|
[19752] | 435 | $this->lfRegistReccomendProducts($objQuery, $arrList, $product_id); |
---|
[15472] | 436 | } |
---|
| 437 | |
---|
| 438 | /** |
---|
| 439 | * 商品規格登録を行う. |
---|
| 440 | * |
---|
[19752] | 441 | * FIXME: 商品規格登録の実処理自体は、LC_Page_Admin_Products_Productと共通化して欲しい。 |
---|
| 442 | * |
---|
[15472] | 443 | * @param SC_Query $objQuery SC_Queryインスタンス |
---|
| 444 | * @param array $arrList 商品規格情報配列 |
---|
| 445 | * @param integer $product_id 商品ID |
---|
| 446 | * @param integer $product_class_id 商品規格ID |
---|
| 447 | * @return void |
---|
| 448 | */ |
---|
| 449 | function lfRegistProductClass($objQuery, $arrList, $product_id, $product_class_id) { |
---|
[20487] | 450 | $objProduct = new SC_Product_Ex(); |
---|
[19752] | 451 | // 商品規格登録情報を生成する。 |
---|
| 452 | // 商品規格テーブルのカラムに存在しているもののうち、Form投入設定されていないデータは上書きしない。 |
---|
| 453 | $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $this->arrProductClassColumn); |
---|
[15551] | 454 | |
---|
[21514] | 455 | if ($product_class_id == '') { |
---|
[15472] | 456 | // 新規登録 |
---|
[22044] | 457 | // 必須入力では無い項目だが、空文字では問題のある特殊なカラム値の初期値設定 |
---|
| 458 | $sqlval = $this->lfSetProductClassDefaultData($sqlval); |
---|
[15472] | 459 | $sqlval['product_id'] = $product_id; |
---|
[18788] | 460 | $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id'); |
---|
[19752] | 461 | $sqlval['create_date'] = $arrList['update_date']; |
---|
| 462 | // INSERTの実行 |
---|
[21481] | 463 | $objQuery->insert('dtb_products_class', $sqlval); |
---|
[19752] | 464 | $product_class_id = $sqlval['product_class_id']; |
---|
[15472] | 465 | } else { |
---|
[19752] | 466 | // UPDATEの実行 |
---|
[22044] | 467 | // 必須入力では無い項目だが、空文字では問題のある特殊なカラム値の初期値設定 |
---|
| 468 | $sqlval = $this->lfSetProductClassDefaultData($sqlval, true); |
---|
[21514] | 469 | $where = 'product_class_id = ?'; |
---|
[21481] | 470 | $objQuery->update('dtb_products_class', $sqlval, $where, array($product_class_id)); |
---|
[15472] | 471 | } |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | /** |
---|
[19752] | 475 | * 関連商品登録を行う. |
---|
[15472] | 476 | * |
---|
[19752] | 477 | * FIXME: 商品規格登録の実処理自体は、LC_Page_Admin_Products_Productと共通化して欲しい。 |
---|
| 478 | * DELETE/INSERT ではなく UPDATEへの変更も・・・ |
---|
| 479 | * |
---|
| 480 | * @param SC_Query $objQuery SC_Queryインスタンス |
---|
| 481 | * @param array $arrList 商品規格情報配列 |
---|
| 482 | * @param integer $product_id 商品ID |
---|
[15472] | 483 | * @return void |
---|
| 484 | */ |
---|
[19752] | 485 | function lfRegistReccomendProducts($objQuery, $arrList, $product_id) { |
---|
[21514] | 486 | $objQuery->delete('dtb_recommend_products', 'product_id = ?', array($product_id)); |
---|
[21441] | 487 | for ($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { |
---|
[21481] | 488 | $keyname = 'recommend_product_id' . $i; |
---|
| 489 | $comment_key = 'recommend_comment' . $i; |
---|
[21514] | 490 | if ($arrList[$keyname] != '') { |
---|
[21515] | 491 | $arrProduct = $objQuery->select('product_id', 'dtb_products', 'product_id = ?', array($arrList[$keyname])); |
---|
[21514] | 492 | if ($arrProduct[0]['product_id'] != '') { |
---|
[21563] | 493 | $arrWhereVal = array(); |
---|
| 494 | $arrWhereVal['product_id'] = $product_id; |
---|
| 495 | $arrWhereVal['recommend_product_id'] = $arrProduct[0]['product_id']; |
---|
| 496 | $arrWhereVal['comment'] = $arrList[$comment_key]; |
---|
| 497 | $arrWhereVal['update_date'] = $arrList['update_date']; |
---|
| 498 | $arrWhereVal['create_date'] = $arrList['update_date']; |
---|
| 499 | $arrWhereVal['creator_id'] = $_SESSION['member_id']; |
---|
| 500 | $arrWhereVal['rank'] = RECOMMEND_PRODUCT_MAX - $i + 1; |
---|
| 501 | $objQuery->insert('dtb_recommend_products', $arrWhereVal); |
---|
[19752] | 502 | } |
---|
| 503 | } |
---|
| 504 | } |
---|
| 505 | } |
---|
[15472] | 506 | |
---|
[19752] | 507 | /** |
---|
| 508 | * 初期値の設定 |
---|
| 509 | * |
---|
| 510 | * @param array $arrCSVFrame CSV構造配列 |
---|
| 511 | * @return array $arrCSVFrame CSV構造配列 |
---|
| 512 | */ |
---|
| 513 | function lfSetParamDefaultValue(&$arrCSVFrame) { |
---|
[21441] | 514 | foreach ($arrCSVFrame as $key => $val) { |
---|
| 515 | switch ($val['col']) { |
---|
[19752] | 516 | case 'status': |
---|
| 517 | $arrCSVFrame[$key]['default'] = DEFAULT_PRODUCT_DISP; |
---|
| 518 | break; |
---|
| 519 | case 'del_flg': |
---|
| 520 | $arrCSVFrame[$key]['default'] = '0'; |
---|
| 521 | break; |
---|
| 522 | case 'point_rate': |
---|
| 523 | $arrCSVFrame[$key]['default'] = $this->arrInfo['point_rate']; |
---|
| 524 | break; |
---|
| 525 | case 'product_type_id': |
---|
| 526 | $arrCSVFrame[$key]['default'] = DEFAULT_PRODUCT_DOWN; |
---|
| 527 | break; |
---|
[19950] | 528 | case 'stock_unlimited': |
---|
| 529 | $arrCSVFrame[$key]['default'] = UNLIMITED_FLG_LIMITED; |
---|
[19752] | 530 | default: |
---|
| 531 | break; |
---|
| 532 | } |
---|
| 533 | } |
---|
| 534 | return $arrCSVFrame; |
---|
| 535 | } |
---|
[15472] | 536 | |
---|
[19752] | 537 | /** |
---|
| 538 | * 商品データ登録前に特殊な値の持ち方をする部分のデータ部分の初期値補正を行う |
---|
| 539 | * |
---|
| 540 | * @param array $sqlval 商品登録情報配列 |
---|
| 541 | * @return $sqlval 登録情報配列 |
---|
| 542 | */ |
---|
| 543 | function lfSetProductDefaultData(&$sqlval) { |
---|
| 544 | //新規登録時のみ設定する項目 |
---|
[21514] | 545 | if ($sqlval['product_id'] == '') { |
---|
| 546 | if ($sqlval['status'] == '') { |
---|
[19752] | 547 | $sqlval['status'] = DEFAULT_PRODUCT_DISP; |
---|
[15472] | 548 | } |
---|
[19752] | 549 | } |
---|
| 550 | //共通で空欄時に上書きする項目 |
---|
[21514] | 551 | if ($sqlval['del_flg'] == '') { |
---|
[19752] | 552 | $sqlval['del_flg'] = '0'; //有効 |
---|
| 553 | } |
---|
[21514] | 554 | if ($sqlval['creator_id'] == '') { |
---|
[19752] | 555 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
| 556 | } |
---|
| 557 | return $sqlval; |
---|
| 558 | } |
---|
[15472] | 559 | |
---|
[19752] | 560 | /** |
---|
| 561 | * 商品規格データ登録前に特殊な値の持ち方をする部分のデータ部分の初期値補正を行う |
---|
| 562 | * |
---|
| 563 | * @param array $sqlval 商品登録情報配列 |
---|
[22044] | 564 | * @param boolean $upload_flg 更新フラグ(更新の場合true) |
---|
[19752] | 565 | * @return $sqlval 登録情報配列 |
---|
| 566 | */ |
---|
[22044] | 567 | function lfSetProductClassDefaultData(&$sqlval, $upload_flg) { |
---|
[19752] | 568 | //新規登録時のみ設定する項目 |
---|
[21514] | 569 | if ($sqlval['product_class_id'] == '') { |
---|
| 570 | if ($sqlval['point_rate'] == '') { |
---|
[19752] | 571 | $sqlval['point_rate'] = $this->arrInfo['point_rate']; |
---|
[15472] | 572 | } |
---|
[21514] | 573 | if ($sqlval['product_type_id'] == '') { |
---|
[19752] | 574 | $sqlval['product_type_id'] = DEFAULT_PRODUCT_DOWN; |
---|
| 575 | } |
---|
| 576 | } |
---|
| 577 | //共通で設定する項目 |
---|
[21514] | 578 | if ($sqlval['del_flg'] == '') { |
---|
[19752] | 579 | $sqlval['del_flg'] = '0'; //有効 |
---|
| 580 | } |
---|
[21514] | 581 | if ($sqlval['creator_id'] == '') { |
---|
[19752] | 582 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
| 583 | } |
---|
[22044] | 584 | |
---|
[21538] | 585 | // 在庫無制限フラグ列を利用する場合、 |
---|
[22241] | 586 | if (array_key_exists('stock_unlimited', $sqlval) and $sqlval['stock_unlimited'] != '') { |
---|
[21538] | 587 | // 在庫無制限フラグ = 無制限の場合、 |
---|
| 588 | if ($sqlval['stock_unlimited'] == UNLIMITED_FLG_UNLIMITED) { |
---|
| 589 | $sqlval['stock'] = null; |
---|
| 590 | } |
---|
| 591 | } else { |
---|
[22044] | 592 | // 初期登録の場合は、在庫数設定がされていない場合、在庫無制限フラグ = 無制限。 |
---|
| 593 | if (strlen($sqlval['stock']) === 0){ |
---|
| 594 | //更新の場合は、sqlvalのキーにstockがある場合のみ対象 |
---|
[22093] | 595 | if (!$upload_flg or ($upload_flg and array_key_exists('stock', $sqlval))) { |
---|
[22044] | 596 | $sqlval['stock_unlimited'] = UNLIMITED_FLG_UNLIMITED; |
---|
| 597 | } |
---|
[21538] | 598 | } |
---|
| 599 | // 在庫数を入力している場合、在庫無制限フラグ = 制限有り |
---|
| 600 | elseif (strlen($sqlval['stock']) >= 1) { |
---|
| 601 | $sqlval['stock_unlimited'] = UNLIMITED_FLG_LIMITED; |
---|
| 602 | } |
---|
| 603 | // いずれにも該当しない場合、例外エラー |
---|
| 604 | else { |
---|
[21582] | 605 | trigger_error('', E_USER_ERROR); |
---|
[21538] | 606 | } |
---|
| 607 | } |
---|
[19752] | 608 | return $sqlval; |
---|
| 609 | } |
---|
[15472] | 610 | |
---|
[19752] | 611 | /** |
---|
| 612 | * このフォーム特有の複雑な入力チェックを行う. |
---|
| 613 | * |
---|
| 614 | * @param array 確認対象データ |
---|
| 615 | * @param array エラー配列 |
---|
| 616 | * @return array エラー配列 |
---|
| 617 | */ |
---|
| 618 | function lfCheckErrorDetail($item, $arrErr) { |
---|
| 619 | // 規格IDの存在チェック |
---|
[21502] | 620 | // FIXME 規格分類ID自体のが有効かを主眼においたチェックをすべきと感じる。 |
---|
[21441] | 621 | if (!$this->lfIsDbRecord('dtb_products_class', 'product_class_id', $item)) { |
---|
[21514] | 622 | $arrErr['product_class_id'] = '※ 指定の商品規格IDは、登録されていません。'; |
---|
[19752] | 623 | } |
---|
| 624 | // 商品ID、規格IDの組合せチェック |
---|
[21684] | 625 | if (array_search('product_class_id', $this->arrFormKeyList) !== FALSE |
---|
| 626 | && $item['product_class_id'] != '' |
---|
| 627 | ) { |
---|
[21514] | 628 | if ($item['product_id'] == '') { |
---|
| 629 | $arrErr['product_class_id'] = '※ 商品規格ID指定時には商品IDの指定が必須です。'; |
---|
[21441] | 630 | } else { |
---|
[21684] | 631 | if (!$this->objDb->sfIsRecord('dtb_products_class', 'product_id, product_class_id' |
---|
| 632 | , array($item['product_id'], $item['product_class_id'])) |
---|
| 633 | ) { |
---|
[21514] | 634 | $arrErr['product_class_id'] = '※ 指定の商品IDと商品規格IDの組合せは正しくありません。'; |
---|
[16559] | 635 | } |
---|
[15472] | 636 | } |
---|
| 637 | } |
---|
[19752] | 638 | // 表示ステータスの存在チェック |
---|
[21441] | 639 | if (!$this->lfIsArrayRecord($this->arrDISP, 'status', $item)) { |
---|
[21514] | 640 | $arrErr['status'] = '※ 指定の表示ステータスは、登録されていません。'; |
---|
[19752] | 641 | } |
---|
| 642 | // メーカーIDの存在チェック |
---|
[21441] | 643 | if (!$this->lfIsArrayRecord($this->arrMaker, 'maker_id', $item)) { |
---|
[21514] | 644 | $arrErr['maker_id'] = '※ 指定のメーカーIDは、登録されていません。'; |
---|
[19752] | 645 | } |
---|
| 646 | // 発送日目安IDの存在チェック |
---|
[21441] | 647 | if (!$this->lfIsArrayRecord($this->arrDELIVERYDATE, 'deliv_date_id', $item)) { |
---|
[21514] | 648 | $arrErr['deliv_date_id'] = '※ 指定の発送日目安IDは、登録されていません。'; |
---|
[19752] | 649 | } |
---|
| 650 | // 発送日目安IDの存在チェック |
---|
[21441] | 651 | if (!$this->lfIsArrayRecord($this->arrProductType, 'product_type_id', $item)) { |
---|
[21514] | 652 | $arrErr['product_type_id'] = '※ 指定の商品種別IDは、登録されていません。'; |
---|
[19752] | 653 | } |
---|
[21910] | 654 | // 関連商品IDのチェック |
---|
| 655 | $arrRecommendProductUnique = array(); |
---|
[21441] | 656 | for ($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { |
---|
[21910] | 657 | $recommend_product_id_key = 'recommend_product_id' . $i; |
---|
| 658 | if ((array_search($recommend_product_id_key, $this->arrFormKeyList) !== FALSE) |
---|
[21981] | 659 | && ($item[$recommend_product_id_key] != '')) { |
---|
[21910] | 660 | |
---|
| 661 | // 商品IDの存在チェック |
---|
| 662 | if (!$this->objDb->sfIsRecord('dtb_products', 'product_id', (array)$item[$recommend_product_id_key])) { |
---|
| 663 | $arrErr[$recommend_product_id_key] = "※ 指定の関連商品ID($i)は、登録されていません。"; |
---|
| 664 | continue; |
---|
| 665 | } |
---|
| 666 | // 商品IDの重複チェック |
---|
| 667 | $recommend_product_id = $item[$recommend_product_id_key]; |
---|
| 668 | if (isset($arrRecommendProductUnique[$recommend_product_id])) { |
---|
| 669 | $arrErr[$recommend_product_id_key] = "※ 指定の関連商品ID($i)は、すでに登録されています。"; |
---|
| 670 | } else { |
---|
| 671 | $arrRecommendProductUnique[$recommend_product_id] = true; |
---|
| 672 | } |
---|
[19752] | 673 | } |
---|
| 674 | } |
---|
| 675 | // カテゴリIDの存在チェック |
---|
[21441] | 676 | if (!$this->lfIsDbRecordMulti('dtb_category', 'category_id', 'category_ids', $item, ',')) { |
---|
[21514] | 677 | $arrErr['category_ids'] = '※ 指定のカテゴリIDは、登録されていません。'; |
---|
[19752] | 678 | } |
---|
[21182] | 679 | // 商品ステータスIDの存在チェック |
---|
[21441] | 680 | if (!$this->lfIsArrayRecordMulti($this->arrSTATUS, 'product_statuses', $item, ',')) { |
---|
[21514] | 681 | $arrErr['product_statuses'] = '※ 指定の商品ステータスIDは、登録されていません。'; |
---|
[19752] | 682 | } |
---|
| 683 | // 削除フラグのチェック |
---|
[21684] | 684 | if (array_search('del_flg', $this->arrFormKeyList) !== FALSE |
---|
| 685 | && $item['del_flg'] != '' |
---|
| 686 | ) { |
---|
[21481] | 687 | if (!($item['del_flg'] == '0' or $item['del_flg'] == '1')) { |
---|
[21514] | 688 | $arrErr['del_flg'] = '※ 削除フラグは「0」(有効)、「1」(削除)のみが有効な値です。'; |
---|
[19752] | 689 | } |
---|
| 690 | } |
---|
| 691 | /* |
---|
| 692 | TODO: 在庫数の扱いが2.4仕様ではぶれているのでどうするか・・ |
---|
| 693 | // 在庫数/在庫無制限フラグの有効性に関するチェック |
---|
[21514] | 694 | if ($item['stock'] == '') { |
---|
[21441] | 695 | if (array_search('stock_unlimited', $this->arrFormKeyList) === FALSE) { |
---|
[21514] | 696 | $arrErr['stock'] = '※ 在庫数は必須です(無制限フラグ項目がある場合のみ空欄許可)。'; |
---|
[21686] | 697 | } else if ($item['stock_unlimited'] != UNLIMITED_FLG_UNLIMITED) { |
---|
[21514] | 698 | $arrErr['stock'] = '※ 在庫数または在庫無制限フラグのいずれかの入力が必須です。'; |
---|
[19752] | 699 | } |
---|
| 700 | } |
---|
[20041] | 701 | */ |
---|
[19752] | 702 | // ダウンロード商品チェック |
---|
[21527] | 703 | if (array_search('product_type_id', $this->arrFormKeyList) !== FALSE |
---|
| 704 | && $item['product_type_id'] == PRODUCT_TYPE_NORMAL |
---|
| 705 | ) { |
---|
[19752] | 706 | //実商品の場合 |
---|
[21514] | 707 | if ($item['down_filename'] != '') { |
---|
| 708 | $arrErr['down_filename'] = '※ 実商品の場合はダウンロードファイル名は入力できません。'; |
---|
[19752] | 709 | } |
---|
[21514] | 710 | if ($item['down_realfilename'] != '') { |
---|
| 711 | $arrErr['down_realfilename'] = '※ 実商品の場合はダウンロード商品用ファイルアップロードは入力できません。'; |
---|
[19752] | 712 | } |
---|
[21527] | 713 | } elseif (array_search('product_type_id', $this->arrFormKeyList) !== FALSE |
---|
| 714 | && $item['product_type_id'] == PRODUCT_TYPE_DOWNLOAD |
---|
| 715 | ) { |
---|
[19752] | 716 | //ダウンロード商品の場合 |
---|
[21514] | 717 | if ($item['down_filename'] == '') { |
---|
| 718 | $arrErr['down_filename'] = '※ ダウンロード商品の場合はダウンロードファイル名は必須です。'; |
---|
[19752] | 719 | } |
---|
[21514] | 720 | if ($item['down_realfilename'] == '') { |
---|
| 721 | $arrErr['down_realfilename'] = '※ ダウンロード商品の場合はダウンロード商品用ファイルアップロードは必須です。'; |
---|
[19752] | 722 | } |
---|
| 723 | } |
---|
| 724 | return $arrErr; |
---|
[15472] | 725 | } |
---|
| 726 | |
---|
[19752] | 727 | // TODO: ここから下のルーチンは汎用ルーチンとして移動が望ましい |
---|
| 728 | |
---|
[15472] | 729 | /** |
---|
[19752] | 730 | * 指定された行番号をmicrotimeに付与してDB保存用の時間を生成する。 |
---|
[21185] | 731 | * トランザクション内のCURRENT_TIMESTAMPは全てcommit()時の時間に統一されてしまう為。 |
---|
[15472] | 732 | * |
---|
[19752] | 733 | * @param string $line_no 行番号 |
---|
| 734 | * @return string $time DB保存用の時間文字列 |
---|
[15472] | 735 | */ |
---|
[19752] | 736 | function lfGetDbFormatTimeWithLine($line_no = '') { |
---|
[21514] | 737 | $time = date('Y-m-d H:i:s'); |
---|
[19752] | 738 | // 秒以下を生成 |
---|
[21441] | 739 | if ($line_no != '') { |
---|
[21514] | 740 | $microtime = sprintf('%06d', $line_no); |
---|
[19752] | 741 | $time .= ".$microtime"; |
---|
| 742 | } |
---|
| 743 | return $time; |
---|
| 744 | } |
---|
[15472] | 745 | |
---|
[19752] | 746 | /** |
---|
| 747 | * 指定されたキーと複数値の有効性の配列内確認 |
---|
| 748 | * |
---|
| 749 | * @param string $arr チェック対象配列 |
---|
| 750 | * @param string $keyname フォームキー名 |
---|
| 751 | * @param array $item 入力データ配列 |
---|
| 752 | * @param string $delimiter 分割文字 |
---|
| 753 | * @return boolean true:有効なデータがある false:有効ではない |
---|
| 754 | */ |
---|
| 755 | function lfIsArrayRecordMulti($arr, $keyname, $item, $delimiter = ',') { |
---|
[21441] | 756 | if (array_search($keyname, $this->arrFormKeyList) === FALSE) { |
---|
[19752] | 757 | return true; |
---|
[15472] | 758 | } |
---|
[21514] | 759 | if ($item[$keyname] == '') { |
---|
[19752] | 760 | return true; |
---|
[18508] | 761 | } |
---|
[19752] | 762 | $arrItems = explode($delimiter, $item[$keyname]); |
---|
| 763 | //空項目のチェック 1つでも空指定があったら不正とする。 |
---|
[21514] | 764 | if (array_search('', $arrItems) !== FALSE) { |
---|
[19752] | 765 | return false; |
---|
| 766 | } |
---|
| 767 | //キー項目への存在チェック |
---|
[21441] | 768 | foreach ($arrItems as $item) { |
---|
| 769 | if (!array_key_exists($item, $arr)) { |
---|
[19752] | 770 | return false; |
---|
| 771 | } |
---|
| 772 | } |
---|
| 773 | return true; |
---|
[15472] | 774 | } |
---|
| 775 | |
---|
| 776 | /** |
---|
[19752] | 777 | * 指定されたキーと複数値の有効性のDB確認 |
---|
| 778 | * |
---|
| 779 | * @param string $table テーブル名 |
---|
| 780 | * @param string $tblkey テーブルキー名 |
---|
| 781 | * @param string $keyname フォームキー名 |
---|
| 782 | * @param array $item 入力データ配列 |
---|
| 783 | * @param string $delimiter 分割文字 |
---|
| 784 | * @return boolean true:有効なデータがある false:有効ではない |
---|
| 785 | */ |
---|
| 786 | function lfIsDbRecordMulti($table, $tblkey, $keyname, $item, $delimiter = ',') { |
---|
[21441] | 787 | if (array_search($keyname, $this->arrFormKeyList) === FALSE) { |
---|
[19752] | 788 | return true; |
---|
| 789 | } |
---|
[21514] | 790 | if ($item[$keyname] == '') { |
---|
[19752] | 791 | return true; |
---|
| 792 | } |
---|
| 793 | $arrItems = explode($delimiter, $item[$keyname]); |
---|
| 794 | //空項目のチェック 1つでも空指定があったら不正とする。 |
---|
[21514] | 795 | if (array_search('', $arrItems) !== FALSE) { |
---|
[19752] | 796 | return false; |
---|
| 797 | } |
---|
| 798 | $count = count($arrItems); |
---|
[21564] | 799 | $where = $tblkey .' IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', $count) . ')'; |
---|
[20041] | 800 | |
---|
[20507] | 801 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[19752] | 802 | $db_count = $objQuery->count($table, $where, $arrItems); |
---|
[21441] | 803 | if ($count != $db_count) { |
---|
[19752] | 804 | return false; |
---|
| 805 | } |
---|
| 806 | return true; |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | /** |
---|
| 810 | * 指定されたキーと値の有効性のDB確認 |
---|
| 811 | * |
---|
| 812 | * @param string $table テーブル名 |
---|
| 813 | * @param string $keyname キー名 |
---|
| 814 | * @param array $item 入力データ配列 |
---|
| 815 | * @return boolean true:有効なデータがある false:有効ではない |
---|
| 816 | */ |
---|
| 817 | function lfIsDbRecord($table, $keyname, $item) { |
---|
[21684] | 818 | if (array_search($keyname, $this->arrFormKeyList) !== FALSE //入力対象である |
---|
| 819 | && $item[$keyname] != '' // 空ではない |
---|
| 820 | && !$this->objDb->sfIsRecord($table, $keyname, (array)$item[$keyname]) //DBに存在するか |
---|
| 821 | ) { |
---|
[19752] | 822 | return false; |
---|
| 823 | } |
---|
| 824 | return true; |
---|
| 825 | } |
---|
| 826 | |
---|
| 827 | /** |
---|
| 828 | * 指定されたキーと値の有効性の配列内確認 |
---|
| 829 | * |
---|
| 830 | * @param string $arr チェック対象配列 |
---|
| 831 | * @param string $keyname キー名 |
---|
| 832 | * @param array $item 入力データ配列 |
---|
| 833 | * @return boolean true:有効なデータがある false:有効ではない |
---|
| 834 | */ |
---|
| 835 | function lfIsArrayRecord($arr, $keyname, $item) { |
---|
[21684] | 836 | if (array_search($keyname, $this->arrFormKeyList) !== FALSE //入力対象である |
---|
| 837 | && $item[$keyname] != '' // 空ではない |
---|
| 838 | && !array_key_exists($item[$keyname], $arr) //配列に存在するか |
---|
| 839 | ) { |
---|
[19752] | 840 | return false; |
---|
| 841 | } |
---|
| 842 | return true; |
---|
| 843 | } |
---|
[15472] | 844 | } |
---|