Proyectos de Subversion LeadersLinked - Services

Rev

Rev 1 | Rev 5 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Plugin;
6
 
7
use Laminas\Mvc\Controller\Plugin\AbstractPlugin;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Authentication\AuthenticationService;
10
use LeadersLinked\Model\Device;
11
use LeadersLinked\Mapper\DeviceMapper;
12
use LeadersLinked\Model\UserType;
13
use LeadersLinked\Mapper\NetworkMapper;
14
 
15
 
16
class CurrentNetworkPlugin extends AbstractPlugin
17
{
18
 
19
    /**
20
     *
21
     * @var boolean
22
     */
23
    protected $hasNetwork;
24
 
25
 
26
 
27
    /**
28
     *
29
     * @return \LeadersLinked\Model\Network
30
     */
31
    protected $network;
32
 
33
 
34
    /**
35
     *
36
     * @var string
37
     */
38
    protected $hostname;
39
 
40
    /**
41
     *
42
     * @param AdapterInterface $adapter
43
     */
44
    public function __construct($adapter)
45
    {
46
 
47
        $this->hasNetwork = false;
48
        $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
49
        //$hostname = str_replace('www.', '', $hostname);
50
 
51
 
3 efrain 52
        echo '<pre>';
53
        print_r($_SERVER);
54
        echo '</pre>';
55
        //echo $_SERVER['HTTP_ORIGIN'];
56
        exit;
1 efrain 57
 
3 efrain 58
 
59
 
1 efrain 60
        $networkMapper = NetworkMapper::getInstance($adapter);
61
        $this->network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
62
 
63
 
64
        if($this->network) {
65
 
66
            $this->hostname = $this->network->main_hostname == $hostname ?  $this->network->main_hostname : $this->network->alternative_hostname;
67
            $this->hasNetwork = true;
68
        }
69
 
70
    }
71
 
72
 
73
 
74
 
75
    /**
76
     *
77
     * @return \LeadersLinked\Model\Network
78
     */
79
    public function getNetwork()
80
    {
81
 
82
        if($this->hasNetwork) {
83
            return $this->network;
84
        } else {
85
 
86
            return null;
87
        }
88
    }
89
 
90
 
91
    /**
92
     *
93
     * @return int
94
     */
95
    public function getNetworkId()
96
    {
97
        if($this->hasNetwork) {
98
           return $this->network->id;
99
 
100
        } else {
101
            return 0;
102
        }
103
    }
104
 
105
 
106
    /**
107
     *
108
     * @return boolean
109
     */
110
    public function hasNetwork()
111
    {
112
        return $this->hasNetwork;
113
    }
114
 
115
 
116
    public function getHostname() : string
117
    {
118
        return  $this->hostname;
119
    }
120
 
121
 
122
 
123
}