/** * @inheritdoc */ public function run() { $models = StorageItem::find()->all(); $results = []; if (Yii::$app->controller->module->webAccessUrl === false) { foreach ($models as $model) { $filePath = Yii::$app->controller->module->getFilePath($model->file_path); $url = Url::to(['view', 'id' => $model->id]); $fileName = pathinfo($filePath, PATHINFO_FILENAME); $results[] = $this->createEntry($filePath, $url, $fileName); } } else { $onlyExtensions = array_map(function ($ext) { return '*.' . $ext; }, Yii::$app->controller->module->imageAllowedExtensions); $filesPath = FileHelper::findFiles(Yii::$app->controller->module->getStorageDir(), ['recursive' => true, 'only' => $onlyExtensions]); if (is_array($filesPath) && count($filesPath)) { foreach ($filesPath as $filePath) { $url = Yii::$app->controller->module->getUrl(pathinfo($filePath, PATHINFO_BASENAME)); $fileName = pathinfo($filePath, PATHINFO_FILENAME); $results[] = $this->createEntry($filePath, $url, $fileName); } } } return $results; }