/** * 規格データをコピーする * * @param array $arrList フォーム入力パラメーター配列 * @param Query $objQuery Queryインスタンス * @return boolean エラーフラグ */ public function lfCopyProductClass($arrList, &$objQuery) { // 複製元のdtb_products_classを取得(規格なしのため、1件のみの取得) $col = '*'; $table = 'dtb_products_class'; $where = 'product_id = ?'; $arrProductClass = $objQuery->select($col, $table, $where, array($arrList['copy_product_id'])); //トランザクション開始 $objQuery->begin(); $err_flag = false; //非編集項目は複製、編集項目は上書きして登録 foreach ($arrProductClass as $records) { foreach ($records as $key => $value) { if (isset($arrList[$key])) { switch ($key) { case 'stock_unlimited': $records[$key] = (int) $arrList[$key]; break; default: $records[$key] = $arrList[$key]; break; } } } $records['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id'); $records['update_date'] = 'CURRENT_TIMESTAMP'; $records['create_date'] = 'CURRENT_TIMESTAMP'; $objQuery->insert($table, $records); //エラー発生時は中断 if ($objQuery->isError()) { $err_flag = true; continue; } } //トランザクション終了 if ($err_flag) { $objQuery->rollback(); } else { $objQuery->commit(); } return !$err_flag; }
/** * 関連商品登録を行う. * * FIXME: 商品規格登録の実処理自体は、LC_Page_Admin_Products_Productと共通化して欲しい。 * DELETE/INSERT ではなく UPDATEへの変更も・・・ * * @param Query $objQuery Queryインスタンス * @param array $arrList 商品規格情報配列 * @param integer $product_id 商品ID * @return void */ public function lfRegistReccomendProducts($objQuery, $arrList, $product_id) { $objQuery->delete('dtb_recommend_products', 'product_id = ?', array($product_id)); for ($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { $keyname = 'recommend_product_id' . $i; $comment_key = 'recommend_comment' . $i; if ($arrList[$keyname] != '') { $arrProduct = $objQuery->select('product_id', 'dtb_products', 'product_id = ?', array($arrList[$keyname])); if ($arrProduct[0]['product_id'] != '') { $arrWhereVal = array(); $arrWhereVal['product_id'] = $product_id; $arrWhereVal['recommend_product_id'] = $arrProduct[0]['product_id']; $arrWhereVal['comment'] = $arrList[$comment_key]; $arrWhereVal['update_date'] = $arrList['update_date']; $arrWhereVal['create_date'] = $arrList['update_date']; $arrWhereVal['creator_id'] = $_SESSION['member_id']; $arrWhereVal['rank'] = RECOMMEND_PRODUCT_MAX - $i + 1; $objQuery->insert('dtb_recommend_products', $arrWhereVal); } } } }
/** * CSVファイルからインサート実行. * * @param Query $objQuery * @param string $dir * @param string $mode * @return boolean */ public function lfExeInsertSQL(&$objQuery, $dir, $mode) { $tbl_flg = false; $col_flg = false; $ret = true; $pagelayout_flg = false; $arrVal = array(); $arrCol = array(); $arrAllTableList = $objQuery->listTables(); $objDir = dir($dir); while (false !== ($file_name = $objDir->read())) { if (!preg_match('/^((dtb|mtb|plg)_(\\w+))\\.csv$/', $file_name, $matches)) { continue; } $file_path = $dir . $file_name; $table = $matches[1]; // テーブル存在チェック if (!in_array($table, $arrAllTableList)) { if ($mode === 'restore_config') { continue; } return false; } // csvファイルからデータの取得 $fp = fopen($file_path, 'r'); if ($fp === false) { trigger_error($file_name . ' のファイルオープンに失敗しました。', E_USER_ERROR); } GcUtils::gfPrintLog('リストア実行: ' . $table); $objQuery->delete($table); $line = 0; $arrColName = array(); while (!feof($fp)) { $line++; $arrCsvLine = fgetcsv($fp, 1024 * 1024); // 1行目: 列名 if ($line === 1) { $arrColName = $arrCsvLine; continue; } // 空行を無視 // false との比較は PHP 5.2.x Windows バグ対応 // 参考: http://www.php.net/manual/ja/function.fgetcsv.php#98502 if ($arrCsvLine === array(null) || $arrCsvLine === false) { continue; } $arrVal = array_combine($arrColName, $arrCsvLine); $objQuery->insert($table, $arrVal); Utils::extendTimeOut(); } fclose($fp); } return $ret; }