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

Revision 22567, 7.0 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

  • 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-2013 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_EX_REALDIR . 'page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ex.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_Ex
35{
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init()
46    {
47        parent::init();
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
55    function process()
56    {
57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のアクション.
63     *
64     * @return void
65     */
66    function action()
67    {
68
69        $objFormParam = new SC_FormParam_Ex();
70        switch ($this->getMode()) {
71            case 'getList':
72                $this->lfInitNewsParam($objFormParam);
73                $objFormParam->setParam($_POST);
74                $objFormParam->convParam();
75                $this->arrErr = $objFormParam->checkError(false);
76                if (empty($this->arrErr)) {
77
78                    $json = $this->lfGetNewsForJson($objFormParam);
79                    echo $json;
80                    SC_Response_Ex::actionExit();
81                } else {
82                    echo $this->lfGetErrors($this->arrErr);
83                    SC_Response_Ex::actionExit();
84                }
85                break;
86            case 'getDetail':
87                $this->lfInitNewsParam($objFormParam);
88                $objFormParam->setParam($_GET);
89                $objFormParam->convParam();
90                $this->arrErr = $objFormParam->checkError(false);
91                if (empty($this->arrErr)) {
92
93                    $json = $this->lfGetNewsDetailForJson($objFormParam);
94                    echo $json;
95                    SC_Response_Ex::actionExit();
96                } else {
97                    echo $this->lfGetErrors($this->arrErr);
98                    SC_Response_Ex::actionExit();
99                }
100                break;
101            default:
102                $this->newsCount = $this->lfGetNewsCount();
103                $this->arrNews = $this->lfGetNews(SC_Query_Ex::getSingletonInstance());
104                break;
105        }
106
107    }
108
109    /**
110     * デストラクタ.
111     *
112     * @return void
113     */
114    function destroy()
115    {
116        parent::destroy();
117    }
118
119    /**
120     * 新着情報パラメーター初期化
121     *
122     * @param array $objFormParam フォームパラメータークラス
123     * @return void
124     */
125    function lfInitNewsParam(&$objFormParam)
126    {
127        $objFormParam->addParam('現在ページ', 'pageno', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false);
128        $objFormParam->addParam('表示件数', 'disp_number', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false);
129        $objFormParam->addParam('新着ID', 'news_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false);
130    }
131
132    /**
133     * 新着情報を取得する.
134     *
135     * @return array $arrNewsList 新着情報の配列を返す
136     */
137    function lfGetNews(&$objQuery)
138    {
139        $objQuery->setOrder('rank DESC ');
140        $arrNewsList = $objQuery->select('* , cast(news_date as date) as news_date_disp', 'dtb_news' ,'del_flg = 0');
141
142        // モバイルサイトのセッション保持 (#797)
143        if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
144            foreach ($arrNewsList as $key => $value) {
145                $arrRow =& $arrNewsList[$key];
146                if (SC_Utils_Ex::isAppInnerUrl($arrRow['news_url'])) {
147                    $netUrl = new Net_URL($arrRow['news_url']);
148                    $netUrl->addQueryString(session_name(), session_id());
149                    $arrRow['news_url'] = $netUrl->getURL();
150                }
151            }
152        }
153
154        return $arrNewsList;
155    }
156
157    /**
158     * 新着情報をJSON形式で取得する
159     * (ページと表示件数を指定)
160     *
161     * @param array $objFormParam フォームパラメータークラス
162     * @return String $json 新着情報のJSONを返す
163     */
164    function lfGetNewsForJson(&$objFormParam)
165    {
166
167        $objQuery =& SC_Query_Ex::getSingletonInstance();
168        $arrData = $objFormParam->getHashArray();
169
170        $dispNumber = $arrData['disp_number'];
171        $pageNo = $arrData['pageno'];
172        if (!empty($dispNumber) && !empty($pageNo)) {
173            $objQuery->setLimitOffset($dispNumber, (($pageNo - 1) * $dispNumber));
174        }
175
176        $arrNewsList = $this->lfGetNews($objQuery);
177
178        //新着情報の最大ページ数をセット
179        $newsCount = $this->lfGetNewsCount();
180        $arrNewsList['news_page_count'] = ceil($newsCount / 3);
181
182        $json =  SC_Utils_Ex::jsonEncode($arrNewsList);    //JSON形式
183
184        return $json;
185    }
186
187    /**
188     * 新着情報1件分をJSON形式で取得する
189     * (news_idを指定)
190     *
191     * @param array $objFormParam フォームパラメータークラス
192     * @return String $json 新着情報1件分のJSONを返す
193     */
194    function lfGetNewsDetailForJson(&$objFormParam)
195    {
196
197        $objQuery = SC_Query_Ex::getSingletonInstance();
198        $arrData = $objFormParam->getHashArray();
199        $newsId = $arrData['news_id'];
200        $arrNewsList = $objQuery->select(' * , cast(news_date as date) as news_date_disp ',' dtb_news '," del_flg = '0' AND news_id = ? ", array($newsId));
201
202        $json =  SC_Utils_Ex::jsonEncode($arrNewsList);    //JSON形式
203
204        return $json;
205    }
206
207    /**
208     * 新着情報の件数を取得する
209     *
210     * @return Integer $count 新着情報の件数を返す
211     */
212    function lfGetNewsCount()
213    {
214
215        $count = 0;
216
217        $objQuery = SC_Query_Ex::getSingletonInstance();
218        $count = $objQuery->count('dtb_news', "del_flg = '0'");
219
220        return $count;
221    }
222
223    /**
224     * エラーメッセージを整形し, JSON 形式で返す.
225     *
226     * @param array $arrErr エラーメッセージの配列
227     * @return string JSON 形式のエラーメッセージ
228     */
229    function lfGetErrors($arrErr)
230    {
231        $messages = '';
232        foreach ($arrErr as $val) {
233            $messages .= $val . "\n";
234        }
235        return SC_Utils_Ex::jsonEncode(array('error' => $messages));
236    }
237}
Note: See TracBrowser for help on using the repository browser.