Changeset 21564


Ignore:
Timestamp:
2012/03/01 10:06:28 (12 years ago)
Author:
Seasoft
Message:

#1670 (「文字列を区切り文字を挟み反復する」ユーティリティ関数を追加)
#1613 (typo修正・ソース整形・ソースコメントの改善)

Location:
branches/version-2_12-dev/data/class
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/SC_Product.php

    r21527 r21564  
    173173        } 
    174174 
    175         $where = 'alldtl.product_id IN (' . implode(',', array_fill(0, count($arrProductId), '?')) . ')'; 
     175        $where = 'alldtl.product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrProductId)) . ')'; 
    176176        $where .= ' AND alldtl.del_flg = 0'; 
    177177 
     
    410410        } 
    411411        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    412         $where = 'product_id IN (' . implode(', ', array_pad(array(), count($productIds), '?')) . ')'; 
     412        $where = 'product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')'; 
    413413        if (!$has_deleted) { 
    414414            $where .= ' AND T1.del_flg = 0'; 
     
    443443        $cols = 'product_id, product_status_id'; 
    444444        $from = 'dtb_product_status'; 
    445         $where = 'del_flg = 0 AND product_id IN (' . implode(', ', array_pad(array(), count($productIds), '?')) . ')'; 
     445        $where = 'del_flg = 0 AND product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')'; 
    446446        $productStatus = $objQuery->select($cols, $from, $where, $productIds); 
    447447        $results = array(); 
  • branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php

    r21563 r21564  
    853853        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    854854 
    855         $where = "$pid_name IN (" . implode(',', array_fill(0, count($arrPID), '?')) . ")"; 
     855        $where = "$pid_name IN (" . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrPID)) . ')'; 
    856856 
    857857        $return = $objQuery->getCol($id_name, $table, $where, $arrPID); 
     
    921921        $arrRet = SC_Helper_DB_Ex::sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $category_id); 
    922922 
    923         $where = 'category_id IN (' . implode(',', array_fill(0, count($arrRet), '?')) . ')'; 
     923        $where = 'category_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrRet)) . ')'; 
    924924 
    925925        return array($where, $arrRet); 
  • branches/version-2_12-dev/data/class/helper/SC_Helper_Purchase.php

    r21551 r21564  
    496496 
    497497        // 削除されていない支払方法を取得 
    498         $where = 'del_flg = 0 AND payment_id IN (' . implode(', ', array_pad(array(), count($arrPaymentIds), '?')) . ')'; 
     498        $where = 'del_flg = 0 AND payment_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrPaymentIds)) . ')'; 
    499499        $objQuery->setOrder('rank DESC'); 
    500500        $payments = $objQuery->select('payment_id, payment_method, rule, upper_rule, note, payment_image, charge', 'dtb_payment', $where, $arrPaymentIds); 
  • branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products.php

    r21563 r21564  
    282282        $dbFactory = SC_DB_DBFactory_Ex::getInstance(); 
    283283        switch ($key) { 
    284         // 商品ID 
    285         case 'search_product_id': 
    286             $where .= ' AND product_id = ?'; 
    287             $arrValues[] = sprintf('%d', $objFormParam->getValue($key)); 
    288             break; 
    289         // 商品コード 
    290         case 'search_product_code': 
    291             $where .= ' AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? GROUP BY product_id)'; 
    292             $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key)); 
    293             break; 
    294         // 商品名 
    295         case 'search_name': 
    296             $where .= ' AND name LIKE ?'; 
    297             $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key)); 
    298             break; 
    299         // カテゴリ 
    300         case 'search_category_id': 
    301             list($tmp_where, $tmp_Values) = $objDb->sfGetCatWhere($objFormParam->getValue($key)); 
    302             if ($tmp_where != '') { 
    303                 $where.= ' AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')'; 
    304                 $arrValues = array_merge((array)$arrValues, (array)$tmp_Values); 
    305             } 
    306             break; 
    307         // 種別 
    308         case 'search_status': 
    309             $tmp_where = ''; 
    310             foreach ($objFormParam->getValue($key) as $element) { 
    311                 if ($element != '') { 
    312                     if (SC_Utils_Ex::isBlank($tmp_where)) { 
    313                         $tmp_where .= ' AND (status = ?'; 
    314                     } else { 
    315                         $tmp_where .= ' OR status = ?'; 
     284            // 商品ID 
     285            case 'search_product_id': 
     286                $where .= ' AND product_id = ?'; 
     287                $arrValues[] = sprintf('%d', $objFormParam->getValue($key)); 
     288                break; 
     289            // 商品コード 
     290            case 'search_product_code': 
     291                $where .= ' AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? GROUP BY product_id)'; 
     292                $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key)); 
     293                break; 
     294            // 商品名 
     295            case 'search_name': 
     296                $where .= ' AND name LIKE ?'; 
     297                $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key)); 
     298                break; 
     299            // カテゴリ 
     300            case 'search_category_id': 
     301                list($tmp_where, $tmp_Values) = $objDb->sfGetCatWhere($objFormParam->getValue($key)); 
     302                if ($tmp_where != '') { 
     303                    $where.= ' AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')'; 
     304                    $arrValues = array_merge((array)$arrValues, (array)$tmp_Values); 
     305                } 
     306                break; 
     307            // 種別 
     308            case 'search_status': 
     309                $tmp_where = ''; 
     310                foreach ($objFormParam->getValue($key) as $element) { 
     311                    if ($element != '') { 
     312                        if (SC_Utils_Ex::isBlank($tmp_where)) { 
     313                            $tmp_where .= ' AND (status = ?'; 
     314                        } else { 
     315                            $tmp_where .= ' OR status = ?'; 
     316                        } 
     317                        $arrValues[] = $element; 
    316318                    } 
    317                     $arrValues[] = $element; 
    318                 } 
    319             } 
    320  
    321             if (!SC_Utils_Ex::isBlank($tmp_where)) { 
    322                 $tmp_where .= ')'; 
    323                 $where .= " $tmp_where "; 
    324             } 
    325             break; 
    326         // 登録・更新日(開始) 
    327         case 'search_startyear': 
    328             $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_startyear'), 
    329                                                 $objFormParam->getValue('search_startmonth'), 
    330                                                 $objFormParam->getValue('search_startday')); 
    331             $where.= ' AND update_date >= ?'; 
    332             $arrValues[] = $date; 
    333             break; 
    334         // 登録・更新日(終了) 
    335         case 'search_endyear': 
    336             $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_endyear'), 
    337                                                 $objFormParam->getValue('search_endmonth'), 
    338                                                 $objFormParam->getValue('search_endday'), true); 
    339             $where.= ' AND update_date <= ?'; 
    340             $arrValues[] = $date; 
    341             break; 
    342         // 商品ステータス 
    343         case 'search_product_statuses': 
    344             if (count($objFormParam->getValue($key)) > 0) { 
    345                 $where .= ' AND product_id IN (SELECT product_id FROM dtb_product_status WHERE product_status_id IN ('; 
    346                 foreach ($objFormParam->getValue($key) as $param) { 
    347                     $where .= '?,'; 
    348                     $arrValues[] = $param; 
    349                 } 
    350                 $where = preg_replace("/,$/", "))", $where); 
    351             } 
    352             break; 
     319                } 
     320 
     321                if (!SC_Utils_Ex::isBlank($tmp_where)) { 
     322                    $tmp_where .= ')'; 
     323                    $where .= " $tmp_where "; 
     324                } 
     325                break; 
     326            // 登録・更新日(開始) 
     327            case 'search_startyear': 
     328                $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_startyear'), 
     329                                                    $objFormParam->getValue('search_startmonth'), 
     330                                                    $objFormParam->getValue('search_startday')); 
     331                $where.= ' AND update_date >= ?'; 
     332                $arrValues[] = $date; 
     333                break; 
     334            // 登録・更新日(終了) 
     335            case 'search_endyear': 
     336                $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_endyear'), 
     337                                                    $objFormParam->getValue('search_endmonth'), 
     338                                                    $objFormParam->getValue('search_endday'), true); 
     339                $where.= ' AND update_date <= ?'; 
     340                $arrValues[] = $date; 
     341                break; 
     342            // 商品ステータス 
     343            case 'search_product_statuses': 
     344                $arrPartVal = $objFormParam->getValue($key); 
     345                $count = count($arrPartVal); 
     346                if ($count >= 1) { 
     347                    $where .= ' ' 
     348                        . 'AND product_id IN (' 
     349                        . '    SELECT product_id FROM dtb_product_status WHERE product_status_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', $count) . ')' 
     350                        . ')'; 
     351                    $arrValues = array_merge($arrValues, $arrPartVal); 
     352                } 
     353                break; 
     354            default: 
     355                break; 
    353356        } 
    354357    } 
  • branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products_UploadCSV.php

    r21563 r21564  
    785785        } 
    786786        $count = count($arrItems); 
    787         $where = $tblkey .' IN (' . implode(',', array_fill(0, $count, '?')) . ')'; 
     787        $where = $tblkey .' IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', $count) . ')'; 
    788788 
    789789        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
  • branches/version-2_12-dev/data/class/util/SC_Utils.php

    r21563 r21564  
    21922192    /** 
    21932193     * 指定されたパスの配下を再帰的にコピーします. 
    2194      * @param string $imageDir コピー元ディレクトリのパス  
    2195      * @param string $destDir コピー先ディレクトリのパス  
     2194     * @param string $imageDir コピー元ディレクトリのパス 
     2195     * @param string $destDir コピー先ディレクトリのパス 
     2196     * @return void 
    21962197     */ 
    21972198    function copyDirectory($source_path, $dest_path) { 
     
    21992200        $handle=opendir($source_path);   
    22002201        while ($filename = readdir($handle)) { 
    2201             if($filename === '.' || $filename === '..') continue; 
     2202            if ($filename === '.' || $filename === '..') continue; 
    22022203            $cur_path = $source_path . $filename; 
    22032204            $dest_file_path = $dest_path . $filename; 
     
    22052206                // ディレクトリの場合 
    22062207                // コピー先に無いディレクトリの場合、ディレクトリ作成. 
    2207                 if(!empty($filename) && !file_exists($dest_file_path)) mkdir($dest_file_path); 
     2208                if (!empty($filename) && !file_exists($dest_file_path)) mkdir($dest_file_path); 
    22082209                SC_Utils_EX::copyDirectory($cur_path . '/', $dest_file_path . '/'); 
    22092210            } else { 
    2210                 if(file_exists($dest_file_path)) unlink($dest_file_path); 
     2211                if (file_exists($dest_file_path)) unlink($dest_file_path); 
    22112212                copy($cur_path, $dest_file_path); 
    22122213            } 
     
    22142215    } 
    22152216 
     2217    /** 
     2218     * 文字列を区切り文字を挟み反復する 
     2219     * @param string $input 繰り返す文字列。 
     2220     * @param string $multiplier input を繰り返す回数。 
     2221     * @param string $separator 区切り文字 
     2222     * @return string 
     2223     */ 
     2224    function repeatStrWithSeparator($input, $multiplier, $separator = ',') { 
     2225        return implode($separator, array_fill(0, $multiplier, $input)); 
     2226    } 
    22162227} 
Note: See TracChangeset for help on using the changeset viewer.