FileListWidget::run()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 17
rs 9.9
c 0
b 0
f 0
cc 3
nc 2
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: floor12
5
 * Date: 31.12.2017
6
 * Time: 16:00
7
 */
8
9
namespace floor12\files\components;
10
11
use floor12\files\assets\FileListAsset;
12
use Yii;
13
use yii\base\Widget;
14
use yii\helpers\Url;
15
use yii\web\View;
16
17
18
class FileListWidget extends Widget
19
{
20
    public $files;
21
    public $title;
22
    public $zipTitle = 'files';
23
    public $downloadAll = false;
24
    public $passFirst = false;
25
    public $allowImageSrcDownload = false;
26
    public $lightboxKey;
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function init()
32
    {
33
        if (empty($this->files))
34
            return null;
35
        Yii::$app->getModule('files')->registerTranslations();
36
        if (empty($this->lightboxKey)) {
37
            $this->lightboxKey = $this->files[0]->field . '-' . $this->files[0]->object_id;
38
        }
39
        parent::init();
40
    }
41
42
43
    /**
44
     * @return string|null
45
     */
46
    public function run()
47
    {
48
        FileListAsset::register($this->getView());
49
50
        $this->getView()->registerJs("yiiDownloadAllLink = '" . Url::toRoute('files/default/zip') . "'", View::POS_BEGIN, 'yiiDownloadAllLink');
51
52
        if ($this->passFirst && sizeof($this->files) > 0)
53
            $this->files = array_slice($this->files, 1);
54
55
56
        return $this->render('fileListWidget', [
57
            'files' => $this->files,
58
            'zipTitle' => $this->zipTitle,
59
            'title' => $this->title,
60
            'downloadAll' => $this->downloadAll,
61
            'lightboxKey' => $this->lightboxKey,
62
            'allowImageSrcDownload' => $this->allowImageSrcDownload,
63
        ]);
64
    }
65
}