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

Revision 21689, 10.2 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 インスタンスを呼び出す処理を統一

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