Changeset 20272
- Timestamp:
- 2011/02/20 22:23:52 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/class/pages/admin/order/LC_Page_Admin_Order_ProductSelect.php
r20213 r20272 64 64 } 65 65 66 66 67 /** 67 68 * Page のアクション. … … 75 76 // 認証可否の判定 76 77 SC_Utils_Ex::sfIsSuccess($objSess); 77 78 if ($_GET['no'] != '') {79 $this->tpl_no = strval($_GET['no']);80 } elseif ($_POST['no'] != '') {81 $this->tpl_no = strval($_POST['no']); 82 }78 $objFormParam = new SC_FormParam(); 79 $this->lfInitParam($objFormParam); 80 $objFormParam->setParam($_POST); 81 $objFormParam->convParam(); 82 83 $this->tpl_no = $this->getNo(array($_GET,$_POST)); 83 84 84 85 switch ($this->getMode()) { 85 86 case 'search': 87 $objProduct = new SC_Product(); 86 88 // 入力文字の強制変換とPOST値の引き継ぎ 87 SC_FormParam::convParam(); 88 $this->arrForm = $this->lfConvertParam($_POST,$this->getConvertRule()); 89 90 $where = "alldtl.del_flg = 0"; 91 $arrval = array(); 92 93 /* 入力エラーなし */ 94 foreach ($this->arrForm as $key => $val) { 95 if($val == "") { 96 continue; 97 } 98 99 switch ($key) { 100 case 'search_name': 101 $where .= " AND name ILIKE ?"; 102 $arrval[] = "%$val%"; 103 break; 104 case 'search_category_id': 105 list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($val); 106 if($tmp_where != "") { 107 $where.= " AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")"; 108 $arrval = array_merge((array)$arrval, (array)$tmp_arrval); 109 } 110 break; 111 case 'search_product_code': 112 $where .= " AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)"; 113 $arrval[] = "$val%"; 114 break; 115 default: 116 break; 117 } 118 } 119 120 // 検索結果対象となる商品の数を取得 121 $objQuery =& SC_Query::getSingletonInstance(); 122 $objQuery->setWhere($where); 123 $objProduct = new SC_Product(); 124 $linemax = $objProduct->findProductCount($objQuery, $arrval); 125 $this->tpl_linemax = $linemax; // 何件が該当しました。表示用 126 89 // $this->arrForm = $this->lfConvertParam($_POST,$this->getConvertRule()); 90 $this->arrForm = $objFormParam->getHashArray(); 91 $wheres = $this->createWhere($objFormParam,$objDb); 92 $this->tpl_linemax = $this->getLineCount($wheres,$objProduct); 93 94 //ぶった斬りポイント================================================================== 127 95 // ページ送りの処理 128 96 if(isset($_POST['search_page_max']) … … 137 105 $this->tpl_strnavi = $objNavi->strnavi; // 表示文字列 138 106 $startno = $objNavi->start_row; 139 140 $objProduct = new SC_Product(); 141 $objQuery =& SC_Query::getSingletonInstance(); 142 $objQuery->setWhere($where); 143 144 // 取得範囲の指定(開始行番号、行数のセット) 145 $objQuery->setLimitOffset($page_max, $startno); 146 // 表示順序 147 $objQuery->setOrder($order); 148 149 // 検索結果の取得 150 $arrProduct_id = $objProduct->findProductIdsOrder($objQuery, $arrval); 151 152 $where = ""; 153 if (is_array($arrProduct_id) && !empty($arrProduct_id)) { 154 $where = 'product_id IN (' . implode(',', $arrProduct_id) . ')'; 155 } else { 156 // 一致させない 157 $where = '0<>0'; 158 } 159 $objQuery =& SC_Query::getSingletonInstance(); 160 $objQuery->setWhere($where); 161 $arrProducts = $objProduct->lists($objQuery, $arrProduct_id); 162 107 //ぶった斬りポイント================================================================== 108 $arrProduct_id = $this->getProducts($wheres, $objProduct); 109 //ぶった斬りポイント================================================================== 110 $productList = $this->getProductList($arrProduct_id,$objProduct); 111 //ぶった斬りポイント================================================================== 163 112 //取得している並び順で並び替え 164 $arrProducts2 = array(); 165 foreach($arrProducts as $item) { 166 $arrProducts2[ $item['product_id'] ] = $item; 167 } 168 $this->arrProducts = array(); 169 foreach($arrProduct_id as $product_id) { 170 $this->arrProducts[] = $arrProducts2[$product_id]; 171 } 172 113 $this->arrProducts = $this->sortProducts($arrProduct_id,$productList); 114 //ぶった斬りポイント================================================================== 173 115 $objProduct->setProductsClassByProductIds($arrProduct_id); 174 $objJson = new Services_JSON(); 175 $this->tpl_javascript .= 'productsClassCategories = ' . $objJson->encode($objProduct->classCategories) . '; '; 176 177 foreach ($this->arrProducts as $arrProduct) { 178 $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});\n"; 179 } 180 116 //ぶった斬りポイント================================================================== 117 $this->tpl_javascript .= $this->getTplJavascript($objProduct); 118 //ぶった斬りポイント================================================================== 119 $js_fnOnLoad = $this->getFnOnload($this->arrProducts); 120 //ぶった斬りポイント================================================================== 181 121 $this->tpl_javascript .= 'function fnOnLoad(){' . $js_fnOnLoad . '}'; 182 122 $this->tpl_onload .= 'fnOnLoad(); '; 183 184 123 // 規格1クラス名 185 124 $this->tpl_class_name1 = $objProduct->className1; 186 187 125 // 規格2クラス名 188 126 $this->tpl_class_name2 = $objProduct->className2; 189 190 127 // 規格1 191 128 $this->arrClassCat1 = $objProduct->classCats1; 192 193 129 // 規格1が設定されている 194 130 $this->tpl_classcat_find1 = $objProduct->classCat1_find; … … 206 142 $this->setTemplate($this->tpl_mainpage); 207 143 } 144 145 function getProductList($arrProduct_id,&$objProduct){ 146 $where = ""; 147 if (is_array($arrProduct_id) && !empty($arrProduct_id)) { 148 $where = 'product_id IN (' . implode(',', $arrProduct_id) . ')'; 149 } else { 150 // 一致させない 151 $where = '0<>0'; 152 } 153 $objQuery =& SC_Query::getSingletonInstance(); 154 $objQuery->setWhere($where); 155 return $objProduct->lists($objQuery, $arrProduct_id); 156 } 157 158 159 function getFnOnload($arrProducts){ 160 foreach ($arrProducts as $arrProduct) { 161 $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});\n"; 162 } 163 } 164 165 function getTplJavascript(&$objProduct){ 166 $objJson = new Services_JSON(); 167 return 'productsClassCategories = ' . $objJson->encode($objProduct->classCategories) . '; '; 168 } 169 170 171 /** 172 * 検索結果の取得 173 * @param array $whereAndBind string whereと array bindの連想配列 174 * @param SC_Product $objProduct 175 */ 176 function getProducts($whereAndBind,&$objProduct){ 177 $where = $whereAndBind['where']; 178 $bind = $whereAndBind['bind']; 179 $objQuery =& SC_Query::getSingletonInstance(); 180 $objQuery->setWhere($where); 181 // 取得範囲の指定(開始行番号、行数のセット) 182 $objQuery->setLimitOffset($page_max, $startno); 183 // 表示順序 184 $objQuery->setOrder($order); 185 186 // 検索結果の取得 187 return $objProduct->findProductIdsOrder($objQuery, $bind); 188 } 189 190 /** 191 * 192 * Enter description here ... 193 * @param unknown_type $whereAndBind 194 * @param unknown_type $objProduct 195 */ 196 function getLineCount($whereAndBind,&$objProduct){ 197 $where = $whereAndBind['where']; 198 $bind = $whereAndBind['bind']; 199 // 検索結果対象となる商品の数を取得 200 $objQuery =& SC_Query::getSingletonInstance(); 201 $objQuery->setWhere($where); 202 $linemax = $objProduct->findProductCount($objQuery, $bind); 203 return $linemax; // 何件が該当しました。表示用 204 } 205 206 207 /** 208 * 209 * POSTされた値からSQLのWHEREとBINDを配列で返す。 210 * @return array ('where' => where string, 'bind' => databind array) 211 * @param SC_FormParam $objFormParam 212 */ 213 function createWhere(&$objFormParam,&$objDb){ 214 $arrForm = $objFormParam->getHashArray(); 215 $where = "alldtl.del_flg = 0"; 216 $bind = array(); 217 foreach ($arrForm as $key => $val) { 218 if($val == "") { 219 continue; 220 } 221 222 switch ($key) { 223 case 'search_name': 224 $where .= " AND name ILIKE ?"; 225 $bind[] = "%".$val."%"; 226 break; 227 case 'search_category_id': 228 list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val); 229 if($tmp_where != "") { 230 $where.= " AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")"; 231 $bind = array_merge((array)$bind, (array)$tmp_bind); 232 } 233 break; 234 case 'search_product_code': 235 $where .= " AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)"; 236 // $arrval[] = "$val%"; 237 $bind[] = '%'.$val.'%'; 238 break; 239 240 default: 241 break; 242 } 243 } 244 return array( 245 'where'=>$where, 246 'bind' => $bind 247 ); 248 } 249 250 251 /** 252 * リクエストパラメータnoを取ってくる。 253 * @param unknown_type $globalParams 254 */ 255 function getNo($globalParams){ 256 foreach ($globalParams as $params){ 257 if(isset($params['no']) && $params['no']!= ''){ 258 return strval($params['no']); 259 } 260 } 261 return null; 262 } 263 264 /** 265 * 取得している並び順で並び替え 266 * @param $arrProduct_id 267 * @param $productList 268 */ 269 function sortProducts($arrProduct_id,$productList){ 270 $products = array(); 271 foreach($productList as $item) { 272 $products[ $item['product_id'] ] = $item; 273 } 274 $arrProducts = array(); 275 foreach($arrProduct_id as $product_id) { 276 $arrProducts[] = $products[$product_id]; 277 } 278 return $arrProducts; 279 } 280 208 281 209 282 /** … … 232 305 return $arrConvList; 233 306 } 307 /** 308 * パラメータ情報の初期化 309 * @param SC_FormParam $objFormParam 310 */ 311 function lfInitParam(&$objFormParam) { 312 $objFormParam->addParam("オーダーID", "order_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); 313 $objFormParam->addParam("商品名", "search_name", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK")); 314 $objFormParam->addParam("カテゴリID", "search_category_id", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK", "SPTAB_CHECK")); 315 $objFormParam->addParam("商品コード", "search_product_code", LTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK", "SPTAB_CHECK")); 316 $objFormParam->addParam("フッター", "footer", LTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK", "SPTAB_CHECK")); 317 } 234 318 235 319 /**
Note: See TracChangeset
for help on using the changeset viewer.