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 | // {{{ 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 = $objFormParam->checkError(false); |
---|
72 | if (empty($this->arrErr)) { |
---|
73 | |
---|
74 | $json = $this->lfGetNewsForJson($objFormParam); |
---|
75 | echo $json; |
---|
76 | SC_Response_Ex::actionExit(); |
---|
77 | } else { |
---|
78 | echo $this->lfGetErrors($this->arrErr); |
---|
79 | SC_Response_Ex::actionExit(); |
---|
80 | } |
---|
81 | break; |
---|
82 | case 'getDetail': |
---|
83 | $this->lfInitNewsParam($objFormParam); |
---|
84 | $objFormParam->setParam($_GET); |
---|
85 | $objFormParam->convParam(); |
---|
86 | $this->arrErr = $objFormParam->checkError(false); |
---|
87 | if (empty($this->arrErr)) { |
---|
88 | |
---|
89 | $json = $this->lfGetNewsDetailForJson($objFormParam); |
---|
90 | echo $json; |
---|
91 | SC_Response_Ex::actionExit(); |
---|
92 | } else { |
---|
93 | echo $this->lfGetErrors($this->arrErr); |
---|
94 | SC_Response_Ex::actionExit(); |
---|
95 | } |
---|
96 | break; |
---|
97 | default: |
---|
98 | $this->newsCount = $this->lfGetNewsCount(); |
---|
99 | $this->arrNews = $this->lfGetNews(SC_Query_Ex::getSingletonInstance()); |
---|
100 | break; |
---|
101 | } |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | * デストラクタ. |
---|
107 | * |
---|
108 | * @return void |
---|
109 | */ |
---|
110 | function destroy() { |
---|
111 | parent::destroy(); |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | * 新着情報パラメーター初期化 |
---|
116 | * |
---|
117 | * @param array $objFormParam フォームパラメータークラス |
---|
118 | * @return void |
---|
119 | */ |
---|
120 | function lfInitNewsParam(&$objFormParam) { |
---|
121 | $objFormParam->addParam('現在ページ', 'pageno', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false); |
---|
122 | $objFormParam->addParam('表示件数', 'disp_number', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false); |
---|
123 | $objFormParam->addParam('新着ID', 'news_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false); |
---|
124 | } |
---|
125 | |
---|
126 | /** |
---|
127 | * 新着情報を取得する. |
---|
128 | * |
---|
129 | * @return array $arrNewsList 新着情報の配列を返す |
---|
130 | */ |
---|
131 | function lfGetNews(&$objQuery) { |
---|
132 | $objQuery->setOrder('rank DESC '); |
---|
133 | $arrNewsList = $objQuery->select('* , cast(news_date as date) as news_date_disp', 'dtb_news' ,'del_flg = 0'); |
---|
134 | |
---|
135 | // モバイルサイトのセッション保持 (#797) |
---|
136 | if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) { |
---|
137 | foreach ($arrNewsList as $key => $value) { |
---|
138 | $arrRow =& $arrNewsList[$key]; |
---|
139 | if (SC_Utils_Ex::isAppInnerUrl($arrRow['news_url'])) { |
---|
140 | $netUrl = new Net_URL($arrRow['news_url']); |
---|
141 | $netUrl->addQueryString(session_name(), session_id()); |
---|
142 | $arrRow['news_url'] = $netUrl->getURL(); |
---|
143 | } |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
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 | $arrNewsList = $this->lfGetNews($objQuery); |
---|
169 | |
---|
170 | //新着情報の最大ページ数をセット |
---|
171 | $newsCount = $this->lfGetNewsCount(); |
---|
172 | $arrNewsList['news_page_count'] = ceil($newsCount / 3); |
---|
173 | |
---|
174 | $json = SC_Utils_Ex::jsonEncode($arrNewsList); //JSON形式 |
---|
175 | |
---|
176 | return $json; |
---|
177 | } |
---|
178 | |
---|
179 | /** |
---|
180 | * 新着情報1件分をJSON形式で取得する |
---|
181 | * (news_idを指定) |
---|
182 | * |
---|
183 | * @param array $objFormParam フォームパラメータークラス |
---|
184 | * @return String $json 新着情報1件分のJSONを返す |
---|
185 | */ |
---|
186 | function lfGetNewsDetailForJson(&$objFormParam) { |
---|
187 | |
---|
188 | $objQuery = SC_Query_Ex::getSingletonInstance(); |
---|
189 | $arrData = $objFormParam->getHashArray(); |
---|
190 | $newsId = $arrData['news_id']; |
---|
191 | $arrNewsList = $objQuery->select(' * , cast(news_date as date) as news_date_disp ',' dtb_news '," del_flg = '0' AND news_id = ? ", array($newsId)); |
---|
192 | |
---|
193 | $json = SC_Utils_Ex::jsonEncode($arrNewsList); //JSON形式 |
---|
194 | |
---|
195 | return $json; |
---|
196 | } |
---|
197 | |
---|
198 | /** |
---|
199 | * 新着情報の件数を取得する |
---|
200 | * |
---|
201 | * @return Integer $count 新着情報の件数を返す |
---|
202 | */ |
---|
203 | function lfGetNewsCount() { |
---|
204 | |
---|
205 | $count = 0; |
---|
206 | |
---|
207 | $objQuery = SC_Query_Ex::getSingletonInstance(); |
---|
208 | $count = $objQuery->count('dtb_news', "del_flg = '0'"); |
---|
209 | |
---|
210 | return $count; |
---|
211 | } |
---|
212 | |
---|
213 | /** |
---|
214 | * エラーメッセージを整形し, JSON 形式で返す. |
---|
215 | * |
---|
216 | * @param array $arrErr エラーメッセージの配列 |
---|
217 | * @return string JSON 形式のエラーメッセージ |
---|
218 | */ |
---|
219 | function lfGetErrors($arrErr) { |
---|
220 | $messages = ''; |
---|
221 | foreach ($arrErr as $val) { |
---|
222 | $messages .= $val . "\n"; |
---|
223 | } |
---|
224 | return SC_Utils_Ex::jsonEncode(array('error' => $messages)); |
---|
225 | } |
---|
226 | } |
---|