source: branches/version-2_13_0/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_News.php @ 23126

Revision 23126, 6.2 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

  • 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
24require_once CLASS_EX_REALDIR . 'page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ex.php';
25
26/**
27 * 新着情報 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_FrontParts_Bloc_News extends LC_Page_FrontParts_Bloc_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43    }
44
45    /**
46     * Page のプロセス.
47     *
48     * @return void
49     */
50    public function process()
51    {
52        $this->action();
53        $this->sendResponse();
54    }
55
56    /**
57     * Page のアクション.
58     *
59     * @return void
60     */
61    public function action()
62    {
63        $objNews = new SC_Helper_News_Ex();
64        $objFormParam = new SC_FormParam_Ex();
65        switch ($this->getMode()) {
66            case 'getList':
67                $this->lfInitNewsParam($objFormParam);
68                $objFormParam->setParam($_POST);
69                $objFormParam->convParam();
70                $this->arrErr = $objFormParam->checkError(false);
71                if (empty($this->arrErr)) {
72                    $arrData = $objFormParam->getHashArray();
73                    $json = $this->lfGetNewsForJson($arrData, $objNews);
74                    echo $json;
75                    SC_Response_Ex::actionExit();
76                } else {
77                    echo $this->lfGetErrors($this->arrErr);
78                    SC_Response_Ex::actionExit();
79                }
80                break;
81            case 'getDetail':
82                $this->lfInitNewsParam($objFormParam);
83                $objFormParam->setParam($_GET);
84                $objFormParam->convParam();
85                $this->arrErr = $objFormParam->checkError(false);
86                if (empty($this->arrErr)) {
87                    $arrData = $objFormParam->getHashArray();
88                    $json = $this->lfGetNewsDetailForJson($arrData);
89                    echo $json;
90                    SC_Response_Ex::actionExit();
91                } else {
92                    echo $this->lfGetErrors($this->arrErr);
93                    SC_Response_Ex::actionExit();
94                }
95                break;
96            default:
97                $this->arrNews = $objNews->getList();
98                $this->newsCount = $objNews->getCount();
99                break;
100        }
101
102    }
103
104    /**
105     * 新着情報パラメーター初期化
106     *
107     * @param  array $objFormParam フォームパラメータークラス
108     * @return void
109     */
110    public function lfInitNewsParam(&$objFormParam)
111    {
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     * @return array $arrNewsList 新着情報の配列を返す
121     */
122    public function lfGetNews($dispNumber, $pageNo, SC_Helper_News_Ex $objNews)
123    {
124        $arrNewsList = $objNews->getList($dispNumber, $pageNo);
125
126        // モバイルサイトのセッション保持 (#797)
127        if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
128            foreach ($arrNewsList as $key => $value) {
129                $arrRow =& $arrNewsList[$key];
130                if (SC_Utils_Ex::isAppInnerUrl($arrRow['news_url'])) {
131                    $netUrl = new Net_URL($arrRow['news_url']);
132                    $netUrl->addQueryString(session_name(), session_id());
133                    $arrRow['news_url'] = $netUrl->getURL();
134                }
135            }
136        }
137
138        return $arrNewsList;
139    }
140
141    /**
142     * 新着情報をJSON形式で取得する
143     * (ページと表示件数を指定)
144     *
145     * @param  array  $arrData フォーム入力値
146     * @param  object $objNews
147     * @return String $json 新着情報のJSONを返す
148     */
149    public function lfGetNewsForJson($arrData, SC_Helper_News_Ex $objNews)
150    {
151        $dispNumber = $arrData['disp_number'];
152        $pageNo = $arrData['pageno'];
153        $arrNewsList = $this->lfGetNews($dispNumber, $pageNo, $objNews);
154
155        //新着情報の最大ページ数をセット
156        $newsCount = $objNews->getCount();
157        $arrNewsList['news_page_count'] = ceil($newsCount / 3);
158
159        $json =  SC_Utils_Ex::jsonEncode($arrNewsList);    //JSON形式
160
161        return $json;
162    }
163
164    /**
165     * 新着情報1件分をJSON形式で取得する
166     * (news_idを指定)
167     *
168     * @param  array  $arrData フォーム入力値
169     * @param  object $objNews
170     * @return String $json 新着情報1件分のJSONを返す
171     */
172    public function lfGetNewsDetailForJson($arrData)
173    {
174        $arrNewsList = SC_Helper_News_Ex::getNews($arrData['news_id']);
175        $json =  SC_Utils_Ex::jsonEncode($arrNewsList);    //JSON形式
176
177        return $json;
178    }
179
180    /**
181     * エラーメッセージを整形し, JSON 形式で返す.
182     *
183     * @param  array  $arrErr エラーメッセージの配列
184     * @return string JSON 形式のエラーメッセージ
185     */
186    public function lfGetErrors($arrErr)
187    {
188        $messages = '';
189        foreach ($arrErr as $val) {
190            $messages .= $val . "\n";
191        }
192
193        return SC_Utils_Ex::jsonEncode(array('error' => $messages));
194    }
195}
Note: See TracBrowser for help on using the repository browser.