[Svn-src-all:2665] [version-2_12-dev 21564] #1670 (「文字列を区切り文字を挟み反復する」ユーティリティ関数を追加)

Seasoft admin @ mail.ec-cube.net
2012年 3月 1日 (木) 10:06:29 JST


Subversion committed to /home/svn/open 21564
http://svn.ec-cube.net/open_trac/changeset/21564
┌────────────────────────────┐
│更新者 :  Seasoft                                      │
│更新日時:  2012-03-01 10:06:28 +0900 (木, 01  3月 2012)│
└────────────────────────────┘

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

Changed:                      [U:修正,A:追加,D:削除]
--------------------------------------------------------
U   branches/version-2_12-dev/data/class/SC_Product.php
U   branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php
U   branches/version-2_12-dev/data/class/helper/SC_Helper_Purchase.php
U   branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products.php
U   branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products_UploadCSV.php
U   branches/version-2_12-dev/data/class/util/SC_Utils.php

変更: branches/version-2_12-dev/data/class/SC_Product.php
===================================================================
--- branches/version-2_12-dev/data/class/SC_Product.php	2012-02-28 13:35:14 UTC (rev 21563)
+++ branches/version-2_12-dev/data/class/SC_Product.php	2012-03-01 01:06:28 UTC (rev 21564)
@@ -172,7 +172,7 @@
             return array();
         }
 
-        $where = 'alldtl.product_id IN (' . implode(',', array_fill(0, count($arrProductId), '?')) . ')';
+        $where = 'alldtl.product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrProductId)) . ')';
         $where .= ' AND alldtl.del_flg = 0';
 
         $objQuery->setWhere($where, $arrProductId);
@@ -409,7 +409,7 @@
             return array();
         }
         $objQuery =& SC_Query_Ex::getSingletonInstance();
-        $where = 'product_id IN (' . implode(', ', array_pad(array(), count($productIds), '?')) . ')';
+        $where = 'product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')';
         if (!$has_deleted) {
             $where .= ' AND T1.del_flg = 0';
         }
@@ -442,7 +442,7 @@
         $objQuery =& SC_Query_Ex::getSingletonInstance();
         $cols = 'product_id, product_status_id';
         $from = 'dtb_product_status';
-        $where = 'del_flg = 0 AND product_id IN (' . implode(', ', array_pad(array(), count($productIds), '?')) . ')';
+        $where = 'del_flg = 0 AND product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')';
         $productStatus = $objQuery->select($cols, $from, $where, $productIds);
         $results = array();
         foreach ($productStatus as $status) {

変更: branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php
===================================================================
--- branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php	2012-02-28 13:35:14 UTC (rev 21563)
+++ branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php	2012-03-01 01:06:28 UTC (rev 21564)
@@ -852,7 +852,7 @@
     function sfGetChildrenArraySub($table, $pid_name, $id_name, $arrPID) {
         $objQuery =& SC_Query_Ex::getSingletonInstance();
 
-        $where = "$pid_name IN (" . implode(',', array_fill(0, count($arrPID), '?')) . ")";
+        $where = "$pid_name IN (" . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrPID)) . ')';
 
         $return = $objQuery->getCol($id_name, $table, $where, $arrPID);
 
@@ -920,7 +920,7 @@
         // 子カテゴリIDの取得
         $arrRet = SC_Helper_DB_Ex::sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $category_id);
 
-        $where = 'category_id IN (' . implode(',', array_fill(0, count($arrRet), '?')) . ')';
+        $where = 'category_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrRet)) . ')';
 
         return array($where, $arrRet);
     }

変更: branches/version-2_12-dev/data/class/helper/SC_Helper_Purchase.php
===================================================================
--- branches/version-2_12-dev/data/class/helper/SC_Helper_Purchase.php	2012-02-28 13:35:14 UTC (rev 21563)
+++ branches/version-2_12-dev/data/class/helper/SC_Helper_Purchase.php	2012-03-01 01:06:28 UTC (rev 21564)
@@ -495,7 +495,7 @@
         $objQuery =& SC_Query_Ex::getSingletonInstance();
 
         // 削除されていない支払方法を取得
