Ignore:
Timestamp:
2011/02/11 18:57:46 (15 years ago)
Author:
kimoto
Message:

LC_Page_Mypage_Favorite リファクタリング

  • SC_Productでページング処理までしたほうがいいのではないか
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage_Favorite.php

    r20116 r20146  
    2323 
    2424// {{{ requires 
    25 require_once(CLASS_REALDIR . "pages/LC_Page.php"); 
     25require_once(CLASS_REALDIR . "pages/mypage/LC_Page_AbstractMypage.php"); 
    2626 
    2727/** 
     
    3232 * @version $Id$ 
    3333 */ 
    34 class LC_Page_MyPage_Favorite extends LC_Page { 
     34class LC_Page_MyPage_Favorite extends LC_Page_AbstractMypage { 
    3535 
    3636    // {{{ properties 
     
    4949    function init() { 
    5050        parent::init(); 
    51         $this->tpl_title = 'MYページ'; 
    5251        $this->tpl_subtitle = 'お気に入り一覧'; 
    53         $this->tpl_navi = TEMPLATE_REALDIR . 'mypage/navi.tpl'; 
    54         $this->tpl_mainno = 'mypage'; 
    5552        $this->tpl_mypageno = 'favorite'; 
    5653    } 
     
    6360    function process() { 
    6461        parent::process(); 
    65         $this->action(); 
    66         $this->sendResponse(); 
    6762    } 
    6863 
     
    7469    function action() { 
    7570 
    76         $objQuery = new SC_Query(); 
    7771        $objCustomer = new SC_Customer(); 
    78  
    79         // 退会判定用情報の取得 
    80         $this->tpl_login = $objCustomer->isLoginSuccess(true); 
    81  
    82         // ログインチェック 
    83         if(!$objCustomer->isLoginSuccess(true)) { 
    84             SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR); 
    85         }else { 
    86             // マイページトップ顧客情報表示用 
    87             $this->CustomerName1 = $objCustomer->getvalue('name01'); 
    88             $this->CustomerName2 = $objCustomer->getvalue('name02'); 
    89             $this->CustomerPoint = $objCustomer->getvalue('point'); 
    90         } 
     72        $customer_id = $objCustomer->getValue('customer_id'); 
    9173 
    9274        switch ($this->getMode()) { 
    9375        case 'delete_favorite': 
    94         // お気に入り削除 
    95             $customer_id = $objCustomer->getValue('customer_id'); 
     76            // お気に入り削除 
    9677            $this->lfDeleteFavoriteProduct($customer_id, $_POST['product_id']); 
    97             break; 
    98         default: 
    9978            break; 
    10079        } 
     
    10483            $this->tpl_pageno = htmlspecialchars($_POST['pageno'], ENT_QUOTES, CHAR_CODE); 
    10584        } 
    106  
    107         // FIXME SC_Product クラスを使用した実装 
    108         $col = "alldtl.*"; 
    109         $from = "dtb_customer_favorite_products AS dcfp LEFT JOIN vw_products_allclass_detail AS alldtl USING(product_id)"; 
    110  
    111         $where = "dcfp.customer_id = ? AND alldtl.del_flg = 0 AND alldtl.status = 1"; 
    112         // 在庫無し商品の非表示 
    113         if (NOSTOCK_HIDDEN === true) { 
    114             $where .= ' AND (alldtl.stock_max >= 1 OR alldtl.stock_unlimited_max = 1)'; 
    115         } 
    116         $order = "create_date DESC"; 
    117  
    118         $arrval = array($objCustomer->getvalue('customer_id')); 
    119  
    120         // お気に入りの数を取得 
    121         $linemax = $objQuery->count($from, $where, $arrval); 
    122         $this->tpl_linemax = $linemax; 
    123  
    124         // ページ送りの取得 
    125         $objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, SEARCH_PMAX, "fnNaviPage", NAVI_PMAX); 
    126         $this->tpl_strnavi = $objNavi->strnavi;     // 表示文字列 
    127         $startno = $objNavi->start_row; 
    128  
    129         // 取得範囲の指定(開始行番号、行数のセット) 
    130         $objQuery->setLimitOffset(SEARCH_PMAX, $startno); 
    131         // 表示順序 
    132         $objQuery->setOrder($order); 
    133  
    134         // お気に入りの取得 
    135         $this->arrFavorite = $objQuery->select($col, $from, $where, $arrval); 
    136  
    137         // パラメータ管理クラス 
    138         $this->objFormParam = new SC_FormParam(); 
    139         // POST値の取得 
    140         $this->objFormParam->setParam($_POST); 
    141  
    142         // 入力情報を渡す 
    143         $this->arrForm = $this->objFormParam->getFormParamList(); 
     85        $this->arrFavorite = $this->lfGetFavoriteProduct($customer_id, $this); 
    14486    } 
    14587 
     
    15395    } 
    15496 
    155     //エラーチェック 
    15697 
    157     function lfErrorCheck() { 
    158         $objErr = new SC_CheckError(); 
    159         $objErr->doFunc(array("メールアドレス", "login_email", MTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","EMAIL_CHECK","MAX_LENGTH_CHECK")); 
    160         $objErr->dofunc(array("パスワード", "login_password", PASSWORD_LEN2), array("EXIST_CHECK","ALNUM_CHECK")); 
    161         return $objErr->arrErr; 
     98    /** 
     99     * お気に入りを取得する 
     100     * 
     101     * @param mixed $customer_id 
     102     * @param mixed $objPage 
     103     * @access private 
     104     * @return array お気に入り商品一覧 
     105     */ 
     106    function lfGetFavoriteProduct($customer_id, &$objPage) { 
     107        $objQuery       = SC_Query::getSingletonInstance(); 
     108        $objProduct     = new SC_Product(); 
     109 
     110        $objQuery->setOrder('create_date DESC'); 
     111        $arrProduct_id  = $objQuery->getCol('product_id', 'dtb_customer_favorite_products', 'customer_id = ?', array($customer_id)); 
     112 
     113        $objQuery       =& SC_Query::getSingletonInstance(); 
     114        $objQuery->setWhere($this->lfMakeWhere('alldtl.', $arrProduct_id)); 
     115        $linemax        = $objProduct->findProductCount($objQuery); 
     116 
     117        $objPage->tpl_linemax = $linemax;   // 何件が該当しました。表示用 
     118 
     119        // ページ送りの取得 
     120        $objNavi        = new SC_PageNavi($objPage->tpl_pageno, $linemax, SEARCH_PMAX, "fnNaviPage", NAVI_PMAX); 
     121        $this->tpl_strnavi = $objNavi->strnavi;     // 表示文字列 
     122        $startno        = $objNavi->start_row; 
     123 
     124        $objQuery       =& SC_Query::getSingletonInstance(); 
     125        //$objQuery->setLimitOffset(SEARCH_PMAX, $startno); 
     126        // 取得範囲の指定(開始行番号、行数のセット) 
     127        $arrProduct_id  = array_slice($arrProduct_id, $startno, SEARCH_PMAX); 
     128 
     129        $objQuery->setWhere($this->lfMakeWhere('', $arrProduct_id)); 
     130        $objProduct->setProductsOrder('create_date', 'dtb_customer_favorite_products', 'DESC'); 
     131        $arrProducts    = $objProduct->lists($objQuery, $arrProduct_id); 
     132 
     133        //取得している並び順で並び替え 
     134        $arrProducts2 = array(); 
     135        foreach($arrProducts as $item) { 
     136            $arrProducts2[ $item['product_id'] ] = $item; 
     137        } 
     138        $arrProductsList = array(); 
     139        foreach($arrProduct_id as $product_id) { 
     140            $arrProductsList[] = $arrProducts2[$product_id]; 
     141        } 
     142 
     143        return $arrProductsList; 
    162144    } 
     145 
     146 
     147    /* 仕方がない処理。。 */ 
     148    function lfMakeWhere ($tablename, $arrProduct_id) { 
     149 
     150        // 取得した表示すべきIDだけを指定して情報を取得。 
     151        $where = ""; 
     152        if (is_array($arrProduct_id) && !empty($arrProduct_id)) { 
     153            $where = $tablename . 'product_id IN (' . implode(',', $arrProduct_id) . ')'; 
     154        } else { 
     155            // 一致させない 
     156            $where = '0<>0'; 
     157        } 
     158        // 在庫無し商品の非表示 
     159        if (NOSTOCK_HIDDEN === true) { 
     160            $where .= ' AND (stock_max >= 1 OR stock_unlimited_max = 1)'; 
     161        } 
     162        return $where; 
     163    } 
     164 
    163165 
    164166    // お気に入り商品削除 
    165167    function lfDeleteFavoriteProduct($customer_id, $product_id) { 
    166         $objQuery = new SC_Query(); 
    167         $count = $objQuery->count("dtb_customer_favorite_products", "customer_id = ? AND product_id = ?", array($customer_id, $product_id)); 
     168        $objQuery   = new SC_Query(); 
     169        $count      = $objQuery->count("dtb_customer_favorite_products", "customer_id = ? AND product_id = ?", array($customer_id, $product_id)); 
    168170 
    169171        if ($count > 0) { 
     
    174176    } 
    175177} 
    176 ?> 
Note: See TracChangeset for help on using the changeset viewer.