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 |
---|
25 | require_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 | */ |
---|
34 | class 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 | $objNews = new SC_Helper_News_Ex(); |
---|
70 | $objFormParam = new SC_FormParam_Ex(); |
---|
71 | switch ($this->getMode()) { |
---|
72 | case 'getList': |
---|
73 | $this->lfInitNewsParam($objFormParam); |
---|
74 | $objFormParam->setParam($_POST); |
---|
75 | $objFormParam->convParam(); |
---|
76 | $this->arrErr = $objFormParam->checkError(false); |
---|
77 | if (empty($this->arrErr)) { |
---|
78 | $arrData = $objFormParam->getHashArray(); |
---|
79 | $json = $this->lfGetNewsForJson($arrData, $objNews); |
---|
80 | echo $json; |
---|
81 | SC_Response_Ex::actionExit(); |
---|
82 | } else { |
---|
83 | echo $this->lfGetErrors($this->arrErr); |
---|
84 | SC_Response_Ex::actionExit(); |
---|
85 | } |
---|
86 | break; |
---|
87 | case 'getDetail': |
---|
88 | $this->lfInitNewsParam($objFormParam); |
---|
89 | $objFormParam->setParam($_GET); |
---|
90 | $objFormParam->convParam(); |
---|
91 | $this->arrErr = $objFormParam->checkError(false); |
---|
92 | if (empty($this->arrErr)) { |
---|
93 | $arrData = $objFormParam->getHashArray(); |
---|
94 | $json = $this->lfGetNewsDetailForJson($arrData, $objNews); |
---|
95 | echo $json; |
---|
96 | SC_Response_Ex::actionExit(); |
---|
97 | } else { |
---|
98 | echo $this->lfGetErrors($this->arrErr); |
---|
99 | SC_Response_Ex::actionExit(); |
---|
100 | } |
---|
101 | break; |
---|
102 | default: |
---|
103 | $this->arrNews = $objNews->getList(); |
---|
104 | $this->newsCount = $objNews->getCount(); |
---|
105 | break; |
---|
106 | } |
---|
107 | |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * デストラクタ. |
---|
112 | * |
---|
113 | * @return void |
---|
114 | */ |
---|
115 | function destroy() |
---|
116 | { |
---|
117 | parent::destroy(); |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | * 新着情報パラメーター初期化 |
---|
122 | * |
---|
123 | * @param array $objFormParam フォームパラメータークラス |
---|
124 | * @return void |
---|
125 | */ |
---|
126 | function lfInitNewsParam(&$objFormParam) |
---|
127 | { |
---|
128 | $objFormParam->addParam('現在ページ', 'pageno', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false); |
---|
129 | $objFormParam->addParam('表示件数', 'disp_number', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false); |
---|
130 | $objFormParam->addParam('新着ID', 'news_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false); |
---|
131 | } |
---|
132 | |
---|
133 | /** |
---|
134 | * 新着情報を取得する. |
---|
135 | * |
---|
136 | * @return array $arrNewsList 新着情報の配列を返す |
---|
137 | */ |
---|
138 | function lfGetNews($dispNumber, $pageNo, SC_Helper_News_Ex $objNews) |
---|
139 | { |
---|
140 | $arrNewsList = $objNews->getList($dispNumber, $pageNo); |
---|
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 $arrData フォーム入力値 |
---|
162 | * @param object $objNews |
---|
163 | * @return String $json 新着情報のJSONを返す |
---|
164 | */ |
---|
165 | function lfGetNewsForJson($arrData, SC_Helper_News_Ex $objNews) |
---|
166 | { |
---|
167 | |
---|
168 | $dispNumber = $arrData['disp_number']; |
---|
169 | $pageNo = $arrData['pageno']; |
---|
170 | $arrNewsList = $this->lfGetNews($dispNumber, $pageNo, $objNews); |
---|
171 | |
---|
172 | //新着情報の最大ページ数をセット |
---|
173 | $newsCount = $objNews->getCount(); |
---|
174 | $arrNewsList['news_page_count'] = ceil($newsCount / 3); |
---|
175 | |
---|
176 | $json = SC_Utils_Ex::jsonEncode($arrNewsList); //JSON形式 |
---|
177 | |
---|
178 | return $json; |
---|
179 | } |
---|
180 | |
---|
181 | /** |
---|
182 | * 新着情報1件分をJSON形式で取得する |
---|
183 | * (news_idを指定) |
---|
184 | * |
---|
185 | * @param array $arrData フォーム入力値 |
---|
186 | * @param object $objNews |
---|
187 | * @return String $json 新着情報1件分のJSONを返す |
---|
188 | */ |
---|
189 | function lfGetNewsDetailForJson($arrData, SC_Helper_News_Ex $objNews) |
---|
190 | { |
---|
191 | |
---|
192 | $arrNewsList = $objNews->get($arrData['news_id']); |
---|
193 | $json = SC_Utils_Ex::jsonEncode($arrNewsList); //JSON形式 |
---|
194 | |
---|
195 | return $json; |
---|
196 | } |
---|
197 | |
---|
198 | /** |
---|
199 | * エラーメッセージを整形し, JSON 形式で返す. |
---|
200 | * |
---|
201 | * @param array $arrErr エラーメッセージの配列 |
---|
202 | * @return string JSON 形式のエラーメッセージ |
---|
203 | */ |
---|
204 | function lfGetErrors($arrErr) |
---|
205 | { |
---|
206 | $messages = ''; |
---|
207 | foreach ($arrErr as $val) { |
---|
208 | $messages .= $val . "\n"; |
---|
209 | } |
---|
210 | return SC_Utils_Ex::jsonEncode(array('error' => $messages)); |
---|
211 | } |
---|
212 | } |
---|