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
32ec38bf
Commit
32ec38bf
authored
Sep 09, 2016
by
jomon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code review changes
parent
3725cdac
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
46 deletions
+45
-46
CategoryController.php
backend/modules/theme/controllers/CategoryController.php
+21
-25
file.php
backend/modules/theme/views/category/file.php
+5
-5
_form.php
backend/modules/theme/views/file/_form.php
+10
-14
CategoryFiles.php
common/models/CategoryFiles.php
+9
-2
No files found.
backend/modules/theme/controllers/CategoryController.php
View file @
32ec38bf
...
...
@@ -121,17 +121,17 @@ class CategoryController extends Controller
{
$this
->
layout
=
'@backend/modules/theme/views/category/layout.php'
;
$
m
odel
=
$this
->
findModel
(
$id
);
$model
Files
=
$m
odel
->
categoryFiles
;
$
categoryM
odel
=
$this
->
findModel
(
$id
);
$model
s
=
$categoryM
odel
->
categoryFiles
;
if
(
Yii
::
$app
->
request
->
isPost
)
{
$oldIDs
=
ArrayHelper
::
map
(
$model
File
s
,
'id'
,
'id'
);
$model
Files
=
Model
::
createMultiple
(
CategoryFiles
::
classname
(),
$modelFile
s
);
$oldIDs
=
ArrayHelper
::
map
(
$models
,
'id'
,
'id'
);
$model
s
=
Model
::
createMultiple
(
CategoryFiles
::
classname
(),
$model
s
);
if
(
Model
::
loadMultiple
(
$model
File
s
,
Yii
::
$app
->
request
->
post
()))
{
$deletedIDs
=
array_diff
(
$oldIDs
,
array_filter
(
ArrayHelper
::
map
(
$model
File
s
,
'id'
,
'id'
)));
if
(
Model
::
loadMultiple
(
$models
,
Yii
::
$app
->
request
->
post
()))
{
$deletedIDs
=
array_diff
(
$oldIDs
,
array_filter
(
ArrayHelper
::
map
(
$models
,
'id'
,
'id'
)));
if
(
Model
::
validateMultiple
(
$model
File
s
))
{
if
(
Model
::
validateMultiple
(
$models
))
{
$transaction
=
\Yii
::
$app
->
db
->
beginTransaction
();
try
{
...
...
@@ -141,21 +141,17 @@ class CategoryController extends Controller
CategoryFiles
::
deleteAll
([
'id'
=>
$deletedIDs
]);
}
foreach
(
$model
Files
as
$modelFiles
)
{
if
(
!
(
$flag
=
$modelFiles
->
save
(
false
)))
{
foreach
(
$model
s
as
$model
)
{
$model
->
category_id
=
$categoryModel
->
id
;
if
(
!
(
$flag
=
$model
->
save
(
false
)))
{
$transaction
->
rollBack
();
echo
'<pre>'
;
var_dump
(
$modelFiles
);
echo
'</pre>'
;
exit
();
break
;
}
}
if
(
$flag
)
{
$transaction
->
commit
();
return
$this
->
redirect
([
'index'
,
'category_id'
=>
$model
->
id
]);
return
$this
->
redirect
([
'index'
]);
}
}
catch
(
Exception
$e
)
{
$transaction
->
rollBack
();
...
...
@@ -165,8 +161,8 @@ class CategoryController extends Controller
}
return
$this
->
render
(
'file'
,
[
'
model'
=>
$m
odel
,
'model
Files'
=>
(
empty
(
$modelFiles
))
?
[
new
CategoryFiles
([
'category_id'
=>
$model
->
id
])]
:
$modelFiles
'
categoryModel'
=>
$categoryM
odel
,
'model
s'
=>
(
empty
(
$models
))
?
[
new
CategoryFiles
([
'category_id'
=>
$categoryModel
->
id
])]
:
$models
,
]);
}
...
...
@@ -190,31 +186,31 @@ class CategoryController extends Controller
// public function actionCreatee()
// {
// $model = new Category();
// $model
File
s = [new CategoryFiles()];
// $models = [new CategoryFiles()];
// if ($model->load(Yii::$app->request->post())) {
//
// $model
File
s = Model::createMultiple(CategoryFiles::classname());
// Model::loadMultiple($model
File
s, Yii::$app->request->post());
// $models = Model::createMultiple(CategoryFiles::classname());
// Model::loadMultiple($models, Yii::$app->request->post());
//
// // ajax validation
// if (Yii::$app->request->isAjax) {
// Yii::$app->response->format = Response::FORMAT_JSON;
//
// return ArrayHelper::merge(
// ActiveForm::validateMultiple($model
File
s),
// ActiveForm::validateMultiple($models),
// ActiveForm::validate($model)
// );
// }
//
// // validate all models
// $valid = $model->validate();
// $valid = Model::validateMultiple($model
File
s) && $valid;
// $valid = Model::validateMultiple($models) && $valid;
//
// if ($valid) {
// $transaction = \Yii::$app->db->beginTransaction();
// try {
// if ($flag = $model->save(false)) {
// foreach ($model
File
s as $modelFile) {
// foreach ($models as $modelFile) {
// $modelFile->category_id = $model->id;
// if (!($flag = $modelFile->save(false))) {
// $transaction->rollBack();
...
...
@@ -235,7 +231,7 @@ class CategoryController extends Controller
//
// return $this->render('file', [
// 'model' => $model,
// 'modelFiles' => (empty($model
Files)) ? [new CategoryFiles()] : $modelFile
s
// 'modelFiles' => (empty($model
s)) ? [new CategoryFiles()] : $model
s
// ]);
// }
}
backend/modules/theme/views/category/file.php
View file @
32ec38bf
<?php
/* @var $this yii\web\View */
/* @var $
m
odel common\models\Category */
/* @var $model
Files common\models\CategoryFiles
*/
/* @var $
categoryM
odel common\models\Category */
/* @var $model
s common\models\CategoryFiles[]
*/
$this
->
title
=
Yii
::
t
(
'admin'
,
'Create Category File'
);
$this
->
params
[
'breadcrumbs'
][]
=
[
'label'
=>
Yii
::
t
(
'backend'
,
'Categories'
),
'url'
=>
[
'index'
]];
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
$this
->
params
[
'categoryId'
]
=
$
m
odel
->
id
;
$this
->
params
[
'categoryId'
]
=
$
categoryM
odel
->
id
;
?>
<div
class=
"category-create"
>
<?=
$this
->
render
(
'..\file\_form'
,
[
'
model'
=>
$m
odel
,
'model
Files'
=>
$modelFile
s
,
'
categoryModel'
=>
$categoryM
odel
,
'model
s'
=>
$model
s
,
])
?>
</div>
backend/modules/theme/views/file/_form.php
View file @
32ec38bf
<?php
?>
<?php
use
yii\helpers\Html
;
use
yii\widgets\ActiveForm
;
use
wbraganca\dynamicform\DynamicFormWidget
;
/* @var $this yii\web\View */
/* @var $categoryModel common\models\Category */
/* @var $models common\models\CategoryFiles[] */
?>
<div
class=
"customer-form"
>
...
...
@@ -28,7 +29,7 @@ use wbraganca\dynamicform\DynamicFormWidget;
// css class
'deleteButton'
=>
'.remove-item'
,
// css class
'model'
=>
$model
File
s
[
0
],
'model'
=>
$models
[
0
],
'formId'
=>
'dynamic-form'
,
'formFields'
=>
[
'name'
,
...
...
@@ -39,7 +40,7 @@ use wbraganca\dynamicform\DynamicFormWidget;
<div
class=
"container-items"
>
<!-- widgetContainer -->
<?php
foreach
(
$model
Files
as
$i
=>
$modelFile
)
:
?>
<?php
foreach
(
$model
s
as
$i
=>
$model
)
:
?>
<div
class=
"item panel panel-default"
>
<!-- widgetBody -->
<div
class=
"panel-heading"
>
...
...
@@ -56,34 +57,29 @@ use wbraganca\dynamicform\DynamicFormWidget;
<?php
// necessary for update action.
if
(
!
$model
File
->
isNewRecord
)
{
echo
Html
::
activeHiddenInput
(
$model
File
,
"[
{
$i
}
]category_id"
);
if
(
!
$model
->
isNewRecord
)
{
echo
Html
::
activeHiddenInput
(
$model
,
"[
{
$i
}
]category_id"
);
}
?>
<div
class=
"row"
>
<div
class=
"col-sm-4"
>
<?=
$form
->
field
(
$model
File
,
"[
{
$i
}
]name"
)
->
textInput
([
'maxlength'
=>
true
])
?>
<?=
$form
->
field
(
$model
,
"[
{
$i
}
]name"
)
->
textInput
([
'maxlength'
=>
true
])
?>
</div>
<div
class=
"col-sm-4"
>
<?=
$form
->
field
(
$model
File
,
"[
{
$i
}
]code"
)
->
textInput
([
'maxlength'
=>
true
])
?>
<?=
$form
->
field
(
$model
,
"[
{
$i
}
]code"
)
->
textInput
([
'maxlength'
=>
true
])
?>
</div>
<div
class=
"col-sm-4"
>
<?=
$form
->
field
(
$model
File
,
"[
{
$i
}
]type"
)
->
dropDownList
(
$modelFile
::
getfiles
(),
<?=
$form
->
field
(
$model
,
"[
{
$i
}
]type"
)
->
dropDownList
(
$model
::
getfiles
(),
[
'prompt'
=>
''
])
?>
</div>
</div>
<div
class=
"hidden"
>
<?=
$form
->
field
(
$modelFile
,
"[
{
$i
}
]category_id"
)
->
hiddenInput
()
?>
</div>
</div>
</div>
...
...
common/models/CategoryFiles.php
View file @
32ec38bf
...
...
@@ -23,6 +23,7 @@ class CategoryFiles extends \yii\db\ActiveRecord
const
TYPE_CSS
=
2
;
const
TYPE_HTML
=
3
;
const
TYPE_HTML_BLOCK
=
4
;
/**
* @inheritdoc
*/
...
...
@@ -37,10 +38,16 @@ class CategoryFiles extends \yii\db\ActiveRecord
public
function
rules
()
{
return
[
[[
'c
ategory_id'
,
'c
ode'
],
'required'
],
[[
'code'
],
'required'
],
[[
'category_id'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'code'
,
'type'
,
'name'
],
'string'
,
'max'
=>
32
],
[[
'category_id'
],
'exist'
,
'skipOnError'
=>
true
,
'targetClass'
=>
Category
::
className
(),
'targetAttribute'
=>
[
'category_id'
=>
'id'
]],
[
[
'category_id'
],
'exist'
,
'skipOnError'
=>
true
,
'targetClass'
=>
Category
::
className
(),
'targetAttribute'
=>
[
'category_id'
=>
'id'
]
],
];
}
...
...
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