MobileDetect::__construct()   B
last analyzed

Complexity

Conditions 9
Paths 32

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.0555
c 0
b 0
f 0
cc 9
nc 32
nop 3
1
<?php
2
3
/**
4
 * @copyright Copyright (c) 2011 - 2015 Oleksandr Torosh (http://wezoom.net)
5
 * @author Oleksandr Torosh <[email protected]>
6
 */
7
8
namespace YonaCMS\Plugin;
9
10
class MobileDetect
11
{
12
13
    public function __construct($session, $view, $request)
14
    {
15
        $detect = new \Mobile_Detect();
16
17
        $mobile = $request->getQuery('mobile');
18
        if ($mobile == 'false') {
19
            $session->set('device_detect', 'normal');
20
        }
21
        if ($mobile == 'true') {
22
            $session->set('device_detect', 'mobile');
23
        }
24
25
        $isMobile = false;
26
        $device_detect = $session->get('device_detect');
27
        if (!empty($device_detect)) {
28
            $isMobile = ($device_detect == 'mobile') ? true : false;
29
        } else {
30
            if ($detect->isMobile() && !$detect->isTablet()) {
31
                $isMobile = true;
32
                $session->set('device_detect', 'mobile');
33
            } else {
34
                $session->set('device_detect', 'normal');
35
            }
36
        }
37
38
        define('MOBILE_DEVICE', ($isMobile) ? true : false);
39
40
        if (MOBILE_DEVICE) {
41
            $view->setMainView(MAIN_VIEW_PATH . 'mobile');
42
        }
43
    }
44
45
}