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

Revision 21420, 6.9 KB checked in by Seasoft, 12 years ago (diff)

#1613 (ソース整形・ソースコメントの改善)

  • Zend Framework PHP 標準コーディング規約への準拠を高めた
  • 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-2011 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_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.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 {
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                    $json = $this->lfGetNewsForJson($objFormParam);
74                    echo $json;
75                    exit;
76                } else {
77                    echo $this->lfGetErrors($this->arrErr);
78                    exit;
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                     $json = $this->lfGetNewsDetailForJson($objFormParam);
88                     echo $json;
89                     exit;
90                } else {
91                    echo $this->lfGetErrors($this->arrErr);
92                    exit;
93                }
94                break;
95            default:
96                $this->newsCount = $this->lfGetNewsCount();
97                $this->arrNews = $this->lfGetNews(SC_Query_Ex::getSingletonInstance());
98                break;
99        }
100    }
101
102    /**
103     * デストラクタ.
104     *
105     * @return void
106     */
107    function destroy() {
108        parent::destroy();
109    }
110
111   /**
112     * 新着情報パラメーター初期化
113     *
114     * @param array $objFormParam フォームパラメータークラス
115     * @return void
116     */
117    function lfInitNewsParam(&$objFormParam) {
118        $objFormParam->addParam("現在ページ", "pageno", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), "", false);
119        $objFormParam->addParam("表示件数", "disp_number", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), "", false);
120        $objFormParam->addParam("新着ID", "news_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), "", false);
121    }
122
123    /**
124     * 新着情報を取得する.
125     *
126     * @return array $arrNewsList 新着情報の配列を返す
127     */
128    function lfGetNews(&$objQuery) {
129        $objQuery->setOrder("rank DESC ");
130        $arrNewsList = $objQuery->select('* , cast(news_date as date) as news_date_disp', 'dtb_news' ,'del_flg = 0');
131
132        // モバイルサイトのセッション保持 (#797)
133        if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
134            foreach (array_keys($arrNewsList) as $key) {
135                $arrRow =& $arrNewsList[$key];
136                if (SC_Utils_Ex::isAppInnerUrl($arrRow['news_url'])) {
137                    $netUrl = new Net_URL($arrRow['news_url']);
138                    $netUrl->addQueryString(session_name(), session_id());
139                    $arrRow['news_url'] = $netUrl->getURL();
140                }
141            }
142        }
143
144        return $arrNewsList;
145    }
146
147    /**
148     * 新着情報をJSON形式で取得する
149     * (ページと表示件数を指定)
150     *
151     * @param array $objFormParam フォームパラメータークラス
152     * @return String $json 新着情報のJSONを返す
153     */
154    function lfGetNewsForJson(&$objFormParam){
155
156        $objQuery =& SC_Query_Ex::getSingletonInstance();
157        $arrData = $objFormParam->getHashArray();
158
159        $dispNumber = $arrData['disp_number'];
160        $pageNo = $arrData['pageno'];
161        if(!empty($dispNumber) && !empty($pageNo)){
162             $objQuery->setLimitOffset($dispNumber, (($pageNo - 1) * $dispNumber));
163        }
164
165        $arrNewsList = $this->lfGetNews($objQuery);
166
167        //新着情報の最大ページ数をセット
168        $newsCount = $this->lfGetNewsCount();
169        $arrNewsList["news_page_count"] = ceil($newsCount / 3);
170
171        $json =  SC_Utils_Ex::jsonEncode($arrNewsList);    //JSON形式
172
173        return $json;
174    }
175
176    /**
177     * 新着情報1件分をJSON形式で取得する
178     * (news_idを指定)
179     *
180     * @param array $objFormParam フォームパラメータークラス
181     * @return String $json 新着情報1件分のJSONを返す
182     */
183    function lfGetNewsDetailForJson(&$objFormParam){
184
185        $objQuery = SC_Query_Ex::getSingletonInstance();
186        $arrData = $objFormParam->getHashArray();
187        $newsId = $arrData['news_id'];
188        $arrNewsList = $objQuery->select(" * , cast(news_date as date) as news_date_disp "," dtb_news "," del_flg = '0' AND news_id = ? ", array($newsId));
189
190        $json =  SC_Utils_Ex::jsonEncode($arrNewsList);    //JSON形式
191
192        return $json;
193    }
194
195    /**
196     * 新着情報の件数を取得する
197     *
198     * @return Integer $count 新着情報の件数を返す
199     */
200    function lfGetNewsCount(){
201
202        $count = 0;
203
204        $objQuery = SC_Query_Ex::getSingletonInstance();
205        $count = $objQuery->count("dtb_news", "del_flg = '0'");
206
207        return $count;
208    }
209
210    /**
211     * エラーメッセージを整形し, JSON 形式で返す.
212     *
213     * @param array $arrErr エラーメッセージの配列
214     * @return string JSON 形式のエラーメッセージ
215     */
216    function lfGetErrors($arrErr) {
217        $messages = '';
218        foreach ($arrErr as $val) {
219            $messages .= $val . "\n";
220        }
221        return SC_Utils_Ex::jsonEncode(array('error' => $messages));
222    }
223}
Note: See TracBrowser for help on using the repository browser.