/**
  * 商品登録を行う.
  *
  * FIXME: 商品登録の実処理自体は、LC_Page_Admin_Products_Productと共通化して欲しい。
  *
  * @param SC_Query $objQuery
  *            SC_Queryインスタンス
  * @param string|integer $line
  *            処理中の行数
  * @return void
  */
 public function lfRegistProduct($objQuery, $line = '', &$objFormParam)
 {
     // 登録データ対象取得
     $arrList = $objFormParam->getDbArray();
     // 登録時間を生成(DBのCURRENT_TIMESTAMPだとcommitした際、全て同一の時間になってしまう)
     $arrList['update_date'] = $this->lfGetDbFormatTimeWithLine($line);
     // 商品登録情報を生成する。
     // 商品テーブルのカラムに存在しているもののうち、Form投入設定されていないデータは上書きしない。
     $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $this->arrProductColumn);
     // 必須入力では無い項目だが、空文字では問題のある特殊なカラム値の初期値設定
     $sqlval = $this->lfSetProductDefaultData($sqlval);
     GC_Utils_Ex::gfPrintLog(print_r(array(__LINE__, $sqlval, $arrList), true), DEBUG_LOG_REALFILE);
     $sqlval = $objQuery->extractOnlyColsOf($this->table, $sqlval);
     if ($sqlval[$this->id_column] != '') {
         // 同じidが存在すればupdate存在しなければinsert
         $where = $this->id_column . ' = ?';
         $product_exists = $objQuery->exists($this->table, $where, array($sqlval[$this->id_column]));
         if ($product_exists) {
             GC_Utils_Ex::gfPrintLog(print_r(array(__LINE__, $sqlval, $arrList), true), DEBUG_LOG_REALFILE);
             $objQuery->update($this->table, $sqlval, $where, array($sqlval[$this->id_column]));
         } else {
             $sqlval['create_date'] = $arrList['update_date'];
             // INSERTの実行
             GC_Utils_Ex::gfPrintLog(print_r(array(__LINE__, $sqlval, $arrList), true), DEBUG_LOG_REALFILE);
             $objQuery->insert($this->table, $sqlval);
             // シーケンスの調整
             $seq_count = $objQuery->currVal($this->seq_name);
             if ($seq_count < $sqlval[$this->id_column]) {
                 $objQuery->setVal($this->seq_name, $sqlval[$this->id_column] + 1);
             }
         }
         $product_id = $sqlval[$this->id_column];
     } else {
         // 新規登録
         $sqlval[$this->id_column] = $objQuery->nextVal($this->seq_name);
         $product_id = $sqlval[$this->id_column];
         $sqlval['create_date'] = $arrList['update_date'];
         // INSERTの実行
         GC_Utils_Ex::gfPrintLog(print_r(array(__LINE__, $sqlval, $arrList), true), DEBUG_LOG_REALFILE);
         $objQuery->insert($this->table, $sqlval);
     }
     $objDb = new SC_Helper_DB_Ex();
     // カテゴリ登録
     if (isset($arrList['category_ids'])) {
         if ($objDb->sfColumnExists($this->categories_table, $this->id_column)) {
             $objQuery->delete($this->categories_table, $this->id_column . " = ?", array($sqlval[$this->id_column]));
             $arrCategory_id = explode(',', $arrList['category_ids']);
             $rank = 1;
             foreach ($arrCategory_id as $category_id) {
                 $sqlval2 = array($this->id_column => $sqlval[$this->id_column], "category_id" => $category_id, "rank" => $rank++);
                 $sqlval2 = $objQuery->extractOnlyColsOf($this->categories_table, $sqlval2);
                 $objQuery->insert($this->categories_table, $sqlval2);
             }
         }
     } elseif (count($this->arrCategory) == 1) {
         if ($objDb->sfColumnExists($this->categories_table, $this->id_column)) {
             $objQuery->delete($this->categories_table, $this->id_column . " = ?", array($sqlval[$this->id_column]));
             $keys = array_keys($this->arrCategory);
             $sqlval2 = array($this->id_column => $sqlval[$this->id_column], "category_id" => $keys[0], "rank" => 1);
             $sqlval2 = $objQuery->extractOnlyColsOf($this->categories_table, $sqlval2);
             $objQuery->insert($this->categories_table, $sqlval2);
         }
     }
 }
 /**
  * 商品登録を行う.
  *
  * FIXME: 商品登録の実処理自体は、LC_Page_Admin_Products_Productと共通化して欲しい。
  *
  * @param  SC_Query       $objQuery SC_Queryインスタンス
  * @param  string|integer $line     処理中の行数
  * @return void
  */
 public function lfRegistProduct($objQuery, $line = '', &$objFormParam)
 {
     $objProduct = new SC_Product_Ex();
     // 登録データ対象取得
     $arrList = $objFormParam->getDbArray();
     // 登録時間を生成(DBのCURRENT_TIMESTAMPだとcommitした際、全て同一の時間になってしまう)
     $arrList['update_date'] = $this->lfGetDbFormatTimeWithLine($line);
     // 商品登録情報を生成する。
     // 商品テーブルのカラムに存在しているもののうち、Form投入設定されていないデータは上書きしない。
     $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $this->arrProductColumn);
     // 必須入力では無い項目だが、空文字では問題のある特殊なカラム値の初期値設定
     $sqlval = $this->lfSetProductDefaultData($sqlval);
     if ($sqlval['product_id'] != '') {
         // 同じidが存在すればupdate存在しなければinsert
         $where = 'product_id = ?';
         $product_exists = $objQuery->exists('dtb_products', $where, array($sqlval['product_id']));
         if ($product_exists) {
             $objQuery->update('dtb_products', $sqlval, $where, array($sqlval['product_id']));
         } else {
             $sqlval['create_date'] = $arrList['update_date'];
             // INSERTの実行
             $objQuery->insert('dtb_products', $sqlval);
             // シーケンスの調整
             $seq_count = $objQuery->currVal('dtb_products_product_id');
             if ($seq_count < $sqlval['product_id']) {
                 $objQuery->setVal('dtb_products_product_id', $sqlval['product_id'] + 1);
             }
         }
         $product_id = $sqlval['product_id'];
     } else {
         // 新規登録
         $sqlval['product_id'] = $objQuery->nextVal('dtb_products_product_id');
         $product_id = $sqlval['product_id'];
         $sqlval['create_date'] = $arrList['update_date'];
         // INSERTの実行
         $objQuery->insert('dtb_products', $sqlval);
     }
     // カテゴリ登録
     if (isset($arrList['category_ids'])) {
         $arrCategory_id = explode(',', $arrList['category_ids']);
         $this->objDb->updateProductCategories($arrCategory_id, $product_id);
     }
     // 商品ステータス登録
     if (isset($arrList['product_statuses'])) {
         $arrStatus_id = explode(',', $arrList['product_statuses']);
         $objProduct->setProductStatus($product_id, $arrStatus_id);
     }
     // 商品規格情報を登録する
     $this->lfRegistProductClass($objQuery, $arrList, $product_id, $arrList['product_class_id']);
     // 関連商品登録
     $this->lfRegistReccomendProducts($objQuery, $arrList, $product_id);
 }