|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Itstructure\MFUploader\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use yii\helpers\BaseUrl; |
|
6
|
|
|
use yii\data\{ActiveDataProvider, Pagination}; |
|
7
|
|
|
use yii\base\InvalidArgumentException; |
|
|
|
|
|
|
8
|
|
|
use yii\filters\{VerbFilter, AccessControl}; |
|
9
|
|
|
use yii\web\{Controller, BadRequestHttpException}; |
|
10
|
|
|
use Itstructure\MFUploader\Module; |
|
11
|
|
|
use Itstructure\MFUploader\models\{OwnerMediafile, Mediafile}; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class ManagerController |
|
15
|
|
|
* Manager controller class to display the next managers: |
|
16
|
|
|
* 1. To view and select available files. |
|
17
|
|
|
* 2. To upload files. |
|
18
|
|
|
* |
|
19
|
|
|
* @property Module $module |
|
20
|
|
|
* |
|
21
|
|
|
* @package Itstructure\MFUploader\controllers |
|
22
|
|
|
* |
|
23
|
|
|
* @author Andrey Girnik <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class ManagerController extends Controller |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Initialize. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function init() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->layout = '@'.Module::MODULE_NAME.'/views/layouts/main'; |
|
33
|
|
|
|
|
34
|
|
|
parent::init(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
|
|
public function behaviors() |
|
41
|
|
|
{ |
|
42
|
|
|
return [ |
|
43
|
|
|
'access' => [ |
|
44
|
|
|
'class' => AccessControl::class, |
|
45
|
|
|
'rules' => [ |
|
46
|
|
|
[ |
|
47
|
|
|
'allow' => true, |
|
48
|
|
|
'roles' => $this->module->accessRoles, |
|
49
|
|
|
], |
|
50
|
|
|
], |
|
51
|
|
|
], |
|
52
|
|
|
'verbs' => [ |
|
53
|
|
|
'class' => VerbFilter::class, |
|
54
|
|
|
'actions' => [ |
|
55
|
|
|
'filemanager' => ['GET'], |
|
56
|
|
|
'uploadmanager' => ['GET'], |
|
57
|
|
|
], |
|
58
|
|
|
], |
|
59
|
|
|
]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get filemanager with uploaded files. |
|
64
|
|
|
* |
|
65
|
|
|
* @throws BadRequestHttpException |
|
66
|
|
|
* |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
public function actionFilemanager() |
|
70
|
|
|
{ |
|
71
|
|
|
try { |
|
72
|
|
|
$request = \Yii::$app->request; |
|
73
|
|
|
|
|
74
|
|
|
$requestParams = []; |
|
75
|
|
|
|
|
76
|
|
|
if ((null !== $request->get('owner') && null !== $request->get('ownerId'))) { |
|
77
|
|
|
$requestParams['owner'] = $request->get('owner'); |
|
78
|
|
|
$requestParams['ownerId'] = $request->get('ownerId'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if ((null !== $request->get('ownerAttribute') && null !== $request->get('ownerAttribute'))) { |
|
82
|
|
|
$requestParams['ownerAttribute'] = $request->get('ownerAttribute'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (count($requestParams) > 0) { |
|
86
|
|
|
$query = OwnerMediafile::getMediaFilesQuery($requestParams)->orWhere([ |
|
87
|
|
|
'not in', 'id', OwnerMediafile::find()->select('mediafileId')->asArray() |
|
88
|
|
|
]); |
|
89
|
|
|
} else { |
|
90
|
|
|
$query = Mediafile::find()->where([ |
|
91
|
|
|
'not in', 'id', OwnerMediafile::find()->select('mediafileId')->asArray() |
|
92
|
|
|
])->orderBy('id DESC'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$pagination = new Pagination([ |
|
96
|
|
|
'defaultPageSize' => 12, |
|
97
|
|
|
'totalCount' => $query->count(), |
|
98
|
|
|
]); |
|
99
|
|
|
|
|
100
|
|
|
$dataProvider = new ActiveDataProvider([ |
|
101
|
|
|
'query' => $query, |
|
102
|
|
|
'pagination' => $pagination |
|
103
|
|
|
]); |
|
104
|
|
|
|
|
105
|
|
|
BaseUrl::remember($request->getAbsoluteUrl(), Module::BACK_URL_PARAM); |
|
106
|
|
|
|
|
107
|
|
|
return $this->render('filemanager', [ |
|
108
|
|
|
'dataProvider' => $dataProvider, |
|
109
|
|
|
'pagination' => $pagination, |
|
110
|
|
|
'manager' => 'filemanager', |
|
111
|
|
|
]); |
|
112
|
|
|
} catch (\Exception|InvalidArgumentException $e) { |
|
113
|
|
|
throw new BadRequestHttpException($e->getMessage(), $e->getCode()); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Get uploadmanager for uploading files. |
|
119
|
|
|
* |
|
120
|
|
|
* @throws BadRequestHttpException |
|
121
|
|
|
* |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
public function actionUploadmanager() |
|
125
|
|
|
{ |
|
126
|
|
|
try { |
|
127
|
|
|
return $this->render('uploadmanager', [ |
|
128
|
|
|
'manager' => 'uploadmanager', |
|
129
|
|
|
'fileAttributeName' => $this->module->fileAttributeName, |
|
130
|
|
|
'sendUrl' => Module::getSendUrl($this->module->defaultStorageType), |
|
131
|
|
|
'deleteUrl' => Module::getDeleteUrl($this->module->defaultStorageType), |
|
132
|
|
|
]); |
|
133
|
|
|
} catch (\Exception $e) { |
|
134
|
|
|
throw new BadRequestHttpException($e->getMessage(), $e->getCode()); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths