[Svn-src-all:1266] [version-2_5-dev 20155] リファクタリング

kimoto admin @ mail.ec-cube.net
2011年 2月 12日 (土) 14:44:11 JST


Subversion committed to /home/svn/open 20155
http://svn.ec-cube.net/open_trac/changeset/20155
┌────────────────────────────┐
│更新者 :  kimoto                                       │
│更新日時:  2011-02-12 14:44:10 +0900 (土, 12  2月 2011)│
└────────────────────────────┘

Log:
--------------------------------------------------------
リファクタリング
*SC_PageNaviの改善 eregの除去 携帯/PC両方で使えるようにパラメーターの追加 htmlspecialcharsを内部でやるように追記 all_rowを返せるように追記


Changed:                      [U:修正,A:追加,D:削除]
--------------------------------------------------------
U   branches/version-2_5-dev/data/Smarty/templates/default/mypage/index.tpl
U   branches/version-2_5-dev/data/Smarty/templates/mobile/mypage/index.tpl
U   branches/version-2_5-dev/data/Smarty/templates/sphone/mypage/index.tpl
U   branches/version-2_5-dev/data/class/SC_PageNavi.php
U   branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage.php

変更: branches/version-2_5-dev/data/Smarty/templates/default/mypage/index.tpl
===================================================================
--- branches/version-2_5-dev/data/Smarty/templates/default/mypage/index.tpl	2011-02-12 03:25:53 UTC (rev 20154)
+++ branches/version-2_5-dev/data/Smarty/templates/default/mypage/index.tpl	2011-02-12 05:44:10 UTC (rev 20155)
@@ -32,15 +32,15 @@
   <div id="mycontentsarea">
     <form name="form1" method="post" action="?">
     <input type="hidden" name="order_id" value="" />
-    <input type="hidden" name="pageno" value="<!--{$tpl_pageno}-->" />
+    <input type="hidden" name="pageno" value="<!--{$objNavi->nowpage}-->" />
     <h3><!--{$tpl_subtitle|h}--></h3>
 
-<!--{if $tpl_linemax > 0}-->
+<!--{if $objNavi->all_row > 0}-->
 
-    <p><!--{$tpl_linemax}-->件の購入履歴があります。</p>
+    <p><!--{$objNavi->all_row}-->件の購入履歴があります。</p>
     <div>
       <!--▼ページナビ-->
-      <!--{$tpl_strnavi}-->
+      <!--{$objNavi->strnavi}-->
       <!--▲ページナビ-->
     </div>
 

変更: branches/version-2_5-dev/data/Smarty/templates/mobile/mypage/index.tpl
===================================================================
--- branches/version-2_5-dev/data/Smarty/templates/mobile/mypage/index.tpl	2011-02-12 03:25:53 UTC (rev 20154)
+++ branches/version-2_5-dev/data/Smarty/templates/mobile/mypage/index.tpl	2011-02-12 05:44:10 UTC (rev 20155)
@@ -34,8 +34,8 @@
 <a href="refusal.php" accesskey="3"><!--{3|numeric_emoji}-->退会</a><br>
 <hr>
 ■購入履歴一覧<br>
-<!--{if $tpl_linemax > 0}-->
-    <!--{$tpl_linemax}-->件の購入履歴があります。<br>
+<!--{if $objNavi->all_row > 0}-->
+    <!--{$objNavi->all_row}-->件の購入履歴があります。<br>
     <!--{section name=cnt loop=$arrOrder}-->
     <hr>
         ●購入日時<br>
@@ -54,7 +54,7 @@
     購入履歴はありません。<br>
 <!--{/if}-->
 
-<!--{if $tpl_strnavi != ""}-->
-<!--{$tpl_strnavi}-->
+<!--{if $objNavi->strnavi != ""}-->
+<!--{$objNavi->strnavi}-->
 <br>
 <!--{/if}-->

変更: branches/version-2_5-dev/data/Smarty/templates/sphone/mypage/index.tpl
===================================================================
--- branches/version-2_5-dev/data/Smarty/templates/sphone/mypage/index.tpl	2011-02-12 03:25:53 UTC (rev 20154)
+++ branches/version-2_5-dev/data/Smarty/templates/sphone/mypage/index.tpl	2011-02-12 05:44:10 UTC (rev 20155)
@@ -32,15 +32,15 @@
   <div id="mycontentsarea">
     <form name="form1" method="post" action="?">
     <input type="hidden" name="order_id" value="" />
