source: branches/camp/camp-2_5-E/data/class/SC_Display.php @ 19517

Revision 19517, 3.2 KB checked in by kim, 16 years ago (diff)

【開発合宿】 SC_Display用のfetchとしてgetResponseに作成

Line 
1<?php
2class SC_Display{
3
4    var $response;
5
6    var $device;
7
8    var $autoSet;
9
10    /**
11     *
12     * @var SC_View
13     */
14    var $view;
15       
16    var $deviceSeted = false;
17   
18    // TODO php4を捨てたときに ここのコメントアウトを外してね。
19    /*
20    * const('MOBILE',1);
21    * const('SMARTPHONE',2);
22    * const('PC',4);
23    * const('ADMIN',8);
24    */
25    function SC_Display($setPrevURL=true,$autoGenerateHttpHeaders = true){
26        require_once(CLASS_EX_PATH."/SC_Response_Ex.php");
27        $this->response = new SC_Response_Ex();
28        $this->autoSet = $autoGenerateHttpHeaders;
29        if ($setPrevURL) {
30            $this->setPrevURL();
31        }
32    }
33   
34    function setPrevURL(){
35        $objCartSess = new SC_CartSession();
36        $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
37
38    }
39
40
41    // TODO このメソッドは、レスポンスを返すためのメソッドです。名前を絶対に変えましょう。
42    /**
43    *
44    * @param $page LC_Page
45    */
46    function hoge(LC_Page $page, $is_admin = false){
47        if(!$this->deviceSeted || !is_null($this->view)){
48            $device = ($is_admin) ? 8 : $this->detectDevice();
49            $this->setDevice($device);
50        }
51        $this->assignobj($page);
52        $this->response->setResposeBody($this->view->getResponse($page->getTemplate()));
53    }
54   
55    function redirect($location){
56        $this->response->sendRedirect($location);
57    }
58   
59    function noAction(){   
60        return;
61    }
62   
63    function addHeader(String $name,String $value){
64        $this->response->addHeader($name, $value);
65    }
66
67    /**
68     * デバイス毎の出力方法を自動で変更する、ファサード
69     * Enter description here ...
70     */
71    function setDevice($device=4){
72       
73        switch ($device){
74            case 1:
75                $this->response->setContentType("text/html");
76                $this->setView(new SC_MobileView());
77                break;
78            case 2:
79                //                $this->view = new
80                break;
81            case 4:
82                $this->setView(new SC_SiteView());
83                break;
84            case 8:
85                $this->setView(new SC_AdminView());
86        }
87        $this->deviceSeted = true;
88    }
89   
90    function setView(SC_View $view){
91       
92        $this->view = $view;
93    }
94
95    /**
96     * 機種を判別する。
97     * SC_Display::MOBILE = ガラケー = 1
98     * SC_Display::SMARTPHONE = スマホ = 2
99     * SC_Display::PC = PC = 4
100     * ※PHP4の為にconstは使っていません。 1がガラケーで、2がスマホで4がPCです。
101     * @return
102     */
103    function detectDevice(){
104        $nu = new Net_UserAgent_Mobile();
105        $retDevice = 0;
106        if($nu->isMobile()){
107            $retDevice = 1;
108        }elseif ($nu->isSmartphone()){
109            $retDevice = 2;
110        }else{
111            $retDevice = 4;
112        }
113
114        if($this->autoSet){
115            $this->setDevice($retDevice);
116        }
117        return $retDevice;
118    }
119
120    function assign($val1,$val2){
121        $this->view->assign($val1, $val2);
122    }
123
124    function assignobj($obj){
125        $this->view->assignobj($obj);
126    }
127
128    function assignarray($array){
129        $this->view->assignarray($array);
130    }
131
132
133}
Note: See TracBrowser for help on using the repository browser.