Proyectos de Subversion LeadersLinked - Services

Rev

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