Commit c1b3cfd2 by Junaid Rahman pv

edited theme module

parent 010258b8
...@@ -19,7 +19,8 @@ class BackendAsset extends AssetBundle ...@@ -19,7 +19,8 @@ class BackendAsset extends AssetBundle
'css/style.css' 'css/style.css'
]; ];
public $js = [ public $js = [
'js/app.js' 'js/app.js',
'js/main.js'
]; ];
public $depends = [ public $depends = [
......
...@@ -13,7 +13,6 @@ use yii\helpers\ArrayHelper; ...@@ -13,7 +13,6 @@ use yii\helpers\ArrayHelper;
use common\models\Model; use common\models\Model;
use yii\httpclient\Response; use yii\httpclient\Response;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use app\models\UploadForm;
use yii\web\UploadedFile; use yii\web\UploadedFile;
/** /**
...@@ -140,71 +139,48 @@ class ThemeController extends Controller ...@@ -140,71 +139,48 @@ class ThemeController extends Controller
if ($model->load(Yii::$app->request->post())) { //&& $model->save() if ($model->load(Yii::$app->request->post())) { //&& $model->save()
// $oldIDs = ArrayHelper::map($modelFiles, 'id', 'id'); $oldIDs = ArrayHelper::map($modelFiles, 'id', 'id');
// $modelFiles = Model::createMultiple(ThemeFiles::classname(), $modelFiles); $modelFiles = Model::createMultiple(ThemeFiles::classname(), $modelFiles);
// Model::loadMultiple($modelFiles, Yii::$app->request->post()); Model::loadMultiple($modelFiles, Yii::$app->request->post());
// $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelFiles, 'id', 'id'))); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelFiles, 'id', 'id')));
//
// // ajax validation // ajax validation
// if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
// Yii::$app->response->format = Response::FORMAT_JSON; Yii::$app->response->format = Response::FORMAT_JSON;
// return ArrayHelper::merge( return ArrayHelper::merge(
// ActiveForm::validateMultiple($modelFiles), ActiveForm::validateMultiple($modelFiles),
// ActiveForm::validate($model) ActiveForm::validate($model)
// ); );
// }
//
// // validate all models
// $valid = $model->validate();
// $valid = Model::validateMultiple($modelFiles) && $valid;
//
// if ($valid) {
// $transaction = \Yii::$app->db->beginTransaction();
// try {
// if ($flag = $model->save(false)) {
// if (! empty($deletedIDs)) {
// ThemeFiles::deleteAll(['id' => $deletedIDs]);
// }
// foreach ($modelFiles as $modelFiles) {
// $modelFiles->customer_id = $model->id;
// if (! ($flag = $modelFiles->save(false))) {
// $transaction->rollBack();
// break;
// }
// }
// }
// if ($flag) {
// $transaction->commit();
// return $this->redirect(['files', 'id' => $model->id]);
// }
// } catch (Exception $e) {
// $transaction->rollBack();
// }
// }
// get the uploaded file instance. for multiple file uploads
// the following data will return an array
$theme_file = UploadedFile::getInstance($model, 'theme_file');
// the path to save file, you can set an uploadPath
// in Yii::$app->params (as used in example below)
$path = $model->file;
if($path){
echo 'a';
if($model->save()){
$theme_file->saveAs($path);
return $this->redirect(['view', 'id'=>$model->id]);
} else {
// error in saving model
} }
}else{
echo 'aaa'; // validate all models
echo $model->file; $valid = $model->validate();
exit(); $valid = Model::validateMultiple($modelFiles) && $valid;
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($flag = $model->save(false)) {
if (! empty($deletedIDs)) {
ThemeFiles::deleteAll(['id' => $deletedIDs]);
}
foreach ($modelFiles as $modelFiles) {
$modelFiles->customer_id = $model->id;
if (! ($flag = $modelFiles->save(false))) {
$transaction->rollBack();
break;
}
}
}
if ($flag) {
$transaction->commit();
return $this->redirect(['files', 'id' => $model->id]);
}
} catch (Exception $e) {
$transaction->rollBack();
}
} }
} }
...@@ -269,22 +245,7 @@ class ThemeController extends Controller ...@@ -269,22 +245,7 @@ class ThemeController extends Controller
'modelFiles' => (empty($modelFiles)) ? [new ThemeFiles()] : $modelFiles 'modelFiles' => (empty($modelFiles)) ? [new ThemeFiles()] : $modelFiles
]); ]);
} }
// public function actionUpload()
// {
// $model = new UploadForm();
//
// if (Yii::$app->request->isPost) {
// $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
// if ($model->upload()) {
// echo 'file is uploaded successfully';
// return true;
// }
// }
//
// return $this->render('file', ['model' => $model]);
// }
protected function findCategoryFiles($id){ protected function findCategoryFiles($id){
$fileDetails = Yii::$app->db->createCommand('SELECT * FROM lw_category_files WHERE category_id=' . $id) $fileDetails = Yii::$app->db->createCommand('SELECT * FROM lw_category_files WHERE category_id=' . $id)
->queryAll(); ->queryAll();
......
<?php
namespace backend\modules\theme\controllers;
use yii;
use common\models\Theme;
use yii\web\NotFoundHttpException;
use yii\web\UploadedFile;
class ThemeFileController extends \yii\web\Controller
{
public function actionIndex()
{
return $this->render('index');
}
/**
* Finds the Theme model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Theme the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Theme::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
public function actionUpload($id){
$model = $this->findModel($id);
$modelFiles = $model->themeFiles;
if ($model->load(Yii::$app->request->post())) { //&& $model->save()
// get the uploaded file instance. for multiple file uploads
// the following data will return an array
$theme_file = UploadedFile::getInstance($model, 'theme-file');
// the path to save file, you can set an uploadPath
$path = $model->file;
if ($path) {
echo 'a';
if ($model->save()) {
$theme_file->saveAs($path);
return $this->redirect(['view', 'id' => $model->id]);
} else {
// error in saving model
}
} else {
echo 'aaa';
echo $theme_file->id;
exit();
}
}
return $this->render('upload');
}
}
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use yii\bootstrap\Modal;
use yii\helpers\Url;
?> ?>
<div class="customer-form"> <div class="customer-form">
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data'],'id' => 'dynamic-form']); ?> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data'], 'id' => 'dynamic-form']); ?>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
...@@ -26,15 +28,50 @@ use yii\widgets\ActiveForm; ...@@ -26,15 +28,50 @@ use yii\widgets\ActiveForm;
<td><?= $value['name'] ?></td> <td><?= $value['name'] ?></td>
<?php <?php
$theme_code = $model->code; $themeCode = $model->code;
$file_code = $value['code']; $fileCode = $value['code'];
if ($a = $modelFiles[0]::isFileExist($theme_code,$file_code)) { ?> $modelFiles[0]->theme_code = $themeCode;
$modelFiles[0]->file_code = $fileCode;
if ($modelFiles[0]::isFileExist($themeCode, $fileCode)) { ?>
<td><?= 'edit' ?></td> <td><?= 'edit' ?></td>
<?php } else { ?> <?php } else { ?>
<td><?= $form->field($model, 'theme_file')->fileInput() ?></td> <td>
<?= Html::button('Upload File', [
'class' => 'btn btn-default',
'id' => 'modalButton' . $value['id'],
'onclick' => 'uploadJquery.upload(' . $value['id'] . ');'
]) ?>
<?php
Modal::begin([
'header' => '<h3>Upload</h3>',
'id' => 'modal' . $value['id'],
'size' => 'modal-sm',
//keeps from closing modal with esc key or by clicking out of the modal.
// user must click cancel or X to close
]);
?>
<div id='modalContent' .<?= $value['id'] ?> style="align-content: center">
<?= $this->render('upload', [
'model' => $model,
'modelFiles' => $modelFiles,
]) ?>
</div>
<?php
yii\bootstrap\Modal::end();
?>
</td>
<?php } ?> <?php } ?>
......
<?php
/* @var $this yii\web\View */
?>
<h1>theme-file/index</h1>
<p>
You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>.
</p>
<?php
/**
* Created by PhpStorm.
* User: Junaid Rahman
* Date: 21-09-2016
* Time: 01:15 PM
*/
/* @var $modelFiles common\models\ThemeFiles */
use yii\widgets\ActiveForm;
use yii\bootstrap\Html;
?>
<?php $form = ActiveForm::begin(); ?>
<div id="myTabContent" class="tab-content">
<div class="row">
<div class="col-md-6">
<p>Choose your file to upload</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($modelFiles[0], 'file')->fileInput(['class'=>'btn btn-primary']) ?>
<?= $modelFiles[0]->file_code?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton() ?>
</div>
<?php ActiveForm::end(); ?>
\ No newline at end of file
...@@ -12,7 +12,7 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -12,7 +12,7 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="theme-create"> <div class="theme-create">
<?= $this->render('..\theme_file\_form', [ <?= $this->render('..\theme-file\_form', [
'model' => $model, 'model' => $model,
'modelFiles' => $modelFiles, 'modelFiles' => $modelFiles,
'categoryFiles' =>$categoryFiles, 'categoryFiles' =>$categoryFiles,
......
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use common\grid\EnumColumn;
use common\models\Theme;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\theme\models\search\ThemeSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'Themes');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="theme-index">
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'ThemeFiles',
]), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'theme_code',
'file_code',
'base_url',
'base_path',
// 'description',
// [
// 'class' => EnumColumn::className(),
// 'attribute' => 'status',
// 'enum' => Theme::statuses(),
// 'filter' => Theme::statuses()
// ],
// 'status',
// 'created_at',
// 'updated_at',
// ['class' => 'yii\grid\ActionColumn'
// ],
// ['class' => 'yii\grid\ActionColumn',
// 'template' => '{update}{delete}'],
],
]); ?>
</div>
/**
* Created by Junaid Rahman on 21-09-2016.
*/
uploadJquery = {
upload: function (id) {
$('#modalButton'+id).click(function () {
$('#modal'+id).modal('show')
.find('#modalContent'+id)
.load($(this).attr['value']);
});
}
};
...@@ -28,8 +28,6 @@ class m160903_101233_theme extends Migration ...@@ -28,8 +28,6 @@ class m160903_101233_theme extends Migration
'id' => $this->primaryKey(), 'id' => $this->primaryKey(),
'theme_code' => $this->integer()->notNull(), 'theme_code' => $this->integer()->notNull(),
'file_code' => $this->integer()->notNull(), 'file_code' => $this->integer()->notNull(),
'base_url' => $this->string(1024),
'base_path' => $this->string(1024),
'created_at' => $this->integer(), 'created_at' => $this->integer(),
'updated_at' => $this->integer() 'updated_at' => $this->integer()
], $tableOptions); ], $tableOptions);
......
...@@ -25,15 +25,6 @@ class Theme extends \yii\db\ActiveRecord ...@@ -25,15 +25,6 @@ class Theme extends \yii\db\ActiveRecord
{ {
const STATUS_ACTIVE = 1; const STATUS_ACTIVE = 1;
const STATUS_IN_ACTIVE = 0; const STATUS_IN_ACTIVE = 0;
/*
* @upload file
*/
public $theme_file;
/*
* @upload file
*/
public $file;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -53,8 +44,6 @@ class Theme extends \yii\db\ActiveRecord ...@@ -53,8 +44,6 @@ class Theme extends \yii\db\ActiveRecord
[['code', 'slug', 'name'], 'string', 'max' => 32], [['code', 'slug', 'name'], 'string', 'max' => 32],
[['description'], 'string', 'max' => 512], [['description'], 'string', 'max' => 512],
[['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'id']], [['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'id']],
[['theme_file'], 'safe'],
[['theme_file'], 'file', 'extensions'=>'js, css, html'],
]; ];
} }
......
...@@ -21,7 +21,10 @@ use Yii; ...@@ -21,7 +21,10 @@ use Yii;
*/ */
class ThemeFiles extends \yii\db\ActiveRecord class ThemeFiles extends \yii\db\ActiveRecord
{ {
/*
* @var file upload
*/
public $file;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -41,6 +44,7 @@ class ThemeFiles extends \yii\db\ActiveRecord ...@@ -41,6 +44,7 @@ class ThemeFiles extends \yii\db\ActiveRecord
[['base_url', 'base_path'], 'string', 'max' => 1024], [['base_url', 'base_path'], 'string', 'max' => 1024],
[['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'],
]; ];
} }
......
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