Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
test-project
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Junaid Rahman pv
test-project
Commits
010258b8
Commit
010258b8
authored
Sep 21, 2016
by
Junaid Rahman pv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edited theme module
parent
f962472a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
62 deletions
+105
-62
ThemeController.php
backend/modules/theme/controllers/ThemeController.php
+82
-53
_form.php
backend/modules/theme/views/theme_file/_form.php
+4
-8
Theme.php
common/models/Theme.php
+7
-1
ThemeFiles.php
common/models/ThemeFiles.php
+12
-0
No files found.
backend/modules/theme/controllers/ThemeController.php
View file @
010258b8
...
...
@@ -140,49 +140,74 @@ class ThemeController extends Controller
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
()))
{
//&& $model->save()
$oldIDs
=
ArrayHelper
::
map
(
$modelFiles
,
'id'
,
'id'
);
$modelFiles
=
Model
::
createMultiple
(
ThemeFiles
::
classname
(),
$modelFiles
);
Model
::
loadMultiple
(
$modelFiles
,
Yii
::
$app
->
request
->
post
());
$deletedIDs
=
array_diff
(
$oldIDs
,
array_filter
(
ArrayHelper
::
map
(
$modelFiles
,
'id'
,
'id'
)));
// ajax validation
if
(
Yii
::
$app
->
request
->
isAjax
)
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
return
ArrayHelper
::
merge
(
ActiveForm
::
validateMultiple
(
$modelFiles
),
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
([
'file'
,
'theme_id'
=>
$model
->
id
]);
}
}
catch
(
Exception
$e
)
{
$transaction
->
rollBack
();
// $oldIDs = ArrayHelper::map($modelFiles, 'id', 'id');
// $modelFiles = Model::createMultiple(ThemeFiles::classname(), $modelFiles);
// Model::loadMultiple($modelFiles, Yii::$app->request->post());
// $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelFiles, 'id', 'id')));
//
// // ajax validation
// if (Yii::$app->request->isAjax) {
// Yii::$app->response->format = Response::FORMAT_JSON;
// return ArrayHelper::merge(
// ActiveForm::validateMultiple($modelFiles),
// 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'
;
echo
$model
->
file
;
exit
();
}
}
$categoryFiles
=
$this
->
findCategoryFiles
(
$model
->
category_id
);
return
$this
->
render
(
'file'
,
[
'model'
=>
$model
,
...
...
@@ -233,6 +258,10 @@ class ThemeController extends Controller
$transaction
->
rollBack
();
}
}
}
return
$this
->
render
(
'file'
,
[
...
...
@@ -240,20 +269,20 @@ class ThemeController extends Controller
'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
(
'view
'
,
[
'model'
=>
$model
]);
}
//
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
){
...
...
backend/modules/theme/views/theme_file/_form.php
View file @
010258b8
...
...
@@ -26,19 +26,15 @@ use yii\widgets\ActiveForm;
<td>
<?=
$value
[
'name'
]
?>
</td>
<?php
$filePath
=
yii
::
getAlias
(
'@storage/private/theme-assets/'
);
$folderName
=
$model
->
code
.
'/'
;
//theme code
$fileCode
=
$value
[
'code'
];
//file code
$file
=
$filePath
.
$folderName
.
$fileCode
;
Yii
::
$app
->
params
[
'uploadPath'
]
=
$file
;
//saving to global parameter
if
(
file_exists
(
$file
))
{
?>
$theme_code
=
$model
->
code
;
$file_code
=
$value
[
'code'
];
if
(
$a
=
$modelFiles
[
0
]
::
isFileExist
(
$theme_code
,
$file_code
))
{
?>
<td>
<?=
'edit'
?>
</td>
<?php
}
else
{
?>
<td>
<?=
$form
->
field
(
$model
,
'theme
F
ile'
)
->
fileInput
()
?>
</td>
<td>
<?=
$form
->
field
(
$model
,
'theme
_f
ile'
)
->
fileInput
()
?>
</td>
<?php
}
?>
...
...
common/models/Theme.php
View file @
010258b8
...
...
@@ -28,7 +28,11 @@ class Theme extends \yii\db\ActiveRecord
/*
* @upload file
*/
public
$themeFile
;
public
$theme_file
;
/*
* @upload file
*/
public
$file
;
/**
* @inheritdoc
...
...
@@ -49,6 +53,8 @@ class Theme extends \yii\db\ActiveRecord
[[
'code'
,
'slug'
,
'name'
],
'string'
,
'max'
=>
32
],
[[
'description'
],
'string'
,
'max'
=>
512
],
[[
'category_id'
],
'exist'
,
'skipOnError'
=>
true
,
'targetClass'
=>
Category
::
className
(),
'targetAttribute'
=>
[
'category_id'
=>
'id'
]],
[[
'theme_file'
],
'safe'
],
[[
'theme_file'
],
'file'
,
'extensions'
=>
'js, css, html'
],
];
}
...
...
common/models/ThemeFiles.php
View file @
010258b8
...
...
@@ -14,6 +14,7 @@ use Yii;
* @property string $base_path
* @property integer $created_at
* @property integer $updated_at
* @property string $filePath
*
* @property CategoryFiles $fileCode
* @property Theme $themeCode
...
...
@@ -75,6 +76,12 @@ class ThemeFiles extends \yii\db\ActiveRecord
return
$this
->
hasOne
(
Theme
::
className
(),
[
'id'
=>
'theme_code'
]);
}
public
function
getFilePath
(
$theme_code
,
$file_code
)
{
return
yii
::
getAlias
(
'@storage/private/theme-assets/'
)
.
$theme_code
.
'/'
.
$file_code
;
}
/**
* @inheritdoc
* @return \common\models\query\ThemeFilesQuery the active query used by this AR class.
...
...
@@ -83,4 +90,9 @@ class ThemeFiles extends \yii\db\ActiveRecord
{
return
new
\common\models\query\ThemeFilesQuery
(
get_called_class
());
}
public
static
function
isFileExist
(
$theme_code
,
$file_code
)
{
return
file_exists
(
self
::
getFilePath
(
$theme_code
,
$file_code
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment