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