source: branches/version-2_11-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_News.php @ 21045

Revision 21045, 6.4 KB checked in by 468, 13 years ago (diff)

#1413 スマートフォン版新着情報ブロック用処理(Ajax通信用データ返信)追加

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php';
26
27/**
28 * 新着情報 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_FrontParts_Bloc_News extends LC_Page_FrontParts_Bloc {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46    }
47
48    /**
49     * Page のプロセス.
50     *
51     * @return void
52     */
53    function process() {
54        $this->action();
55        $this->sendResponse();
56    }
57
58    /**
59     * Page のアクション.
60     *
61     * @return void
62     */
63    function action() {
64
65        $objFormParam = new SC_FormParam_Ex();
66        switch($this->getMode()){
67            case "getList":
68                $this->lfInitNewsParam($objFormParam);
69                $objFormParam->setParam($_POST);
70                $objFormParam->convParam();
71                $this->arrErr = $this->lfCheckError($objFormParam);
72                if(empty($this->arrEr)){
73                     $json = $this->lfGetNewsForJson($objFormParam);
74                     echo $json;
75                     exit;
76                }
77                break;
78            case "getDetail":
79                $this->lfInitNewsParam($objFormParam);
80                $objFormParam->setParam($_GET);
81                $objFormParam->convParam();
82                $this->arrErr = $this->lfCheckError($objFormParam);
83                if(empty($this->arrEr)){
84                     $json = $this->lfGetNewsDetailForJson($objFormParam);
85                     echo $json;
86                     exit;
87                }
88                break;
89            default:
90                $this->newsCount = $this->lfGetNewsCount();
91                $this->arrNews = $this->lfGetNews();
92                break;
93        }
94    }
95
96    /**
97     * デストラクタ.
98     *
99     * @return void
100     */
101    function destroy() {
102        parent::destroy();
103    }
104
105   /**
106     * 新着情報パラメーター初期化
107     *
108     * @param array $objFormParam フォームパラメータークラス
109     * @return void
110     */
111    function lfInitNewsParam(&$objFormParam) {
112        $objFormParam->addParam("現在ページ", "pageno", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), "", false);
113        $objFormParam->addParam("表示件数", "disp_number", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), "", false);
114        $objFormParam->addParam("新着ID", "news_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), "", false);
115    }
116
117      /**
118     * フォーム入力パラメーターエラーチェック
119     *
120     * @param array $objFormParam フォームパラメータークラス
121     * @return array エラー配列
122     */
123    function lfCheckError(&$objFormParam) {
124        $arrErr = SC_Helper_Customer_Ex::sfCustomerMypageErrorCheck($objFormParam, true);
125        return $arrErr;
126    }
127
128    /**
129     * 新着情報を取得する.
130     *
131     * @return array $arrNewsList 新着情報の配列を返す
132     */
133    function lfGetNews(){
134        $objQuery = SC_Query_Ex::getSingletonInstance();
135        $sql = '';
136        $sql .= " SELECT ";
137        $sql .= "   *, ";
138        $sql .= "   cast(news_date as date) as news_date_disp ";
139        $sql .= " FROM ";
140        $sql .= "   dtb_news ";
141        $sql .= " WHERE ";
142        $sql .= "   del_flg = '0' ";
143        $sql .= " ORDER BY ";
144        $sql .= "   rank DESC ";
145
146        $arrNewsList = $objQuery->getAll($sql);
147        return $arrNewsList;
148    }
149
150    /**
151     * 新着情報をJSON形式で取得する
152     * (ページと表示件数を指定)
153     *
154     * @param array $objFormParam フォームパラメータークラス
155     * @return String $json 新着情報のJSONを返す
156     */
157    function lfGetNewsForJson(&$objFormParam){
158
159        $objQuery = SC_Query_Ex::getSingletonInstance();
160        $arrData = $objFormParam->getHashArray();
161       
162        $dispNumber = $arrData['disp_number'];
163        $pageNo = $arrData['pageno'];
164        if(!empty($dispNumber) && !empty($pageNo)){
165             $objQuery->setLimitOffset($dispNumber, (($pageNo - 1) * $dispNumber));
166        }
167
168        $objQuery->setOrder("rank DESC ");
169        $arrNewsList = $objQuery->select(" * , cast(news_date as date) as news_date_disp "," dtb_news "," del_flg = '0' ");
170
171        //新着情報の最大ページ数をセット
172        $newsCount = $this->lfGetNewsCount();
173        $arrNewsList["news_page_count"] = ceil($newsCount / 3);
174
175        $json =  SC_Utils_Ex::jsonEncode($arrNewsList);    //JSON形式
176
177        return $json;
178    }
179
180    /**
181     * 新着情報1件分をJSON形式で取得する
182     * (news_idを指定)
183     *
184     * @param array $objFormParam フォームパラメータークラス
185     * @return String $json 新着情報1件分のJSONを返す
186     */
187    function lfGetNewsDetailForJson(&$objFormParam){
188
189        $objQuery = SC_Query_Ex::getSingletonInstance();
190        $arrData = $objFormParam->getHashArray();
191        $newsId = $arrData['news_id'];
192        $arrNewsList = $objQuery->select(" * , cast(news_date as date) as news_date_disp "," dtb_news "," del_flg = '0' AND news_id = ? ", array($newsId));
193
194        $json =  SC_Utils_Ex::jsonEncode($arrNewsList);    //JSON形式
195
196        return $json;
197    }
198   
199    /**
200     * 新着情報の件数を取得する
201     *
202     * @return Integer $count 新着情報の件数を返す
203     */
204    function lfGetNewsCount(){
205
206        $count = 0;
207       
208        $objQuery = SC_Query_Ex::getSingletonInstance();
209        $count = $objQuery->count("dtb_news", "del_flg = '0'");
210
211        return $count;
212    }
213}
214?>
Note: See TracBrowser for help on using the repository browser.