Example #1
0
 /**
  * クエリを構築する.
  *
  * 検索条件のキーに応じた WHERE 句と, クエリパラメーターを構築する.
  * クエリパラメーターは, FormParam の入力値から取得する.
  *
  * 構築内容は, 引数の $where 及び $arrValues にそれぞれ追加される.
  *
  * @param  string       $key          検索条件のキー
  * @param  string       $where        構築する WHERE 句
  * @param  array        $arrValues    構築するクエリパラメーター
  * @param  FormParam $objFormParam FormParam インスタンス
  * @param  FormParam $objDb        DbHelper インスタンス
  * @return void
  */
 public function buildQuery($key, &$where, &$arrValues, &$objFormParam, &$objDb)
 {
     /* @var $dbFactory DBFactory */
     $dbFactory = Application::alias('eccube.db.factory');
     switch ($key) {
         // 商品ID
         case 'search_product_id':
             $where .= ' AND product_id = ?';
             $arrValues[] = sprintf('%d', $objFormParam->getValue($key));
             break;
             // 商品コード
         // 商品コード
         case 'search_product_code':
             $where .= ' AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? AND del_flg = 0)';
             $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key));
             break;
             // 商品名
         // 商品名
         case 'search_name':
             $where .= ' AND name LIKE ?';
             $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key));
             break;
             // カテゴリ
         // カテゴリ
         case 'search_category_id':
             list($tmp_where, $tmp_Values) = $objDb->getCatWhere($objFormParam->getValue($key));
             if ($tmp_where != '') {
                 $where .= ' AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
                 $arrValues = array_merge((array) $arrValues, (array) $tmp_Values);
             }
             break;
             // 種別
         // 種別
         case 'search_status':
             $tmp_where = '';
             foreach ($objFormParam->getValue($key) as $element) {
                 if ($element != '') {
                     if (Utils::isBlank($tmp_where)) {
                         $tmp_where .= ' AND (status = ?';
                     } else {
                         $tmp_where .= ' OR status = ?';
                     }
                     $arrValues[] = $element;
                 }
             }
             if (!Utils::isBlank($tmp_where)) {
                 $tmp_where .= ')';
                 $where .= " {$tmp_where} ";
             }
             break;
             // 登録・更新日(開始)
         // 登録・更新日(開始)
         case 'search_startyear':
             $date = Utils::sfGetTimestamp($objFormParam->getValue('search_startyear'), $objFormParam->getValue('search_startmonth'), $objFormParam->getValue('search_startday'));
             $where .= ' AND update_date >= ?';
             $arrValues[] = $date;
             break;
             // 登録・更新日(終了)
         // 登録・更新日(終了)
         case 'search_endyear':
             $date = Utils::sfGetTimestamp($objFormParam->getValue('search_endyear'), $objFormParam->getValue('search_endmonth'), $objFormParam->getValue('search_endday'), true);
             $where .= ' AND update_date <= ?';
             $arrValues[] = $date;
             break;
             // 商品ステータス
         // 商品ステータス
         case 'search_product_statuses':
             $arrPartVal = $objFormParam->getValue($key);
             $count = count($arrPartVal);
             if ($count >= 1) {
                 $where .= ' ' . 'AND product_id IN (' . '    SELECT product_id FROM dtb_product_status WHERE product_status_id IN (' . Utils::repeatStrWithSeparator('?', $count) . ')' . ')';
                 $arrValues = array_merge($arrValues, $arrPartVal);
             }
             break;
         default:
             break;
     }
 }