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

Revision 19131, 2.9 KB checked in by miningbrownie, 16 years ago (diff)
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       
17    var $deviceSeted = false;
18   
19    // TODO php4を捨てたときに ここのコメントアウトを外してね。
20    /*
21    * const('MOBILE',1);
22    * const('SMARTPHONE',2);
23    * const('PC',4);
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){
47        $this->assign($page);
48        if(!$this->deviceSeted){
49            $device = $this->detectDevice();
50            $this->setDevice($device);
51        }
52        $this->response->setResposeBody($this->view->fetch($page->getTemplate()));
53    }
54   
55    function redirect($location){
56        $this->response->sendRedirect($location);
57    }
58   
59    function noAction(){   
60        return;
61    }
62
63    /**
64     * デバイス毎の出力方法を自動で変更する、ファサード
65     * Enter description here ...
66     */
67    function setDevice(int $device = 4){
68        switch ($device){
69            case 1:
70                $this->response->setContentType("text/html");
71                $this->view = new SC_MobileView();
72                break;
73            case 2:
74                //                $this->view = new
75                break;
76            case 4:
77                $this->view = new SC_SiteView();
78                break;
79        }
80        $this->deviceSeted = true;
81    }
82
83    /**
84     * 機種を判別する。
85     * SC_Display::MOBILE = ガラケー = 1
86     * SC_Display::SMARTPHONE = スマホ = 2
87     * SC_Display::PC = PC = 4
88     * ※PHP4の為にconstは使っていません。 1がガラケーで、2がスマホで4がPCです。
89     * @return
90     */
91    function detectDevice(){
92        $nu = new Net_UserAgent_Mobile();
93        $retDevice = 0;
94        if($nu->isMobile()){
95            $retDevice = 1;
96        }elseif ($nu->isSmartphone()){
97            $retDevice = 2;
98        }else{
99            $retDevice = 4;
100        }
101
102        if($this->autoSet){
103            $this->setDevice($retDevice);
104        }
105        return $retDevice;
106    }
107
108    function assign($val1,$val2){
109        $this->view->assign($val1, $val2);
110    }
111
112    function assignobj($obj){
113        $this->view->assignobj($obj);
114    }
115
116    function assignarray($array){
117        $this->view->assignarray($array);
118    }
119
120
121}
Note: See TracBrowser for help on using the repository browser.