/** * @param DbHelper $objDb */ public function lfGetProducts(&$objDb) { $where = 'del_flg = 0'; $arrWhereVal = array(); /* 入力エラーなし */ foreach ($this->arrForm as $key => $val) { if ($val == '') { continue; } switch ($key) { case 'search_name': $where .= ' AND name ILIKE ?'; $arrWhereVal[] = "%{$val}%"; break; case 'search_category_id': list($tmp_where, $arrTmp) = $objDb->getCatWhere($val); if ($tmp_where != '') { $where .= ' AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')'; $arrWhereVal = array_merge((array) $arrWhereVal, (array) $arrTmp); } break; case 'search_product_code': $where .= ' AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ?)'; $arrWhereVal[] = "{$val}%"; break; default: break; } } $order = 'update_date DESC, product_id DESC '; $objQuery = Application::alias('eccube.query'); // 行数の取得 $linemax = $objQuery->count('dtb_products', $where, $arrWhereVal); $this->tpl_linemax = $linemax; // 何件が該当しました。表示用 // ページ送りの処理 $page_max = Utils::sfGetSearchPageMax($_POST['search_page_max']); // ページ送りの取得 /* @var $objNavi PageNavi */ $objNavi = Application::alias('eccube.page_navi', $_POST['search_pageno'], $linemax, $page_max, 'eccube.moveSearchPage', NAVI_PMAX); $this->tpl_strnavi = $objNavi->strnavi; // 表示文字列 $startno = $objNavi->start_row; // 取得範囲の指定(開始行番号、行数のセット) $objQuery->setLimitOffset($page_max, $startno); // 表示順序 $objQuery->setOrder($order); // 検索結果の取得 // FIXME 商品コードの表示 $arrProducts = $objQuery->select('*', Application::alias('eccube.product')->alldtlSQL(), $where, $arrWhereVal); return $arrProducts; }
/** * * POSTされた値からSQLのWHEREとBINDを配列で返す。 * @return array ('where' => where string, 'bind' => databind array) * @param FormParam $objFormParam * @param DbHelper $objDb */ public function createWhere(&$objFormParam, &$objDb) { $arrForm = $objFormParam->getHashArray(); $where = 'alldtl.del_flg = 0'; $bind = array(); foreach ($arrForm as $key => $val) { if ($val == '') { continue; } switch ($key) { case 'search_name': $where .= ' AND name ILIKE ?'; $bind[] = '%' . $val . '%'; break; case 'search_category_id': list($tmp_where, $tmp_bind) = $objDb->getCatWhere($val); if ($tmp_where != '') { $where .= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')'; $bind = array_merge((array) $bind, (array) $tmp_bind); } break; case 'search_product_code': $where .= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)'; $bind[] = '%' . $val . '%'; break; case 'search_status': $where .= ' AND alldtl.status = ?'; $bind[] = $val; break; default: break; } } return array('where' => $where, 'bind' => $bind); }