-    <input type="hidden" name="pageno" value="<!--{$tpl_pageno}-->" />
+    <input type="hidden" name="pageno" value="<!--{$objNavi->nowpage}-->" />
     <h3><!--{$tpl_subtitle|h}--></h3>
 
-<!--{if $tpl_linemax > 0}-->
+<!--{if $objNavi->all_row > 0}-->
 
-    <p><!--{$tpl_linemax}-->件の購入履歴があります。</p>
+    <p><!--{$objNavi->all_row}-->件の購入履歴があります。</p>
     <div>
       <!--▼ページナビ-->
-      <!--{$tpl_strnavi}-->
+      <!--{$objNavi->all_row}-->
       <!--▲ページナビ-->
     </div>
 

変更: branches/version-2_5-dev/data/class/SC_PageNavi.php
===================================================================
--- branches/version-2_5-dev/data/class/SC_PageNavi.php	2011-02-12 03:25:53 UTC (rev 20154)
+++ branches/version-2_5-dev/data/class/SC_PageNavi.php	2011-02-12 05:44:10 UTC (rev 20155)
@@ -41,14 +41,14 @@
     var $arrPagenavi = array(); // ページ
 
     // コンストラクタ
-    function SC_PageNavi($now_page, $all_row, $page_row, $func_name, $navi_max = NAVI_PMAX, $urlParam = '') {
+    function SC_PageNavi($now_page, $all_row, $page_row, $func_name, $navi_max = NAVI_PMAX, $urlParam = '', $display_number = true) {
         $this->arrPagenavi['mode'] = 'search';
 
         //現在ページ($now_page)が正しい数値でない場合
-        if (!eregi("^[[:digit:]]+$", $now_page) || $now_page < 1 || strlen($now_page) == 0) {
+        if (!preg_match("/^[[:digit:]]+$/", $now_page) || $now_page < 1 || strlen($now_page) == 0) {
             $this->now_page = 1;
         } else {
-            $this->now_page = $now_page;
+            $this->now_page = htmlspecialchars($now_page, ENT_QUOTES, CHAR_CODE);
         }
         $this->arrPagenavi['now_page'] = $this->now_page;
 
@@ -60,7 +60,8 @@
             $this->now_page = 1;
         }
 
-        $this->start_row = ($this->now_page - 1) * $page_row;
+        $this->start_row    = ($this->now_page - 1) * $page_row;
+        $this->all_row      = $all_row;
 
         // 開始行が不正な場合
         if (!($this->start_row < $all_row && $this->start_row >= 0)) {
@@ -136,7 +137,7 @@
             }
 
             if ($before || $next) {
-                $this->strnavi = $before .$page_number .$next;
+                $this->strnavi = $before .(($display_number) ? $page_number : ' | ') .$next;
             }
         } else {
             $this->arrPagenavi['arrPageno'][0] = 1;

変更: branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage.php
===================================================================
--- branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage.php	2011-02-12 03:25:53 UTC (rev 20154)
+++ branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage.php	2011-02-12 05:44:10 UTC (rev 20155)
@@ -48,15 +48,12 @@
      */
     function init() {
         parent::init();
-        $this->tpl_title        = 'MYページ';
-        if (Net_UserAgent_Mobile::isMobile() === true){
+        $this->tpl_mypageno = 'index';
+        if (SC_Display::detectDevice() === DEVICE_TYPE_MOBILE){
             $this->tpl_subtitle = 'MYページ';
         } else {
             $this->tpl_subtitle = '購入履歴一覧';
         }
-        $this->tpl_navi         = TEMPLATE_REALDIR . 'mypage/navi.tpl';
-        $this->tpl_mainno       = 'mypage';
-        $this->tpl_mypageno     = 'index';
         $this->httpCacheControl('nocache');
     }
 
@@ -76,83 +73,60 @@
      */
     function action() {
 
-        $objQuery = new SC_Query();
         $objCustomer = new SC_Customer();
+        $customer_id = $objCustomer->getvalue('customer_id');
 
         //ページ送り用
-        if (isset($_POST['pageno'])) {
-            $this->tpl_pageno = htmlspecialchars($_POST['pageno'], ENT_QUOTES, CHAR_CODE);
-        }
+        $this->objNavi = new SC_PageNavi($_REQUEST['pageno'],
+                                         $this->lfGetOrderHistory($customer_id),
+                                         SEARCH_PMAX,
+                                         "fnNaviPage",
+                                         NAVI_PMAX,
+                                         'pageno=#page#',
+                                         SC_Display::detectDevice() !== DEVICE_TYPE_MOBILE);
 
-        $col = "order_id, create_date, payment_id, payment_total";
-        $from = "dtb_order";
-        $where = "del_flg = 0 AND customer_id=?";
-        $arrval = array($objCustomer->getvalue('customer_id'));
-        $order = "order_id DESC";
+        $this->arrOrder = $this->lfGetOrderHistory($customer_id, $this->objNavi->start_row);
 
-        $linemax = $objQuery->count($from, $where, $arrval);
-        $this->tpl_linemax = $linemax;
+        // 支払い方法の取得
+        $this->arrPayment = SC_Helper_DB_Ex::sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
+    }
 
-        if (Net_UserAgent_Mobile::isMobile() === true){
-            define ("HISTORY_NUM", 5);  // TODO
-            $pageNo = isset($_GET['pageno']) ? (int) $_GET['pageno'] : 0; // TODO
+    /**
+     * デストラクタ.
+     *
+     * @return void
+     */
+    function destroy() {
+        parent::destroy();
+    }
 
-            // ページ送りの取得
-            // next
-            if ($pageNo + HISTORY_NUM < $linemax) {
-                $next = "<a href='?pageno=" . ($pageNo + HISTORY_NUM) . "'>次へ→</a>";
-            } else {
-                $next = "";
-            }
 
-            // previous
-            if ($pageNo - HISTORY_NUM > 0) {
-                $previous = "<a href='?pageno=" . ($pageNo - HISTORY_NUM) . "'>←前へ</a>";
-            } elseif ($pageNo == 0) {
-                $previous = "";
-            } else {
-                $previous = "<a href='?pageno=0'>←前へ</a>";
-            }
+    /**
+     * 受注履歴を返す
+     *
+     * @param mixed $customer_id
+     * @param mixed $startno 0以上の場合は受注履歴を返却する -1の場合は件数を返す
+     * @access private
+     * @return void
+     */
+    function lfGetOrderHistory($customer_id, $startno = -1) {
+        $objQuery   = SC_Query::getSingletonInstance();
 
-            // bar
-            if ($next != '' && $previous != '') {
-                $bar = " | ";
-            } else {
-                $bar = "";
-            }
+        $col        = "order_id, create_date, payment_id, payment_total";
+        $from       = "dtb_order";
+        $where      = "del_flg = 0 AND customer_id = ?";
+        $arrval     = array($customer_id);
+        $order      = "order_id DESC";
 
-            $this->tpl_strnavi = $previous . $bar . $next;
-
-            // 取得範囲の指定(開始行番号、行数のセット)
-            $objQuery->setLimitOffset(HISTORY_NUM, $pageNo);
-        } else {
-            // ページ送りの取得
-            $objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, SEARCH_PMAX, "fnNaviPage", NAVI_PMAX);
-            $this->tpl_strnavi = $objNavi->strnavi;		// 表示文字列
-            $startno = $objNavi->start_row;
-
-            // 取得範囲の指定(開始行番号、行数のセット)
-            $objQuery->setLimitOffset(SEARCH_PMAX, $startno);
+        if ($startno == -1) {
+            return $objQuery->count($from, $where, $arrval);
         }
 
+        $objQuery->setLimitOffset(SEARCH_PMAX, $startno);
         // 表示順序
         $objQuery->setOrder($order);
 
         //購入履歴の取得
-        $this->arrOrder = $objQuery->select($col, $from, $where, $arrval);
-
-        // 支払い方法の取得
-        $objDb = new SC_Helper_DB_Ex();
-        $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
-
+        return $objQuery->select($col, $from, $where, $arrval);
     }
-
-    /**
-     * デストラクタ.
-     *
-     * @return void
-     */
-    function destroy() {
-        parent::destroy();
-    }
 }




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