Proyectos de Subversion LeadersLinked - Services

Rev

Rev 17 | Rev 19 | 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
 
18 efrain 51
        $hostname = empty($_SERVER['HTTP_REFERER']) ?  '' : $_SERVER['HTTP_REFERER'];
52
        if(empty($hostname)) {
53
            $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
54
        }
9 efrain 55
 
18 efrain 56
        $hostname = trim(str_replace(['https://', 'http://'], '', $hostname));
57
        $parts = explode('/', $hostname);
58
        $hostname = $parts > 1 ? $parts[0] : $hostname;
17 efrain 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
}