Commit 37ea8297 by Junaid Rahman pv

bug fixing

parent 5975a46b
...@@ -70,6 +70,16 @@ class DistrictController extends Controller ...@@ -70,6 +70,16 @@ class DistrictController extends Controller
$states = ArrayHelper::map(State::find()->all(), 'id', 'name'); $states = ArrayHelper::map(State::find()->all(), 'id', 'name');
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('districtCreate', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-map',
'message' => ' New District added',
'showSeparator' => true,
'title' => ' District',
'positonY' => 'top',
'positonX' => 'right'
]);
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect(['view', 'id' => $model->id]);
} else { } else {
return $this->render('create', [ return $this->render('create', [
......
...@@ -66,6 +66,16 @@ class StateController extends Controller ...@@ -66,6 +66,16 @@ class StateController extends Controller
$model = new State(); $model = new State();
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('stateCreate', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-map',
'message' => ' New State added',
'showSeparator' => true,
'title' => ' State',
'positonY' => 'top',
'positonX' => 'right'
]);
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect(['view', 'id' => $model->id]);
} else { } else {
return $this->render('create', [ return $this->render('create', [
......
...@@ -72,11 +72,11 @@ class CategoryController extends Controller ...@@ -72,11 +72,11 @@ class CategoryController extends Controller
Yii::$app->getSession()->setFlash('success', [ Yii::$app->getSession()->setFlash('success', [
'type' => 'success', 'type' => 'success',
'duration' => 5000, 'duration' => 5000,
'icon' => 'fa fa-envira', 'icon' => 'fa fa-sitemap',
'message' => 'New Theme Category Created! ', 'message' => 'New Category '.$model->name.' is Created! ',
'title' => 'Category', 'title' => 'Category',
'positonY' => 'top', 'positonY' => 'top',
'positonX' => 'right' 'positonX' => 'center'
]); ]);
return $this->redirect(['files', 'id' => $model->id]); return $this->redirect(['files', 'id' => $model->id]);
} }
...@@ -99,7 +99,16 @@ class CategoryController extends Controller ...@@ -99,7 +99,16 @@ class CategoryController extends Controller
$model = $this->findModel($id); $model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save() && $model->validate()) { if ($model->load(Yii::$app->request->post()) && $model->save() && $model->validate()) {
return $this->redirect(['view', 'id' => $model->id]); Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-sitemap',
'message' => 'Category '. $model->name .' Updated! ',
'title' => 'Category',
'positonY' => 'top',
'positonX' => 'right'
]);
return $this->redirect(['files', 'id' => $model->id]);
} }
return $this->render('update', [ return $this->render('update', [
...@@ -139,7 +148,6 @@ class CategoryController extends Controller ...@@ -139,7 +148,6 @@ class CategoryController extends Controller
if (Model::loadMultiple($models, Yii::$app->request->post())) { if (Model::loadMultiple($models, Yii::$app->request->post())) {
$deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($models, 'id', 'id'))); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($models, 'id', 'id')));
if (Model::validateMultiple($models)) { if (Model::validateMultiple($models)) {
$transaction = \Yii::$app->db->beginTransaction(); $transaction = \Yii::$app->db->beginTransaction();
...@@ -159,15 +167,6 @@ class CategoryController extends Controller ...@@ -159,15 +167,6 @@ class CategoryController extends Controller
if ($flag) { if ($flag) {
$transaction->commit(); $transaction->commit();
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-file',
'message' => 'New File is added to Category Files list! ',
'title' => 'Category Files',
'positonY' => 'top',
'positonX' => 'right'
]);
} }
} catch (Exception $e) { } catch (Exception $e) {
$transaction->rollBack(); $transaction->rollBack();
......
...@@ -73,7 +73,16 @@ class ThemeController extends Controller ...@@ -73,7 +73,16 @@ class ThemeController extends Controller
$model = new Theme(); $model = new Theme();
$model->status = $model::STATUS_ACTIVE; $model->status = $model::STATUS_ACTIVE;
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]); Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-envira',
'message' => 'New Theme '.$model->name.' is Created! ',
'title' => ' Theme',
'positonY' => 'top',
'positonX' => 'center'
]);
return $this->redirect(['files', 'id' => $model->id]);
} }
return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
...@@ -94,6 +103,15 @@ class ThemeController extends Controller ...@@ -94,6 +103,15 @@ class ThemeController extends Controller
$model = $this->findModel($id); $model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-envira',
'message' => 'Theme '. $model->name .' Updated! ',
'title' => 'Theme',
'positonY' => 'top',
'positonX' => 'right'
]);
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect(['view', 'id' => $model->id]);
} else { } else {
return $this->render('update', [ return $this->render('update', [
......
...@@ -4,7 +4,6 @@ namespace backend\modules\theme\controllers; ...@@ -4,7 +4,6 @@ namespace backend\modules\theme\controllers;
use common\models\ThemeFiles; use common\models\ThemeFiles;
use yii; use yii;
use common\models\Theme;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\web\UploadedFile; use yii\web\UploadedFile;
...@@ -14,6 +13,7 @@ class ThemeFileController extends \yii\web\Controller ...@@ -14,6 +13,7 @@ class ThemeFileController extends \yii\web\Controller
{ {
return $this->render('index'); return $this->render('index');
} }
public function actionUpload() public function actionUpload()
{ {
$model = new ThemeFiles(); $model = new ThemeFiles();
...@@ -24,37 +24,91 @@ class ThemeFileController extends \yii\web\Controller ...@@ -24,37 +24,91 @@ class ThemeFileController extends \yii\web\Controller
// the following data will return an array // the following data will return an array
$theme_file = UploadedFile::getInstance($model, 'file'); $theme_file = UploadedFile::getInstance($model, 'file');
// the path to save file, $model->file = $theme_file;
$folderPath = yii::getAlias('@storage/private/theme-assets/') .$model->theme_code; $ext = $model->file->extension;
if ( ! is_dir($folderPath)) { $allowed = array('js', 'css', 'html');
mkdir($folderPath); if (in_array($ext, $allowed)) {
} // the path to save file,
$path = $folderPath.'/'.$model->file_code; $folderPath = yii::getAlias('@storage/private/theme-assets/') . $model->theme_code;
if ($model->save(false)) { if (!is_dir($folderPath)) {
$theme_file->saveAs($path); mkdir($folderPath);
}
$path = $folderPath . '/' . $model->file_code;
if ($model->save(false)) {
$model->file->saveAs($path);
Yii::$app->getSession()->setFlash($model->file_code, [
'type' => 'warning',
'duration' => 4000,
'icon' => 'fa fa-file',
'message' => ''.$model->file_code.' Uploading...',
'showSeparator' => true,
'title' => ' File Upload',
'showProgressbar' => true,
'positonY' => 'top',
'positonX' => 'right'
]);
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-file',
'message' => ' File successfully Uploaded',
'showSeparator' => true,
'title' => ' File Upload',
'delay' => 4000,
'positonY' => 'top',
'positonX' => 'right'
]);
} else {
echo 'Error';
exit();
}
} else { } else {
echo 'Error'; Yii::$app->getSession()->setFlash('alert', [
exit(); 'type' => 'danger',
'duration' => 5000,
'icon' => 'fa fa-envira',
'message' => 'File type miss match! ',
'showSeparator' => true,
'title' => 'Error',
'showProgressbar' => true,
'positonY' => 'top',
'positonX' => 'right'
]);
} }
} }
return $this->redirect(['theme/index']); return $this->redirect(['theme/files', 'id' => $model->theme_id]);
} }
public function actionEditor($id) public
{ 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;
file_put_contents($file, $model->fileContent); file_put_contents($file, $model->fileContent);
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-file',
'message' => ' File Saved',
'showSeparator' => true,
'title' => ' Code Editor',
'positonY' => 'top',
'positonX' => 'right'
]);
} }
return $this->render('editor',[
'model' => $model, return $this->render('editor', [
'model' => $model,
]); ]);
} }
protected function findModel($id) protected
{ function findModel(
$id
) {
if (($model = ThemeFiles::findOne($id)) !== null) { if (($model = ThemeFiles::findOne($id)) !== null) {
return $model; return $model;
} else { } else {
......
...@@ -45,19 +45,14 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -45,19 +45,14 @@ $this->params['breadcrumbs'][] = $this->title;
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}', 'template' => '{update} {files} {delete}',
'buttons' => [ 'buttons' => [
'download' => function ($url) { 'files' => function ($url) {
return Html::a( return Html::a('<span class="fa fa-file"></span>', $url, [
'<span class="glyphicon glyphicon-arrow-download"></span>', 'title' => Yii::t('yii', 'Files'),
$url, ]);
[ }
'title' => 'Download', ]
'data-pjax' => '0',
]
);
},
],
], ],
], ],
]); ?> ]); ?>
......
...@@ -75,8 +75,7 @@ use wbraganca\dynamicform\DynamicFormWidget; ...@@ -75,8 +75,7 @@ use wbraganca\dynamicform\DynamicFormWidget;
</div> </div>
<div class="col-sm-4"> <div class="col-sm-4">
<?= $form->field($model, "[{$i}]type")->dropDownList($model::getfiles(), <?= $form->field($model, "[{$i}]type")->dropDownList($model::getfiles()) ?>
['prompt' => '']) ?>
</div> </div>
</div> </div>
......
...@@ -65,7 +65,11 @@ use yii\bootstrap\Modal; ...@@ -65,7 +65,11 @@ use yii\bootstrap\Modal;
<div id='modalContent'<?= $value['id'] ?> style="text-align: center"> <div id='modalContent'<?= $value['id'] ?> style="text-align: center">
<?= $this->render('upload', ['model' => $modelFiles[0],]) ?> <?= $this->render('upload',
[
'model' => $modelFiles[0],
'ThemeId' => $model->id,
]) ?>
</div> </div>
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
/* @var $model common\models\ThemeFiles */ /* @var $model common\models\ThemeFiles */
/* @var $ThemeId id of theme */
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use yii\bootstrap\Html; use yii\bootstrap\Html;
...@@ -25,19 +26,21 @@ use yii\bootstrap\Html; ...@@ -25,19 +26,21 @@ use yii\bootstrap\Html;
<div class="col-md-11"> <div class="col-md-11">
<?= $form->field($model, 'file')->fileInput(['class' => 'btn btn-default']) ?> <?= $form->field($model, 'file')->fileInput(['class' => 'btn btn-default']) ?>
</div> </div>
<div class="col-md-11"> <div class="col-md-11">
<?= $form->field($model, 'file_code')->hiddenInput(['value' => $model->file_code])->label(false) ?> <?= $form->field($model, 'file_code')->hiddenInput(['value' => $model->file_code])->label(false) ?>
</div> </div>
<div class="col-md-11"> <div class="col-md-11">
<?= $form->field($model, 'theme_code')->hiddenInput(['value' => $model->theme_code])->label(false) ?> <?= $form->field($model, 'theme_code')->hiddenInput(['value' => $model->theme_code])->label(false) ?>
</div>
<div class="col-md-11">
<?= $form->field($model, 'theme_id')->hiddenInput(['value' => $ThemeId])->label(false) ?>
</div> </div>
</div> </div>
......
...@@ -57,7 +57,7 @@ use yii\bootstrap\ActiveForm; ...@@ -57,7 +57,7 @@ use yii\bootstrap\ActiveForm;
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<?= $form->field($model, 'status')->dropDownList($model::statuses(), ['prompt' => '']) ?> <?= $form->field($model, 'status')->dropDownList($model::statuses()) ?>
</div> </div>
</div> </div>
......
...@@ -18,8 +18,8 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -18,8 +18,8 @@ $this->params['breadcrumbs'][] = $this->title;
<p> <p>
<?= Html::a(Yii::t('backend', 'Create {modelClass}', [ <?= Html::a(Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'Theme', 'modelClass' => 'Theme',
]), ['create'], ['class' => 'btn btn-success']) ?> ]), ['create'], ['class' => 'btn btn-success']) ?>
</p> </p>
<?= GridView::widget([ <?= GridView::widget([
...@@ -44,11 +44,18 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -44,11 +44,18 @@ $this->params['breadcrumbs'][] = $this->title;
// 'created_at', // 'created_at',
// 'updated_at', // 'updated_at',
['class' => 'yii\grid\ActionColumn' [
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {files} {delete}',
'buttons' => [
'files' => function ($url) {
return Html::a('<span class="fa fa-file"></span>', $url, [
'title' => Yii::t('yii', 'Files'),
]);
}
]
], ],
// ['class' => 'yii\grid\ActionColumn',
// 'template' => '{update}{delete}'],
], ],
]); ?> ]); ?>
......
...@@ -342,12 +342,13 @@ $bundle = BackendAsset::register($this); ...@@ -342,12 +342,13 @@ $bundle = BackendAsset::register($this);
<?php foreach (Yii::$app->session->getAllFlashes() as $message):; ?> <?php foreach (Yii::$app->session->getAllFlashes() as $message):; ?>
<?= Growl::widget([ <?= Growl::widget([
'type' => (!empty($message['type'])) ? $message['type'] : 'danger', 'type' => (!empty($message['type'])) ? $message['type'] : 'danger',
'title' => (!empty($message['title'])) ? Html::encode($message['title']) : 'Title Not Set!', 'title' => (!empty($message['title'])) ? Html::encode($message['title']) : 'Libromi Web!',
'icon' => (!empty($message['icon'])) ? $message['icon'] : 'fa fa-info', 'icon' => (!empty($message['icon'])) ? $message['icon'] : 'fa fa-info',
'body' => (!empty($message['message'])) ? Html::encode($message['message']) : 'Message Not Set!', 'body' => (!empty($message['message'])) ? Html::encode($message['message']) : 'Welcome to Libromi Web!',
'showSeparator' => true, 'showSeparator' => true,
'delay' => 1, //This delay is how long before the message shows 'delay' => (!empty($message['delay'])) ? Html::encode($message['delay']) : 1, //This delay is how long before the message shows
'pluginOptions' => [ 'pluginOptions' => [
'showProgressbar' => (!empty($message['showProgressbar'])) ? Html::encode($message['showProgressbar']) : false,
'delay' => (!empty($message['duration'])) ? $message['duration'] : 3000, //This delay is how long the message shows for 'delay' => (!empty($message['duration'])) ? $message['duration'] : 3000, //This delay is how long the message shows for
'placement' => [ 'placement' => [
'from' => (!empty($message['positonY'])) ? $message['positonY'] : 'top', 'from' => (!empty($message['positonY'])) ? $message['positonY'] : 'top',
......
...@@ -40,13 +40,13 @@ class m160830_105840_category extends Migration ...@@ -40,13 +40,13 @@ class m160830_105840_category extends Migration
$this->createIndex('idx_category_files_code', '{{%category_files}}', 'code'); $this->createIndex('idx_category_files_code', '{{%category_files}}', 'code');
$this->createIndex('idx_category_files_name', '{{%category_files}}', 'name'); $this->createIndex('idx_category_files_name', '{{%category_files}}', 'name');
$this->addForeignKey('fk_category', '{{%category_files}}', 'category_id', '{{%category}}', 'id', 'RESTRICT', $this->addForeignKey('fk_category_files_category', '{{%category_files}}', 'category_id', '{{%category}}', 'id', 'cascade',
'RESTRICT'); 'cascade');
} }
public function safeDown() public function safeDown()
{ {
$this->dropForeignKey('fk_category', '{{%category_files}}'); $this->dropForeignKey('fk_category_files_category', '{{%category_files}}');
$this->dropIndex('idx_category_files_name', '{{%category_files}}'); $this->dropIndex('idx_category_files_name', '{{%category_files}}');
$this->dropIndex('idx_category_files_code', '{{%category_files}}'); $this->dropIndex('idx_category_files_code', '{{%category_files}}');
......
...@@ -137,4 +137,5 @@ class Category extends \yii\db\ActiveRecord ...@@ -137,4 +137,5 @@ class Category extends \yii\db\ActiveRecord
]; ];
} }
} }
...@@ -93,4 +93,5 @@ class CategoryFiles extends \yii\db\ActiveRecord ...@@ -93,4 +93,5 @@ class CategoryFiles extends \yii\db\ActiveRecord
self::TYPE_HTML_BLOCK => Yii::t('common', 'HTML BLOCK'), self::TYPE_HTML_BLOCK => Yii::t('common', 'HTML BLOCK'),
]; ];
} }
} }
...@@ -27,6 +27,10 @@ class ThemeFiles extends \yii\db\ActiveRecord ...@@ -27,6 +27,10 @@ class ThemeFiles extends \yii\db\ActiveRecord
*/ */
public $file; public $file;
/* /*
* @var theme_id using to render file page
*/
public $theme_id;
/*
* @var file upload * @var file upload
*/ */
public $fileContent; public $fileContent;
...@@ -56,10 +60,10 @@ class ThemeFiles extends \yii\db\ActiveRecord ...@@ -56,10 +60,10 @@ class ThemeFiles extends \yii\db\ActiveRecord
return [ return [
[['theme_code', 'file_code','file'], 'required'], [['theme_code', 'file_code','file'], 'required'],
[['theme_code', 'file_code','fileContent'], 'string'], [['theme_code', 'file_code','fileContent'], 'string'],
[['created_at', 'updated_at'], 'integer'], [['created_at', 'updated_at','theme_id'], 'integer'],
[['file_code'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryFiles::className(), 'targetAttribute' => ['file_code' => 'id']], [['file_code'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryFiles::className(), 'targetAttribute' => ['file_code' => 'id']],
[['theme_code'], 'exist', 'skipOnError' => true, 'targetClass' => Theme::className(), 'targetAttribute' => ['theme_code' => 'id']], [['theme_code'], 'exist', 'skipOnError' => true, 'targetClass' => Theme::className(), 'targetAttribute' => ['theme_code' => 'id']],
[['file'],'file'], [['file'],'file','skipOnEmpty' => false, 'extensions' => 'js,css,html'],
]; ];
} }
......
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