1 | <?php |
---|
2 | class 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 | /** |
---|
56 | * デバイス毎の出力方法を自動で変更する、ファサード |
---|
57 | * Enter description here ... |
---|
58 | */ |
---|
59 | function setDevice(int $device = 4){ |
---|
60 | switch ($device){ |
---|
61 | case 1: |
---|
62 | $this->response->setContentType("text/html"); |
---|
63 | $this->view = new SC_MobileView(); |
---|
64 | |
---|
65 | break; |
---|
66 | case 2: |
---|
67 | // $this->view = new |
---|
68 | break; |
---|
69 | case 4: |
---|
70 | $this->view = new SC_SiteView(); |
---|
71 | break; |
---|
72 | } |
---|
73 | $this->deviceSeted = true; |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | * 機種を判別する。 |
---|
78 | * SC_Display::MOBILE = ガラケー = 1 |
---|
79 | * SC_Display::SMARTPHONE = スマホ = 2 |
---|
80 | * SC_Display::PC = PC = 4 |
---|
81 | * ※PHP4の為にconstは使っていません。 1がガラケーで、2がスマホで4がPCです。 |
---|
82 | * @return |
---|
83 | */ |
---|
84 | function detectDevice(){ |
---|
85 | $nu = new Net_UserAgent_Mobile(); |
---|
86 | $retDevice = 0; |
---|
87 | if($nu->isMobile()){ |
---|
88 | $retDevice = 1; |
---|
89 | }elseif ($nu->isSmartphone()){ |
---|
90 | $retDevice = 2; |
---|
91 | }else{ |
---|
92 | $retDevice = 4; |
---|
93 | } |
---|
94 | |
---|
95 | if($this->autoSet){ |
---|
96 | $this->setDevice($retDevice); |
---|
97 | } |
---|
98 | return $retDevice; |
---|
99 | } |
---|
100 | |
---|
101 | function assign($val1,$val2){ |
---|
102 | $this->view->assign($val1, $val2); |
---|
103 | } |
---|
104 | |
---|
105 | function assignobj($obj){ |
---|
106 | $this->view->assignobj($obj); |
---|
107 | } |
---|
108 | |
---|
109 | function assignarray($array){ |
---|
110 | $this->view->assignarray($array); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | } |
---|