-        $where = 'del_flg = 0 AND payment_id IN (' . implode(', ', array_pad(array(), count($arrPaymentIds), '?')) . ')';
+        $where = 'del_flg = 0 AND payment_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrPaymentIds)) . ')';
         $objQuery->setOrder('rank DESC');
         $payments = $objQuery->select('payment_id, payment_method, rule, upper_rule, note, payment_image, charge', 'dtb_payment', $where, $arrPaymentIds);
         foreach ($payments as $data) {

変更: branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products.php
===================================================================
--- branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products.php	2012-02-28 13:35:14 UTC (rev 21563)
+++ branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products.php	2012-03-01 01:06:28 UTC (rev 21564)
@@ -281,75 +281,78 @@
     function buildQuery($key, &$where, &$arrValues, &$objFormParam, &$objDb) {
         $dbFactory = SC_DB_DBFactory_Ex::getInstance();
         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 ? GROUP BY product_id)';
-            $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->sfGetCatWhere($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 (SC_Utils_Ex::isBlank($tmp_where)) {
-                        $tmp_where .= ' AND (status = ?';
-                    } else {
-                        $tmp_where .= ' OR status = ?';
+            // 商品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 ? GROUP BY product_id)';
+                $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->sfGetCatWhere($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 (SC_Utils_Ex::isBlank($tmp_where)) {
+                            $tmp_where .= ' AND (status = ?';
+                        } else {
+                            $tmp_where .= ' OR status = ?';
+                        }
+                        $arrValues[] = $element;
                     }
-                    $arrValues[] = $element;
                 }
-            }
 
-            if (!SC_Utils_Ex::isBlank($tmp_where)) {
-                $tmp_where .= ')';
-                $where .= " $tmp_where ";
-            }
-            break;
-        // 登録・更新日(開始)
-        case 'search_startyear':
-            $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_startyear'),
-                                                $objFormParam->getValue('search_startmonth'),
-                                                $objFormParam->getValue('search_startday'));
-            $where.= ' AND update_date >= ?';
-            $arrValues[] = $date;
-            break;
-        // 登録・更新日(終了)
-        case 'search_endyear':
-            $date = SC_Utils_Ex::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':
-            if (count($objFormParam->getValue($key)) > 0) {
-                $where .= ' AND product_id IN (SELECT product_id FROM dtb_product_status WHERE product_status_id IN (';
-                foreach ($objFormParam->getValue($key) as $param) {
-                    $where .= '?,';
-                    $arrValues[] = $param;
+                if (!SC_Utils_Ex::isBlank($tmp_where)) {
+                    $tmp_where .= ')';
+                    $where .= " $tmp_where ";
                 }
-                $where = preg_replace("/,$/", "))", $where);
-            }
-            break;
+                break;
+            // 登録・更新日(開始)
+            case 'search_startyear':
+                $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_startyear'),
+                                                    $objFormParam->getValue('search_startmonth'),
+                                                    $objFormParam->getValue('search_startday'));
+                $where.= ' AND update_date >= ?';
+                $arrValues[] = $date;
+                break;
+            // 登録・更新日(終了)
+            case 'search_endyear':
+                $date = SC_Utils_Ex::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 (' . SC_Utils_Ex::repeatStrWithSeparator('?', $count) . ')'
+                        . ')';
+                    $arrValues = array_merge($arrValues, $arrPartVal);
+                }
+                break;
+            default:
+                break;
         }
     }
 

変更: branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products_UploadCSV.php
===================================================================
--- branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products_UploadCSV.php	2012-02-28 13:35:14 UTC (rev 21563)
+++ branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products_UploadCSV.php	2012-03-01 01:06:28 UTC (rev 21564)
@@ -784,7 +784,7 @@
             return false;
         }
         $count = count($arrItems);
-        $where = $tblkey .' IN (' . implode(',', array_fill(0, $count, '?')) . ')';
+        $where = $tblkey .' IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', $count) . ')';
 
         $objQuery =& SC_Query_Ex::getSingletonInstance();
         $db_count = $objQuery->count($table, $where, $arrItems);

変更: branches/version-2_12-dev/data/class/util/SC_Utils.php
===================================================================
--- branches/version-2_12-dev/data/class/util/SC_Utils.php	2012-02-28 13:35:14 UTC (rev 21563)
+++ branches/version-2_12-dev/data/class/util/SC_Utils.php	2012-03-01 01:06:28 UTC (rev 21564)
@@ -2191,26 +2191,37 @@
 
     /**
      * 指定されたパスの配下を再帰的にコピーします.
-     * @param string $imageDir コピー元ディレクトリのパス 
-     * @param string $destDir コピー先ディレクトリのパス 
+     * @param string $imageDir コピー元ディレクトリのパス
+     * @param string $destDir コピー先ディレクトリのパス
+     * @return void
      */
     function copyDirectory($source_path, $dest_path) {
 
         $handle=opendir($source_path);  
         while ($filename = readdir($handle)) {
-            if($filename === '.' || $filename === '..') continue;
+            if ($filename === '.' || $filename === '..') continue;
             $cur_path = $source_path . $filename;
             $dest_file_path = $dest_path . $filename;
             if (is_dir($cur_path)) {
                 // ディレクトリの場合
                 // コピー先に無いディレクトリの場合、ディレクトリ作成.
-                if(!empty($filename) && !file_exists($dest_file_path)) mkdir($dest_file_path);
+                if (!empty($filename) && !file_exists($dest_file_path)) mkdir($dest_file_path);
                 SC_Utils_EX::copyDirectory($cur_path . '/', $dest_file_path . '/');
             } else {
-                if(file_exists($dest_file_path)) unlink($dest_file_path);
+                if (file_exists($dest_file_path)) unlink($dest_file_path);
                 copy($cur_path, $dest_file_path);
             }
         }
     }
 
+    /**
+     * 文字列を区切り文字を挟み反復する
+     * @param string $input 繰り返す文字列。
+     * @param string $multiplier input を繰り返す回数。
+     * @param string $separator 区切り文字
+     * @return string
+     */
+    function repeatStrWithSeparator($input, $multiplier, $separator = ',') {
+        return implode($separator, array_fill(0, $multiplier, $input));
+    }
 }




Svn-src-all メーリングリストの案内