Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6860 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3639 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Db\Adapter\AdapterInterface;
6849 efrain 7
 
3639 efrain 8
use Laminas\Mvc\Controller\AbstractActionController;
9
use Laminas\Log\LoggerInterface;
10
 
11
 
12
class StorageNetworkController extends AbstractActionController
13
{
14
    /**
15
     *
6866 efrain 16
     * @var \Laminas\Db\Adapter\AdapterInterface
3639 efrain 17
     */
18
    private $adapter;
19
 
20
    /**
21
     *
6866 efrain 22
     * @var \LeadersLinked\Cache\CacheInterface
3639 efrain 23
     */
6866 efrain 24
    private $cache;
25
 
26
 
27
    /**
28
     *
29
     * @var \Laminas\Log\LoggerInterface
30
     */
3639 efrain 31
    private $logger;
32
 
33
    /**
34
     *
35
     * @var array
36
     */
37
    private $config;
38
 
6866 efrain 39
 
3639 efrain 40
    /**
41
     *
6866 efrain 42
     * @var \Laminas\Mvc\I18n\Translator
43
     */
44
    private $translator;
45
 
46
 
47
    /**
48
     *
49
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
50
     * @param \LeadersLinked\Cache\CacheInterface $cache
51
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
3639 efrain 52
     * @param array $config
6866 efrain 53
     * @param \Laminas\Mvc\I18n\Translator $translator
3639 efrain 54
     */
6866 efrain 55
    public function __construct($adapter, $cache, $logger, $config, $translator)
3639 efrain 56
    {
57
        $this->adapter      = $adapter;
6866 efrain 58
        $this->cache        = $cache;
3639 efrain 59
        $this->logger       = $logger;
60
        $this->config       = $config;
6866 efrain 61
        $this->translator   = $translator;
3639 efrain 62
    }
63
 
64
    public function downloadAction()
65
    {
66
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
67
        $currentNetwork = $currentNetworkPlugin->getNetwork();
68
 
69
 
70
        $path = $this->config['leaderslinked.fullpath.network'];
71
 
72
 
73
        $type = $this->params()->fromRoute('type', 'logo');
74
        if($type == 'favico') {
75
            $filename = 'favico.png';
76
        } else  if($type == 'navbar') {
77
            $filename = 'navbar.png';
5848 efrain 78
        } else  if($type == 'moodle') {
79
            $filename = 'moodle.png';
3639 efrain 80
        } else {
81
            $filename = 'logo.png';
82
        }
83
 
84
 
85
        $request_fullpath = $path . $currentNetwork->uuid . DIRECTORY_SEPARATOR . $filename;
86
 
87
 
88
        if(!file_exists($request_fullpath)) {
89
            $request_fullpath = $this->config['leaderslinked.images_default.no_image'];
90
        }
91
 
92
 
93
        if(file_exists($request_fullpath)) {
94
            if (!is_readable($request_fullpath)) {
95
                return $this->getResponse()->setStatusCode(500);
96
            }
97
 
98
            $fileSize = filesize($request_fullpath);
99
 
100
            $mimeType = mime_content_type($request_fullpath);
101
            if($mimeType===false) {
102
                $mimeType = 'application/octet-stream';
103
            }
104
 
105
            $fileContent = file_get_contents($request_fullpath);
106
 
107
            $response = $this->getResponse();
108
            $headers = $response->getHeaders();
109
            $headers->addHeaderLine('Content-type: ' . $mimeType);
110
            $headers->addHeaderLine('Content-length: ' . $fileSize);
111
 
112
            if($fileContent!==false) {
113
                $response->setContent($fileContent);
114
            } else {
115
                $this->getResponse()->setStatusCode(500);
116
                return;
117
            }
118
        } else {
119
            return $this->getResponse()->setStatusCode(404);
120
        }
121
 
122
        return $this->getResponse();
123
    }
124
 
125
}