source: branches/version-2_12-dev/data/class/pages/admin/LC_Page_Admin_Home.php @ 22567

Revision 22567, 9.9 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

  • 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
2<?php
3/*
4 * This file is part of EC-CUBE
5 *
6 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
7 *
8 * http://www.lockon.co.jp/
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 */
24
25// {{{ requires
26require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
27
28/**
29 * 管理画面ホーム のページクラス.
30 *
31 * @package Page
32 * @author LOCKON CO.,LTD.
33 * @version $Id$
34 */
35class LC_Page_Admin_Home extends LC_Page_Admin_Ex
36{
37
38    // }}}
39    // {{{ functions
40
41    /**
42     * Page を初期化する.
43     *
44     * @return void
45     */
46    function init()
47    {
48        parent::init();
49        $this->tpl_mainpage = 'home.tpl';
50        $this->tpl_subtitle = 'ホーム';
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process()
59    {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    function action()
70    {
71
72        // DBバージョンの取得
73        $this->db_version = $this->lfGetDBVersion();
74
75        // PHPバージョンの取得
76        $this->php_version = $this->lfGetPHPVersion();
77
78        // 現在の会員数
79        $this->customer_cnt = $this->lfGetCustomerCnt();
80
81        // 昨日の売上高
82        $this->order_yesterday_amount = $this->lfGetOrderYesterday('SUM');
83
84        // 昨日の売上件数
85        $this->order_yesterday_cnt = $this->lfGetOrderYesterday('COUNT');
86
87        // 今月の売上高
88        $this->order_month_amount = $this->lfGetOrderMonth('SUM');
89
90        // 今月の売上件数
91        $this->order_month_cnt = $this->lfGetOrderMonth('COUNT');
92
93        // 会員の累計ポイント
94        $this->customer_point = $this->lfGetTotalCustomerPoint();
95
96        //昨日のレビュー書き込み数
97        $this->review_yesterday_cnt = $this->lfGetReviewYesterday();
98
99        //レビュー書き込み非表示数
100        $this->review_nondisp_cnt = $this->lfGetReviewNonDisp();
101
102        // 品切れ商品
103        $this->arrSoldout = $this->lfGetSoldOut();
104
105        // 新規受付一覧
106        $this->arrNewOrder = $this->lfGetNewOrder();
107
108        // お知らせ一覧の取得
109        $this->arrInfo = $this->lfGetInfo();
110
111    }
112
113    /**
114     * デストラクタ.
115     *
116     * @return void
117     */
118    function destroy()
119    {
120        parent::destroy();
121    }
122
123    /**
124     * PHPバージョンの取得
125     *
126     * @return string PHPバージョン情報
127     */
128    function lfGetPHPVersion()
129    {
130        return 'PHP ' . phpversion();
131    }
132
133    /**
134     * DBバージョンの取得
135     *
136     * @return mixed DBバージョン情報
137     */
138    function lfGetDBVersion()
139    {
140        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
141        return $dbFactory->sfGetDBVersion();
142    }
143
144    /**
145     * 現在の会員数の取得
146     *
147     * @return integer 会員数
148     */
149    function lfGetCustomerCnt()
150    {
151        $objQuery =& SC_Query_Ex::getSingletonInstance();
152        $col = 'COUNT(customer_id)';
153        $table = 'dtb_customer';
154        $where = 'del_flg = 0 AND status = 2';
155        return $objQuery->get($col, $table, $where);
156    }
157
158    /**
159     * 昨日の売上データの取得
160     *
161     * @param string $method 取得タイプ 件数:'COUNT' or 金額:'SUM'
162     * @return integer 結果数値
163     */
164    function lfGetOrderYesterday($method)
165    {
166        $objQuery =& SC_Query_Ex::getSingletonInstance();
167
168        // TODO: DBFactory使わないでも共通化できそうな気もしますが
169        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
170        $sql = $dbFactory->getOrderYesterdaySql($method);
171        return $objQuery->getOne($sql);
172    }
173
174    /**
175     * 今月の売上データの取得
176     *
177     * @param string $method 取得タイプ 件数:'COUNT' or 金額:'SUM'
178     * @return integer 結果数値
179     */
180    function lfGetOrderMonth($method)
181    {
182        $objQuery =& SC_Query_Ex::getSingletonInstance();
183        $month = date('Y/m', mktime());
184
185        // TODO: DBFactory使わないでも共通化できそうな気もしますが
186        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
187        $sql = $dbFactory->getOrderMonthSql($method);
188        return $objQuery->getOne($sql, array($month));
189    }
190
191    /**
192     * 会員の保持ポイント合計の取得
193     *
194     * @return integer 会員の保持ポイント合計
195     */
196    function lfGetTotalCustomerPoint()
197    {
198        $objQuery =& SC_Query_Ex::getSingletonInstance();
199
200        $col = 'SUM(point)';
201        $where = 'del_flg = 0';
202        $from = 'dtb_customer';
203        return $objQuery->get($col, $from, $where);
204    }
205
206    /**
207     * 昨日のレビュー書き込み数の取得
208     *
209     * @return integer 昨日のレビュー書き込み数
210     */
211    function lfGetReviewYesterday()
212    {
213        $objQuery =& SC_Query_Ex::getSingletonInstance();
214
215        // TODO: DBFactory使わないでも共通化できそうな気もしますが
216        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
217        $sql = $dbFactory->getReviewYesterdaySql();
218        return $objQuery->getOne($sql);
219    }
220
221    /**
222     * レビュー書き込み非表示数の取得
223     *
224     * @return integer レビュー書き込み非表示数
225     */
226    function lfGetReviewNonDisp()
227    {
228        $objQuery =& SC_Query_Ex::getSingletonInstance();
229
230        $table = 'dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id';
231        $where = 'A.del_flg = 0 AND A.status = 2 AND B.del_flg = 0';
232        return $objQuery->count($table, $where);
233    }
234
235    /**
236     * 品切れ商品の取得
237     *
238     * @return array 品切れ商品一覧
239     */
240    function lfGetSoldOut()
241    {
242        $objQuery =& SC_Query_Ex::getSingletonInstance();
243
244        $cols = 'product_id, name';
245        $table = 'dtb_products';
246        $where = 'product_id IN ('
247               . 'SELECT product_id FROM dtb_products_class '
248               . 'WHERE del_flg = 0 AND stock_unlimited = ? AND stock <= 0)'
249               . ' AND del_flg = 0';
250        return $objQuery->select($cols, $table, $where, array(UNLIMITED_FLG_LIMITED));
251    }
252
253    /**
254     * 新規受付一覧の取得
255     *
256     * @return array 新規受付一覧配列
257     */
258    function lfGetNewOrder()
259    {
260        $objQuery =& SC_Query_Ex::getSingletonInstance();
261
262        $sql = <<< __EOS__
263            SELECT
264                ord.order_id,
265                ord.customer_id,
266                ord.order_name01 AS name01,
267                ord.order_name02 AS name02,
268                ord.total,
269                ord.create_date,
270                (SELECT
271                    det.product_name
272                FROM
273                    dtb_order_detail AS det
274                WHERE
275                    ord.order_id = det.order_id
276                ORDER BY det.order_detail_id
277                LIMIT 1
278                ) AS product_name,
279                (SELECT
280                    pay.payment_method
281                FROM
282                    dtb_payment AS pay
283                WHERE
284                    ord.payment_id = pay.payment_id
285                ) AS payment_method
286            FROM (
287                SELECT
288                    order_id,
289                    customer_id,
290                    order_name01,
291                    order_name02,
292                    total,
293                    create_date,
294                    payment_id
295                FROM
296                    dtb_order AS ord
297                WHERE
298                    del_flg = 0 AND status <> ?
299                ORDER BY
300                    create_date DESC LIMIT 10 OFFSET 0
301            ) AS ord
302__EOS__;
303        $arrNewOrder = $objQuery->getAll($sql, ORDER_CANCEL);
304        foreach ($arrNewOrder as $key => $val) {
305            $arrNewOrder[$key]['create_date'] = str_replace('-', '/', substr($val['create_date'], 0,19));
306
307        }
308        return $arrNewOrder;
309    }
310
311    /**
312     * リリース情報を取得する.
313     *
314     * @return array 取得した情報配列
315     */
316    function lfGetInfo()
317    {
318        // 更新情報の取得ON/OFF確認
319        if (!ECCUBE_INFO) return array();
320
321        // パラメーター「UPDATE_HTTP」が空文字の場合、処理しない。
322        // XXX これと別に on/off を持たせるべきか。
323        if (strlen(UPDATE_HTTP) == 0) return array();
324
325        $query = '';
326        // サイト情報の送信可否設定
327        // XXX インストール時に問い合わせて送信可否設定を行うように設定すべきか。
328        // XXX (URLは強制送信すべきではないと思うが)バージョンは強制送信すべきか。
329        if (UPDATE_SEND_SITE_INFO === true) {
330            $query = '?site_url=' . HTTP_URL . '&eccube_version=' . ECCUBE_VERSION;
331        }
332
333        $url = UPDATE_HTTP . $query;
334
335        // タイムアウト時間設定
336        $context = array('http' => array('timeout' => HTTP_REQUEST_TIMEOUT));
337
338        $jsonStr = @file_get_contents($url, false, stream_context_create($context));
339
340        $arrTmpData = is_string($jsonStr) ? SC_Utils_Ex::jsonDecode($jsonStr) : null;
341
342        if (empty($arrTmpData)) {
343            SC_Utils_Ex::sfErrorHeader('>> 更新情報の取得に失敗しました。');
344            return array();
345        }
346        $arrInfo = array();
347        foreach ($arrTmpData as $objData) {
348            $arrInfo[] = get_object_vars($objData);
349        }
350        return $arrInfo;
351    }
352}
Note: See TracBrowser for help on using the repository browser.