Proyectos de Subversion LeadersLinked - Services

Rev

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