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 | require_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 | */ |
---|
33 | class LC_Page_FrontParts_Bloc_News extends LC_Page_FrontParts_Bloc_Ex |
---|
34 | { |
---|
35 | /** |
---|
36 | * Page を初期化する. |
---|
37 | * |
---|
38 | * @return void |
---|
39 | */ |
---|
40 | function init() |
---|
41 | { |
---|
42 | parent::init(); |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * Page のプロセス. |
---|
47 | * |
---|
48 | * @return void |
---|
49 | */ |
---|
50 | function process() |
---|
51 | { |
---|
52 | $this->action(); |
---|
53 | $this->sendResponse(); |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * Page のアクション. |
---|
58 | * |
---|
59 | * @return void |
---|
60 | */ |
---|
61 | 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 | * @return void |
---|
108 | */ |
---|
109 | function destroy() |
---|
110 | { |
---|
111 | parent::destroy(); |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | * 新着情報パラメーター初期化 |
---|
116 | * |
---|
117 | * @param array $objFormParam フォームパラメータークラス |
---|
118 | * @return void |
---|
119 | */ |
---|
120 | function lfInitNewsParam(&$objFormParam) |
---|
121 | { |
---|
122 | $objFormParam->addParam('現在ページ', 'pageno', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false); |
---|
123 | $objFormParam->addParam('表示件数', 'disp_number', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false); |
---|
124 | $objFormParam->addParam('新着ID', 'news_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false); |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | * 新着情報を取得する. |
---|
129 | * |
---|
130 | * @return array $arrNewsList 新着情報の配列を返す |
---|
131 | */ |
---|
132 | function lfGetNews($dispNumber, $pageNo, SC_Helper_News_Ex $objNews) |
---|
133 | { |
---|
134 | $arrNewsList = $objNews->getList($dispNumber, $pageNo); |
---|
135 | |
---|
136 | // モバイルサイトのセッション保持 (#797) |
---|
137 | if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) { |
---|
138 | foreach ($arrNewsList as $key => $value) { |
---|
139 | $arrRow =& $arrNewsList[$key]; |
---|
140 | if (SC_Utils_Ex::isAppInnerUrl($arrRow['news_url'])) { |
---|
141 | $netUrl = new Net_URL($arrRow['news_url']); |
---|
142 | $netUrl->addQueryString(session_name(), session_id()); |
---|
143 | $arrRow['news_url'] = $netUrl->getURL(); |
---|
144 | } |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | return $arrNewsList; |
---|
149 | } |
---|
150 | |
---|
151 | /** |
---|
152 | * 新着情報をJSON形式で取得する |
---|
153 | * (ページと表示件数を指定) |
---|
154 | * |
---|
155 | * @param array $arrData フォーム入力値 |
---|
156 | * @param object $objNews |
---|
157 | * @return String $json 新着情報のJSONを返す |
---|
158 | */ |
---|
159 | function lfGetNewsForJson($arrData, SC_Helper_News_Ex $objNews) |
---|
160 | { |
---|
161 | $dispNumber = $arrData['disp_number']; |
---|
162 | $pageNo = $arrData['pageno']; |
---|
163 | $arrNewsList = $this->lfGetNews($dispNumber, $pageNo, $objNews); |
---|
164 | |
---|
165 | //新着情報の最大ページ数をセット |
---|
166 | $newsCount = $objNews->getCount(); |
---|
167 | $arrNewsList['news_page_count'] = ceil($newsCount / 3); |
---|
168 | |
---|
169 | $json = SC_Utils_Ex::jsonEncode($arrNewsList); //JSON形式 |
---|
170 | |
---|
171 | return $json; |
---|
172 | } |
---|
173 | |
---|
174 | /** |
---|
175 | * 新着情報1件分をJSON形式で取得する |
---|
176 | * (news_idを指定) |
---|
177 | * |
---|
178 | * @param array $arrData フォーム入力値 |
---|
179 | * @param object $objNews |
---|
180 | * @return String $json 新着情報1件分のJSONを返す |
---|
181 | */ |
---|
182 | function lfGetNewsDetailForJson($arrData) |
---|
183 | { |
---|
184 | $arrNewsList = SC_Helper_News_Ex::getNews($arrData['news_id']); |
---|
185 | $json = SC_Utils_Ex::jsonEncode($arrNewsList); //JSON形式 |
---|
186 | |
---|
187 | return $json; |
---|
188 | } |
---|
189 | |
---|
190 | /** |
---|
191 | * エラーメッセージを整形し, JSON 形式で返す. |
---|
192 | * |
---|
193 | * @param array $arrErr エラーメッセージの配列 |
---|
194 | * @return string JSON 形式のエラーメッセージ |
---|
195 | */ |
---|
196 | function lfGetErrors($arrErr) |
---|
197 | { |
---|
198 | $messages = ''; |
---|
199 | foreach ($arrErr as $val) { |
---|
200 | $messages .= $val . "\n"; |
---|
201 | } |
---|
202 | |
---|
203 | return SC_Utils_Ex::jsonEncode(array('error' => $messages)); |
---|
204 | } |
---|
205 | } |
---|