source: branches/version-2_5-dev/data/class/SC_Display.php @ 19832

Revision 19832, 4.6 KB checked in by Seasoft, 13 years ago (diff)

#714(パス指定によるリダイレクトの記述を簡潔にする) 共通処理実装、個別処理の一部を実装
#869(create_date, update_date 列の定義が、表やDBによるバラツキがある)

  • NOT NULL 制約により実装漏れに気づいたので修正

#893(SC_Response#reload を使うべきであろう箇所で SC_Response#sendRedirect を利用している)
#628(未使用処理・定義などの削除)

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 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/**
25 * Http コンテンツ出力を制御するクラス.
26 *
27 * @author Ryuichi Tokugami
28 * @version $Id$
29 */
30class SC_Display{
31
32    var $response;
33
34    var $device;
35
36    /** SC_View インスタンス */
37    var $view;
38
39    var $deviceSeted = false;
40
41    /*
42     * TODO php4を捨てたときに ここのコメントアウトを外してね。
43     * const('MOBILE',1);
44     * const('SMARTPHONE',2);
45     * const('PC',10);
46     * const('ADMIN',99);
47     */
48
49    function SC_Display($hasPrevURL = true) {
50        $this->response = new SC_Response_Ex();
51        if ($hasPrevURL) {
52            $this->setPrevURL();
53        }
54    }
55
56    function setPrevURL(){
57        // TODO SC_SiteSession で実装した方が良さげ
58        $objCartSess = new SC_CartSession();
59        $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
60    }
61
62    /**
63     * LC_Page のパラメータを, テンプレートに設定し, 出力の準備を行う.
64     *
65     * @param LC_Page $page LC_Page インスタンス
66     * @param $is_admin boolean 管理画面を扱う場合 true
67     */
68    function prepare($page, $is_admin = false){
69        if(!$this->deviceSeted || !is_null($this->view)){
70            $device = ($is_admin) ? DEVICE_TYPE_ADMIN : $this->detectDevice();
71            $this->setDevice($device);
72        }
73        $this->assignobj($page);
74        $this->response->setResposeBody($this->view->getResponse($page->getTemplate()));
75    }
76
77    /**
78     * リダイレクトを行う.
79     *
80     * SC_Response::sendRedirect() のラッパーです.
81     */
82    function redirect($location){
83        $this->response->sendRedirect($location, array(), true);
84    }
85
86    /**
87     * リロードを行う.
88     *
89     * SC_Response::reload() のラッパーです.
90     */
91    function reload($queryString = array(), $removeQueryString = false){
92        $this->response->reload($queryString, $removeQueryString);
93    }
94
95    function noAction(){
96        return;
97    }
98
99    /**
100     * ヘッダを追加する.
101     */
102    function addHeader($name, $value){
103        $this->response->addHeader($name, $value);
104    }
105
106    /**
107     * デバイス毎の出力方法を自動で変更する、ファサード
108     * Enter description here ...
109     */
110    function setDevice($device = DEVICE_TYPE_PC){
111
112        switch ($device){
113            case DEVICE_TYPE_MOBILE:
114                $this->response->setContentType("text/html");
115                $this->setView(new SC_MobileView());
116                break;
117            case DEVICE_TYPE_SMARTPHONE:
118                $this->setView(new SC_SmartphoneView());
119                break;
120            case DEVICE_TYPE_PC:
121                $this->setView(new SC_SiteView());
122                break;
123            case DEVICE_TYPE_ADMIN:
124                $this->setView(new SC_AdminView());
125        }
126        $this->deviceSeted = true;
127    }
128
129    /**
130     * SC_View インスタンスを設定する.
131     */
132    function setView($view){
133        $this->view = $view;
134    }
135
136    /**
137     * 機種を判別する。
138     *
139     * SC_Display::MOBILE = ガラケー = 1
140     * SC_Display::SMARTPHONE = スマホ = 2
141     * SC_Display::PC = PC = 10
142     *
143     * @static
144     * @return integer 端末種別ID
145     */
146    function detectDevice(){
147        $nu = new Net_UserAgent_Mobile();
148        $su = new SC_SmartphoneUserAgent();
149        $retDevice = 0;
150        if ($nu->isMobile()) {
151            return DEVICE_TYPE_MOBILE;
152        } elseif ($su->isSmartphone()) {
153            return DEVICE_TYPE_SMARTPHONE;
154        } else {
155            return DEVICE_TYPE_PC;
156        }
157    }
158
159    function assign($val1,$val2){
160        $this->view->assign($val1, $val2);
161    }
162
163    function assignobj($obj){
164        $this->view->assignobj($obj);
165    }
166
167    function assignarray($array){
168        $this->view->assignarray($array);
169    }
170}
Note: See TracBrowser for help on using the repository browser.