Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6749 | Rev 6860 | Ir a la última revisión | | 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
     *
16
     * @var AdapterInterface
17
     */
18
    private $adapter;
19
 
20
    /**
21
     *
22
     * @var  LoggerInterface
23
     */
24
    private $logger;
25
 
26
 
27
    /**
28
     *
29
     * @var array
30
     */
31
    private $config;
32
 
33
    /**
34
     *
35
     * @param AdapterInterface $adapter
36
     * @param LoggerInterface $logger
37
     * @param array $config
38
     */
39
    public function __construct($adapter, $cache , $logger, $config)
40
    {
41
        $this->adapter      = $adapter;
42
        $this->logger       = $logger;
43
        $this->config       = $config;
44
    }
45
 
46
    public function downloadAction()
47
    {
48
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
49
        $currentNetwork = $currentNetworkPlugin->getNetwork();
50
 
51
 
52
        $path = $this->config['leaderslinked.fullpath.network'];
53
 
54
 
55
        $type = $this->params()->fromRoute('type', 'logo');
56
        if($type == 'favico') {
57
            $filename = 'favico.png';
58
        } else  if($type == 'navbar') {
59
            $filename = 'navbar.png';
5848 efrain 60
        } else  if($type == 'moodle') {
61
            $filename = 'moodle.png';
3639 efrain 62
        } else {
63
            $filename = 'logo.png';
64
        }
65
 
66
 
67
        $request_fullpath = $path . $currentNetwork->uuid . DIRECTORY_SEPARATOR . $filename;
68
 
69
 
70
        if(!file_exists($request_fullpath)) {
71
            $request_fullpath = $this->config['leaderslinked.images_default.no_image'];
72
        }
73
 
74
 
75
        if(file_exists($request_fullpath)) {
76
            if (!is_readable($request_fullpath)) {
77
                return $this->getResponse()->setStatusCode(500);
78
            }
79
 
80
            $fileSize = filesize($request_fullpath);
81
 
82
            $mimeType = mime_content_type($request_fullpath);
83
            if($mimeType===false) {
84
                $mimeType = 'application/octet-stream';
85
            }
86
 
87
            $fileContent = file_get_contents($request_fullpath);
88
 
89
            $response = $this->getResponse();
90
            $headers = $response->getHeaders();
91
            $headers->addHeaderLine('Content-type: ' . $mimeType);
92
            $headers->addHeaderLine('Content-length: ' . $fileSize);
93
 
94
            if($fileContent!==false) {
95
                $response->setContent($fileContent);
96
            } else {
97
                $this->getResponse()->setStatusCode(500);
98
                return;
99
            }
100
        } else {
101
            return $this->getResponse()->setStatusCode(404);
102
        }
103
 
104
        return $this->getResponse();
105
    }
106
 
107
}