carono /
yii2-1c-exchange
| 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 | public function actionIndex() |
||
| 18 | { |
||
| 19 | return $this->render('index'); |
||
| 20 | } |
||
| 21 | |||
| 22 | public function actionFiles() |
||
| 23 | { |
||
| 24 | $data = []; |
||
| 25 | $dir = $this->module->getTmpDir(); |
||
| 26 | foreach (FileHelper::findFiles($dir) as $file) { |
||
| 27 | $data[] = ['filename' => substr($file, strlen($dir) + 1), 'size' => filesize($file)]; |
||
| 28 | } |
||
| 29 | $dataProvider = new ArrayDataProvider(['allModels' => $data]); |
||
| 30 | return $this->render('files', ['dataProvider' => $dataProvider]); |
||
| 31 | } |
||
| 32 | |||
| 33 | public function actionImport() |
||
| 34 | { |
||
| 35 | if (\Yii::$app->request->isPost) { |
||
| 36 | |||
| 37 | } |
||
| 38 | return $this->render('import'); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function actionExport() |
||
| 42 | { |
||
| 43 | return $this->render('export'); |
||
| 44 | } |
||
| 45 | |||
| 46 | public function actionMonitor() |
||
| 47 | { |
||
| 48 | return $this->render('monitor'); |
||
| 49 | } |
||
| 50 | |||
| 51 | public function actionDocumentation() |
||
| 52 | { |
||
| 53 | $dir = \Yii::getAlias('@vendor/carono/yii2-1c-exchange/files/doc'); |
||
| 54 | $data = []; |
||
| 55 | foreach (FileHelper::findFiles($dir) as $file) { |
||
| 56 | $data[] = ['filename' => substr($file, strlen($dir) + 1), 'size' => filesize($file)]; |
||
| 57 | } |
||
| 58 | $dataProvider = new ArrayDataProvider(['allModels' => $data]); |
||
| 59 | return $this->render('documentation', ['dataProvider' => $dataProvider]); |
||
| 60 | } |
||
| 61 | |||
| 62 | public function actionInterfaces() |
||
| 63 | { |
||
| 64 | return $this->render('interfaces'); |
||
| 65 | } |
||
| 66 | |||
| 67 | public function actionDownload($file) |
||
| 68 | { |
||
| 69 | $content = file_get_contents($this->module->getTmpDir($file)); |
||
| 70 | return \Yii::$app->response->sendContentAsFile($content, basename($file)); |
||
| 71 | } |
||
| 72 | |||
| 73 | public function actionSettings() |
||
| 74 | { |
||
| 75 | return $this->render('settings'); |
||
| 76 | } |
||
| 77 | |||
| 78 | public function actionClearTmp() |
||
| 79 | { |
||
| 80 | foreach (FileHelper::findFiles($this->module->getTmpDir()) as $file) { |
||
| 81 | @unlink($file); |
||
|
0 ignored issues
–
show
|
|||
| 82 | } |
||
| 83 | return $this->redirect(\Yii::$app->request->referrer); |
||
| 84 | } |
||
| 85 | } |
If you suppress an error, we recommend checking for the error condition explicitly: