PonthubFileController::download()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace KI\PonthubBundle\Controller;
4
5
use KI\CoreBundle\Controller\SubresourceController;
6
use KI\PonthubBundle\Entity\PonthubFileUser;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9
10
// Surcouche pour les fichiers de type PonthubFile
11
class PonthubFileController extends SubresourceController
12
{
13
    /**
14
     * Enregistre un téléchargement Ponthub et redirige vers la Ressource
15
     * @param  PonthubFile $item Le fichier à télécharger
16
     * @return mixed             La ressource distante
17
     */
18
    protected function download($item)
19
    {
20
        $this->trust(!$this->is('EXTERIEUR'));
21
22
        if (!$item->hasBeenDownloaded()) {
23
            $download = new PonthubFileUser();
24
            $download->setFile($item);
25
            $download->setUser($this->user);
26
            $download->setDate(time());
27
            $this->manager->persist($download);
28
            $this->manager->flush();
29
        }
30
31
        return $this->redirect($item->fileUrl());
32
    }
33
}
34