Commit 552d6af1 by Junaid Rahman pv

added file deletion option in theme,bug fix

parent 37ea8297
...@@ -40,7 +40,7 @@ class ThemeFileController extends \yii\web\Controller ...@@ -40,7 +40,7 @@ class ThemeFileController extends \yii\web\Controller
'type' => 'warning', 'type' => 'warning',
'duration' => 4000, 'duration' => 4000,
'icon' => 'fa fa-file', 'icon' => 'fa fa-file',
'message' => ''.$model->file_code.' Uploading...', 'message' => '' . $model->file_code . ' Uploading...',
'showSeparator' => true, 'showSeparator' => true,
'title' => ' File Upload', 'title' => ' File Upload',
'showProgressbar' => true, 'showProgressbar' => true,
...@@ -63,7 +63,7 @@ class ThemeFileController extends \yii\web\Controller ...@@ -63,7 +63,7 @@ class ThemeFileController extends \yii\web\Controller
exit(); exit();
} }
} else { } else {
Yii::$app->getSession()->setFlash('alert', [ Yii::$app->getSession()->setFlash('alert', [
'type' => 'danger', 'type' => 'danger',
'duration' => 5000, 'duration' => 5000,
'icon' => 'fa fa-envira', 'icon' => 'fa fa-envira',
...@@ -80,10 +80,8 @@ class ThemeFileController extends \yii\web\Controller ...@@ -80,10 +80,8 @@ class ThemeFileController extends \yii\web\Controller
return $this->redirect(['theme/files', 'id' => $model->theme_id]); return $this->redirect(['theme/files', 'id' => $model->theme_id]);
} }
public public function actionEditor($id)
function actionEditor( {
$id
) {
$model = $this->findModel($id); $model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) { if ($model->load(Yii::$app->request->post())) {
$file = yii::getAlias('@storage/private/theme-assets/') . $model->theme_code . '/' . $model->file_code; $file = yii::getAlias('@storage/private/theme-assets/') . $model->theme_code . '/' . $model->file_code;
...@@ -105,10 +103,29 @@ class ThemeFileController extends \yii\web\Controller ...@@ -105,10 +103,29 @@ class ThemeFileController extends \yii\web\Controller
]); ]);
} }
protected public function actionDelete($id)
function findModel( {
$id $model = $this->findModel($id);
) { if ($model->load(Yii::$app->request->post())) {
$file = yii::getAlias('@storage/private/theme-assets/') . $model->theme_code . '/' . $model->file_code;
unlink($file);
$this->findModel($id)->delete();
Yii::$app->getSession()->setFlash('Delete Theme file', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-file',
'message' => ' File successfully Deleted',
'showSeparator' => true,
'title' => ' Theme Files',
'positonY' => 'top',
'positonX' => 'right'
]);
}
return $this->redirect(['theme/files', 'id' => $model->theme_id]);
}
protected function findModel($id)
{
if (($model = ThemeFiles::findOne($id)) !== null) { if (($model = ThemeFiles::findOne($id)) !== null) {
return $model; return $model;
} else { } else {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use yii\bootstrap\Modal; use yii\bootstrap\Modal;
use yii\widgets\ActiveForm;
?> ?>
...@@ -36,11 +37,20 @@ use yii\bootstrap\Modal; ...@@ -36,11 +37,20 @@ use yii\bootstrap\Modal;
?> ?>
<td> <td>
<?php $form = ActiveForm::begin(['action' => '../theme-file/delete?id=' . $fileModel->id]); ?>
<?= $form->field($fileModel,
'theme_id')->hiddenInput(['value' => $model->id])->label(false) ?>
<?= Html::a(' Edit ', ['theme-file/editor', 'id' => $fileModel->id], [ <?= Html::a(' Edit ', ['theme-file/editor', 'id' => $fileModel->id], [
'class' => 'btn btn-primary fa fa-edit', 'class' => 'btn btn-primary fa fa-edit',
]) ?> ]) ?>
<?= Html::submitButton(Yii::t('backend', ' Delete'),
[
'class' => 'btn btn-primary fa fa-trash',
'onclick' => 'return confirm("Are you sure?")'
]) ?>
<?php ActiveForm::end(); ?>
</td> </td>
<?php } else { ?> <?php } else { ?>
......
...@@ -49,7 +49,7 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -49,7 +49,7 @@ $this->params['breadcrumbs'][] = $this->title;
'template' => '{update} {files} {delete}', 'template' => '{update} {files} {delete}',
'buttons' => [ 'buttons' => [
'files' => function ($url) { 'files' => function ($url) {
return Html::a('<span class="fa fa-file"></span>', $url, [ return Html::a(' <span class="fa fa-file"> </span> ', $url, [
'title' => Yii::t('yii', 'Files'), 'title' => Yii::t('yii', 'Files'),
]); ]);
......
...@@ -38,10 +38,10 @@ class m160903_101233_theme extends Migration ...@@ -38,10 +38,10 @@ class m160903_101233_theme extends Migration
$this->createIndex('idx_theme_files_theme_code', '{{%theme_files}}', 'theme_code'); $this->createIndex('idx_theme_files_theme_code', '{{%theme_files}}', 'theme_code');
$this->createIndex('idx_theme_files_file_code', '{{%theme_files}}', 'file_code'); $this->createIndex('idx_theme_files_file_code', '{{%theme_files}}', 'file_code');
$this->addForeignKey('fk_theme_category', '{{%theme}}', 'category_id', '{{%category}}', 'id', 'RESTRICT', $this->addForeignKey('fk_theme_category', '{{%theme}}', 'category_id', '{{%category}}', 'id', 'cascade',
'RESTRICT'); 'cascade');
$this->addForeignKey('fk_theme_files_theme', '{{%theme_files}}', 'theme_code', '{{%theme}}', 'code', 'RESTRICT', $this->addForeignKey('fk_theme_files_theme', '{{%theme_files}}', 'theme_code', '{{%theme}}', 'code', 'cascade',
'RESTRICT'); 'cascade');
$this->addForeignKey('fk_theme_files_category_files', '{{%theme_files}}', 'file_code', '{{%category_files}}', 'code', $this->addForeignKey('fk_theme_files_category_files', '{{%theme_files}}', 'file_code', '{{%category_files}}', 'code',
'cascade', 'cascade'); 'cascade', 'cascade');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment