Ignore:
Timestamp:
2013/05/02 18:11:36 (11 years ago)
Author:
h_yoshimoto
Message:

#2236 2.12.3リリース以降の2.12-devへのコミット差し戻し

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_Recommend.php

    r22582 r22796  
    3232 * @version $Id$ 
    3333 */ 
    34 class LC_Page_Admin_Contents_Recommend extends LC_Page_Admin_Ex  
    35 { 
     34class LC_Page_Admin_Contents_Recommend extends LC_Page_Admin_Ex { 
    3635 
    3736    // }}} 
     
    4342     * @return void 
    4443     */ 
    45     function init() 
    46     { 
     44    function init() { 
    4745        parent::init(); 
    4846        $this->tpl_mainpage = 'contents/recommend.tpl'; 
     
    6058     * @return void 
    6159     */ 
    62     function process() 
    63     { 
     60    function process() { 
    6461        $this->action(); 
    6562        $this->sendResponse(); 
     
    7168     * @return void 
    7269     */ 
    73     function action() 
    74     { 
     70    function action() { 
    7571        $objFormParam = new SC_FormParam_Ex(); 
    7672        $this->lfInitParam($objFormParam); 
    7773        $objFormParam->setParam($_POST); 
    7874        $objFormParam->convParam(); 
    79         $arrPost = $objFormParam->getHashArray(); 
    80  
    81         $objRecommend = new SC_Helper_Recommend_Ex(); 
     75        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     76        $objDb = new SC_Helper_DB_Ex(); 
    8277 
    8378        switch ($this->getMode()) { 
    84             case 'down': //商品の並び替えをする。 
    85                 $objRecommend->rankDown($arrPost['best_id']); 
    86                 $arrItems = $this->getRecommendProducts($objRecommend); 
    87                 break; 
    88  
    89             case 'up': //商品の並び替えをする。 
    90                 $objRecommend->rankUp($arrPost['best_id']); 
    91                 $arrItems = $this->getRecommendProducts($objRecommend); 
     79            case 'down': //商品の並び替えをする。おすすめはデータベースの登録が昇順なので、Modeを逆にする。 
     80                $arrRet = $objQuery->select('best_id', 'dtb_best_products', 'rank = ?', array($_POST['rank'])); //おすすめidの取得 
     81                $best_id = $arrRet[0]['best_id']; 
     82                $objDb->sfRankUp('dtb_best_products','best_id',$best_id); 
     83                $arrPost = $objFormParam->getHashArray(); 
     84                $arrItems = $this->getRecommendProducts(); 
     85                break; 
     86 
     87            case 'up': //商品の並び替えをする。おすすめのみデータベースの登録が昇順なので、Modeを逆にする。 
     88                $arrRet = $objQuery->select('best_id', 'dtb_best_products', 'rank = ?', array($_POST['rank'])); //おすすめidの取得 
     89                $best_id = $arrRet[0]['best_id']; 
     90                $objDb->sfRankDown('dtb_best_products','best_id',$best_id); 
     91                $arrPost = $objFormParam->getHashArray(); 
     92                $arrItems = $this->getRecommendProducts(); 
    9293                break; 
    9394 
    9495            case 'regist': // 商品を登録する。 
    9596                $this->arrErr = $this->lfCheckError($objFormParam); 
     97                $arrPost = $objFormParam->getHashArray(); 
    9698                // 登録処理にエラーがあった場合は商品選択の時と同じ処理を行う。 
    9799                if (SC_Utils_Ex::isBlank($this->arrErr)) { 
    98100                    $member_id = $_SESSION['member_id']; 
    99                     $this->insertRecommendProduct($arrPost,$member_id,$objRecommend); 
    100                     $arrItems = $this->getRecommendProducts($objRecommend); 
     101                    $this->insertRecommendProduct($arrPost,$member_id); 
     102                    $arrItems = $this->getRecommendProducts(); 
    101103                } else { 
    102104                    $arrItems = $this->setProducts($arrPost, $arrItems); 
     
    107109            case 'delete': // 商品を削除する。 
    108110                $this->arrErr = $this->lfCheckError($objFormParam); 
     111                $arrPost = $objFormParam->getHashArray(); 
    109112                if (SC_Utils_Ex::isBlank($this->arrErr)) { 
    110                     $this->deleteProduct($arrPost, $objRecommend); 
    111                     $arrItems = $this->getRecommendProducts($objRecommend); 
     113                    $this->deleteProduct($arrPost); 
     114                    $arrItems = $this->getRecommendProducts(); 
    112115                } 
    113116                $this->tpl_onload = "window.alert('削除しました');"; 
     
    117120                $arrPost = $objFormParam->getHashArray(); 
    118121                if (SC_Utils_Ex::isBlank($this->arrErr['rank']) && SC_Utils_Ex::isBlank($this->arrErr['product_id'])) { 
    119                     $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts($objRecommend)); 
     122                    $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts()); 
    120123                    $this->checkRank = $arrPost['rank']; 
    121124                } 
    122125                break; 
    123126            default: 
    124                 $arrItems = $this->getRecommendProducts($objRecommend); 
     127                $arrItems = $this->getRecommendProducts(); 
    125128                break; 
    126129        } 
     
    140143     * @return void 
    141144     */ 
    142     function destroy() 
    143     { 
     145    function destroy() { 
    144146        parent::destroy(); 
    145147    } 
     
    149151     * @param Object $objFormParam 
    150152     */ 
    151     function lfInitParam(&$objFormParam) 
    152     { 
    153         $objFormParam->addParam('おすすめ商品ID', 'best_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); 
     153    function lfInitParam(&$objFormParam) { 
    154154        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); 
    155155        $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); 
     
    163163     * @return Array エラー内容 
    164164     */ 
    165     function lfCheckError(&$objFormParam) 
    166     { 
     165    function lfCheckError(&$objFormParam) { 
    167166        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); 
    168167        $objErr->arrErr = $objFormParam->checkError(); 
     
    172171    /** 
    173172     * 既に登録されている内容を取得する 
    174      * @param Object $objRecommend 
    175173     * @return Array $arrReturnProducts データベースに登録されているおすすめ商品の配列 
    176174     */ 
    177     function getRecommendProducts(SC_Helper_Recommend_Ex &$objRecommend) 
    178     { 
    179         $arrList = $objRecommend->getList(); 
    180         // product_id の一覧を作成 
    181         $product_ids = array(); 
    182         foreach ($arrList as $value) { 
    183             $product_ids[] = $value['product_id']; 
    184         } 
    185  
    186         $objProduct = new SC_Product_Ex; 
    187         $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    188         $arrProducts = $objProduct->getListByProductIds($objQuery, $product_ids); 
     175    function getRecommendProducts() { 
     176        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     177        $col = 'dtb_products.name,dtb_products.main_list_image,dtb_best_products.*'; 
     178        $table = 'dtb_best_products INNER JOIN dtb_products ON dtb_best_products.product_id = dtb_products.product_id'; 
     179        $where = 'dtb_best_products.del_flg = 0'; 
     180        $order = 'rank'; 
     181        $objQuery->setOrder($order); 
     182        $arrProducts = $objQuery->select($col, $table, $where); 
    189183 
    190184        $arrReturnProducts = array(); 
    191         foreach ($arrList as $data) { 
    192             $data['main_list_image'] = $arrProducts[$data['product_id']]['main_list_image']; 
    193             $data['name'] = $arrProducts[$data['product_id']]['name']; 
     185        foreach ($arrProducts as $data) { 
    194186            $arrReturnProducts[$data['rank']] = $data; 
    195187        } 
     
    201193     * @param Array $arrPost POSTの値を格納した配列 
    202194     * @param Integer $member_id 登録した管理者を示すID 
    203      * @param Object $objRecommend 
    204      */ 
    205     function insertRecommendProduct($arrPost,$member_id, SC_Helper_Recommend_Ex &$objRecommend) 
    206     { 
     195     */ 
     196    function insertRecommendProduct($arrPost,$member_id) { 
     197        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    207198        // 古いおすすめ商品のデータを削除する。 
    208         $this->deleteProduct($arrPost, $objRecommend); 
     199        $this->deleteProduct($arrPost); 
    209200 
    210201        $sqlval = array(); 
     
    214205        $sqlval['comment'] = $arrPost['comment']; 
    215206        $sqlval['creator_id'] = $member_id; 
    216         $objRecommend->save($sqlval); 
     207        $sqlval['create_date'] = 'CURRENT_TIMESTAMP'; 
     208        $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; 
     209        $sqlval['best_id'] = $objQuery->nextVal('dtb_best_products_best_id'); 
     210        $objQuery->insert('dtb_best_products', $sqlval); 
    217211    } 
    218212 
     
    220214     * データを削除する 
    221215     * @param Array $arrPost POSTの値を格納した配列 
    222      * @param Object $objRecommend 
    223      * @return void 
    224      */ 
    225     function deleteProduct($arrPost, SC_Helper_Recommend_Ex &$objRecommend) 
    226     { 
    227         if ($arrPost['best_id']) { 
    228             $target = $arrPost['best_id']; 
    229         } else { 
    230             $recommend = $objRecommend->getByRank($arrPost['rank']); 
    231             $target = $recommend['best_id']; 
    232         } 
    233         $objRecommend->delete($target); 
     216     */ 
     217    function deleteProduct($arrPost) { 
     218        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     219        $table = 'dtb_best_products'; 
     220        $where = 'category_id = ? AND rank = ?'; 
     221        $arrWhereVal = array($arrPost['category_id'],$arrPost['rank']); 
     222        $objQuery->delete($table, $where, $arrWhereVal); 
    234223    } 
    235224 
     
    237226     * 商品情報を取得する 
    238227     * @param Integer $product_id 商品ID 
    239      * @return Array $return 商品のデータを格納した配列 
    240      */ 
    241     function getProduct($product_id) 
    242     { 
    243         $objProduct = new SC_Product_Ex(); 
    244         $arrProduct = $objProduct->getDetail($product_id); 
    245         $return = array( 
    246             'product_id' => $arrProduct['product_id'], 
    247             'main_list_image' => $arrProduct['main_list_image'], 
    248             'name' => $arrProduct['name'] 
    249         ); 
    250         return $return; 
     228     * @return Array $arrProduct 商品のデータを格納した配列 
     229     */ 
     230    function getProduct($product_id) { 
     231        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     232        $col = 'product_id,main_list_image,name'; 
     233        $table = 'dtb_products'; 
     234        $where = 'product_id = ? AND del_flg = 0'; 
     235        $arrWhereVal = array($product_id); 
     236        $arrProduct = $objQuery->select($col, $table, $where, $arrWhereVal); 
     237        return $arrProduct[0]; 
    251238    } 
    252239 
     
    256243     * @param Array $arrItems フロントに表示される商品の情報を格納した配列 
    257244     */ 
    258     function setProducts($arrPost,$arrItems) 
    259     { 
     245    function setProducts($arrPost,$arrItems) { 
    260246        $arrProduct = $this->getProduct($arrPost['product_id']); 
    261247        if (count($arrProduct) > 0) { 
Note: See TracChangeset for help on using the changeset viewer.