Proyectos de Subversion LeadersLinked - Services

Rev

Rev 8 | Rev 10 | 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;
5 efrain 48
 
1 efrain 49
 
50
 
5 efrain 51
        //$hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
52
        $hostname = empty($_SERVER['HTTP_ORIGIN']) ?  '' : $_SERVER['HTTP_ORIGIN'];
9 efrain 53
 
54
 
8 efrain 55
        //$hostname = 'dev.leaderslinked.com';
5 efrain 56
        //$hostname = str_replace('www.', '', $hostname);
3 efrain 57
 
1 efrain 58
        $networkMapper = NetworkMapper::getInstance($adapter);
59
        $this->network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
60
 
61
 
62
        if($this->network) {
63
 
64
            $this->hostname = $this->network->main_hostname == $hostname ?  $this->network->main_hostname : $this->network->alternative_hostname;
65
            $this->hasNetwork = true;
66
        }
67
 
68
    }
69
 
70
 
71
 
72
 
73
    /**
74
     *
75
     * @return \LeadersLinked\Model\Network
76
     */
77
    public function getNetwork()
78
    {
79
 
80
        if($this->hasNetwork) {
81
            return $this->network;
82
        } else {
83
 
84
            return null;
85
        }
86
    }
87
 
88
 
89
    /**
90
     *
91
     * @return int
92
     */
93
    public function getNetworkId()
94
    {
95
        if($this->hasNetwork) {
96
           return $this->network->id;
97
 
98
        } else {
99
            return 0;
100
        }
101
    }
102
 
103
 
104
    /**
105
     *
106
     * @return boolean
107
     */
108
    public function hasNetwork()
109
    {
110
        return $this->hasNetwork;
111
    }
112
 
113
 
114
    public function getHostname() : string
115
    {
116
        return  $this->hostname;
117
    }
118
 
119
 
120
 
121
}