Passed
Push — master ( d1ffd7...dce5af )
by Aleksandr
09:17
created

DefaultController::actionIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 3
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace carono\exchange1c\controllers;
5
6
7
use yii\data\ArrayDataProvider;
8
use yii\helpers\FileHelper;
9
10
/**
11
 * Class DefaultController
12
 *
13
 * @package carono\exchange1c\controllers
14
 */
15
class DefaultController extends Controller
16
{
17
    /**
18
     * @return string
19
     */
20
    public function actionIndex()
21
    {
22
        return $this->render('index');
23
    }
24
25
    /**
26
     * @return string
27
     */
28
    public function actionFiles()
29
    {
30
        $data = [];
31
        $dir = $this->module->getTmpDir();
32
        foreach (FileHelper::findFiles($dir) as $file) {
33
            $data[] = ['filename' => substr($file, strlen($dir) + 1), 'size' => filesize($file)];
34
        }
35
        $dataProvider = new ArrayDataProvider(['allModels' => $data]);
36
        return $this->render('files', ['dataProvider' => $dataProvider]);
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function actionImport()
43
    {
44
        return $this->render('import');
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function actionExport()
51
    {
52
        return $this->render('export');
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function actionMonitor()
59
    {
60
        return $this->render('monitor');
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function actionDocumentation()
67
    {
68
        $dir = \Yii::getAlias('@vendor/carono/yii2-1c-exchange/files/doc');
69
        $data = [];
70
        foreach (FileHelper::findFiles($dir) as $file) {
71
            $data[] = ['filename' => substr($file, strlen($dir) + 1), 'size' => filesize($file)];
72
        }
73
        $dataProvider = new ArrayDataProvider(['allModels' => $data]);
74
        return $this->render('documentation', ['dataProvider' => $dataProvider]);
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function actionInterfaces()
81
    {
82
        return $this->render('interfaces');
83
    }
84
85
    /**
86
     * @param $file
87
     */
88
    public function actionDownload($file)
89
    {
90
        $content = file_get_contents($this->module->getTmpDir($file));
91
        \Yii::$app->response->sendContentAsFile($content, basename($file));
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function actionSettings()
98
    {
99
        return $this->render('settings');
100
    }
101
102
    /**
103
     * @return \yii\web\Response
104
     */
105
    public function actionClearTmp()
106
    {
107
        foreach (FileHelper::findFiles($this->module->getTmpDir()) as $file) {
108
            unlink($file);
109
        }
110
        return $this->redirect(\Yii::$app->request->referrer);
111
    }
112
}