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
804166af
Commit
804166af
authored
Sep 09, 2016
by
jomon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code review changes
parent
04be5278
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
65 deletions
+96
-65
CategoryController.php
backend/modules/theme/controllers/CategoryController.php
+47
-48
file.php
backend/modules/theme/views/category/file.php
+5
-2
layout.php
backend/modules/theme/views/category/layout.php
+1
-1
update.php
backend/modules/theme/views/category/update.php
+4
-3
_form.php
backend/modules/theme/views/file/_form.php
+37
-9
web.php
common/config/web.php
+2
-2
No files found.
backend/modules/theme/controllers/CategoryController.php
View file @
804166af
...
...
@@ -6,6 +6,7 @@ use common\models\CategoryFiles;
use
Yii
;
use
common\models\Category
;
use
backend\modules\theme\models\search\CategorySearch
;
use
yii\helpers\Html
;
use
yii\web\Controller
;
use
yii\web\NotFoundHttpException
;
use
yii\filters\VerbFilter
;
...
...
@@ -112,22 +113,6 @@ class CategoryController extends Controller
}
/**
* Finds the Category model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Category the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected
function
findModel
(
$id
)
{
if
((
$model
=
Category
::
findOne
(
$id
))
!==
null
)
{
return
$model
;
}
else
{
throw
new
NotFoundHttpException
(
'The requested page does not exist.'
);
}
}
/**
* Files of an existing Category model.
* If record exists, the browser will be redirected to the 'view' page.
* @param integer $id
...
...
@@ -135,63 +120,75 @@ class CategoryController extends Controller
*/
public
function
actionFiles
(
$id
)
{
//
$this->layout = '@backend/modules/theme/views/category/layout.php';
$this
->
layout
=
'@backend/modules/theme/views/category/layout.php'
;
$model
=
$this
->
findModel
(
$id
);
$modelFiles
=
$model
->
categoryFiles
;
// $modelFiles->type = $modelFiles::TYPE_JS;
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
()))
{
//&& $model->save()
if
(
Yii
::
$app
->
request
->
isPost
)
{
$oldIDs
=
ArrayHelper
::
map
(
$modelFiles
,
'id'
,
'id'
);
$modelFiles
=
Model
::
createMultiple
(
CategoryFiles
::
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
)
);
}
if
(
Model
::
loadMultiple
(
$modelFiles
,
Yii
::
$app
->
request
->
post
()))
{
$deletedIDs
=
array_diff
(
$oldIDs
,
array_filter
(
ArrayHelper
::
map
(
$modelFiles
,
'id'
,
'id'
)));
// validate all models
$valid
=
$model
->
validate
();
$valid
=
Model
::
validateMultiple
(
$modelFiles
)
&&
$valid
;
if
(
Model
::
validateMultiple
(
$modelFiles
))
{
$transaction
=
\Yii
::
$app
->
db
->
beginTransaction
();
if
(
$valid
)
{
$transaction
=
\Yii
::
$app
->
db
->
beginTransaction
();
try
{
if
(
$flag
=
$model
->
save
(
false
))
{
if
(
!
empty
(
$deletedIDs
))
{
try
{
$flag
=
true
;
if
(
!
empty
(
$deletedIDs
))
{
CategoryFiles
::
deleteAll
([
'id'
=>
$deletedIDs
]);
}
foreach
(
$modelFiles
as
$modelFiles
)
{
$modelFiles
->
customer_id
=
$model
->
id
;
if
(
!
(
$flag
=
$modelFiles
->
save
(
false
)))
{
if
(
!
(
$flag
=
$modelFiles
->
save
(
false
)))
{
$transaction
->
rollBack
();
echo
'<pre>'
;
var_dump
(
$modelFiles
);
echo
'</pre>'
;
exit
();
break
;
}
}
if
(
$flag
)
{
$transaction
->
commit
();
return
$this
->
redirect
([
'file'
,
'category_id'
=>
$model
->
id
]);
}
}
catch
(
Exception
$e
)
{
$transaction
->
rollBack
();
}
if
(
$flag
)
{
$transaction
->
commit
();
return
$this
->
redirect
([
'file'
,
'category_id'
=>
$model
->
id
]);
}
}
catch
(
Exception
$e
)
{
$transaction
->
rollBack
();
}
}
}
return
$this
->
render
(
'file'
,
[
'model'
=>
$model
,
'modelFiles'
=>
(
empty
(
$modelFiles
))
?
[
new
CategoryFiles
()]
:
$modelFiles
'modelFiles'
=>
(
empty
(
$modelFiles
))
?
[
new
CategoryFiles
(
[
'category_id'
=>
$model
->
id
]
)]
:
$modelFiles
]);
}
/**
* Finds the Category model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Category the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected
function
findModel
(
$id
)
{
if
((
$model
=
Category
::
findOne
(
$id
))
!==
null
)
{
return
$model
;
}
else
{
throw
new
NotFoundHttpException
(
'The requested page does not exist.'
);
}
}
public
function
actionCreatee
()
{
$model
=
new
Category
();
...
...
@@ -204,6 +201,7 @@ class CategoryController extends Controller
// ajax validation
if
(
Yii
::
$app
->
request
->
isAjax
)
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
return
ArrayHelper
::
merge
(
ActiveForm
::
validateMultiple
(
$modelFiles
),
ActiveForm
::
validate
(
$model
)
...
...
@@ -220,7 +218,7 @@ class CategoryController extends Controller
if
(
$flag
=
$model
->
save
(
false
))
{
foreach
(
$modelFiles
as
$modelFile
)
{
$modelFile
->
category_id
=
$model
->
id
;
if
(
!
(
$flag
=
$modelFile
->
save
(
false
)))
{
if
(
!
(
$flag
=
$modelFile
->
save
(
false
)))
{
$transaction
->
rollBack
();
break
;
}
...
...
@@ -228,6 +226,7 @@ class CategoryController extends Controller
}
if
(
$flag
)
{
$transaction
->
commit
();
return
$this
->
redirect
([
'file'
,
'category_id'
=>
$model
->
id
]);
}
}
catch
(
Exception
$e
)
{
...
...
backend/modules/theme/views/category/file.php
View file @
804166af
...
...
@@ -3,10 +3,13 @@
/* @var $model common\models\Category */
/* @var $modelFiles common\models\CategoryFiles */
$this
->
params
[
'categoryId'
]
=
false
;
$this
->
title
=
'Create Category File'
;
$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'
]
=
$model
->
id
;
?>
<div
class=
"category-create"
>
...
...
backend/modules/theme/views/category/layout.php
View file @
804166af
...
...
@@ -20,7 +20,7 @@ Menu::widget([
'url'
=>
$this
->
params
[
'categoryId'
]
?
[
'category/files'
,
'id'
=>
$this
->
params
[
'categoryId'
]]
:
'#'
,
'options'
=>
[
'class'
=>
$this
->
params
[
'categoryId'
]
?
''
:
'disabled'
]
'options'
=>
$this
->
params
[
'categoryId'
]
?
[]
:
[
'class'
=>
'disabled'
],
],
],
'options'
=>
[
...
...
backend/modules/theme/views/category/update.php
View file @
804166af
<?php
/* @var $this yii\web\View */
/* @var $model common\models\Category */
$this
->
params
[
'categoryId'
]
=
$model
->
id
;
$this
->
title
=
Yii
::
t
(
'backend'
,
'Update {modelClass}: '
,
[
'modelClass'
=>
'Category'
,
])
.
' '
.
$model
->
name
;
$this
->
params
[
'breadcrumbs'
][]
=
[
'label'
=>
Yii
::
t
(
'backend'
,
'Categories'
),
'url'
=>
[
'index'
]];
$this
->
params
[
'breadcrumbs'
][]
=
[
'label'
=>
$model
->
name
,
'url'
=>
[
'view'
,
'id'
=>
$model
->
id
]];
$this
->
params
[
'breadcrumbs'
][]
=
Yii
::
t
(
'backend'
,
'Update'
);
$this
->
params
[
'categoryId'
]
=
$model
->
id
;
?>
<div
class=
"category-update"
>
...
...
backend/modules/theme/views/file/_form.php
View file @
804166af
...
...
@@ -14,13 +14,20 @@ use wbraganca\dynamicform\DynamicFormWidget;
<div
class=
"panel panel-default"
>
<div
class=
"panel-body"
>
<?php
DynamicFormWidget
::
begin
([
'widgetContainer'
=>
'dynamicform_wrapper'
,
// required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody'
=>
'.container-items'
,
// required: css class selector
'widgetItem'
=>
'.item'
,
// required: css class
'limit'
=>
4
,
// the maximum times, an element can be cloned (default 999)
'min'
=>
1
,
// 0 or 1 (default 1)
'insertButton'
=>
'.add-item'
,
// css class
'deleteButton'
=>
'.remove-item'
,
// css class
'widgetContainer'
=>
'dynamicform_wrapper'
,
// required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody'
=>
'.container-items'
,
// required: css class selector
'widgetItem'
=>
'.item'
,
// required: css class
'limit'
=>
4
,
// the maximum times, an element can be cloned (default 999)
'min'
=>
1
,
// 0 or 1 (default 1)
'insertButton'
=>
'.add-item'
,
// css class
'deleteButton'
=>
'.remove-item'
,
// css class
'model'
=>
$modelFiles
[
0
],
'formId'
=>
'dynamic-form'
,
'formFields'
=>
[
...
...
@@ -31,7 +38,9 @@ use wbraganca\dynamicform\DynamicFormWidget;
]);
?>
<div
class=
"container-items"
>
<!-- widgetContainer -->
<?php
foreach
(
$modelFiles
as
$i
=>
$modelFile
)
:
?>
<div
class=
"item panel panel-default"
>
<!-- widgetBody -->
<div
class=
"panel-heading"
>
<h3
class=
"panel-title pull-left"
>
Category Files
</h3>
...
...
@@ -44,34 +53,53 @@ use wbraganca\dynamicform\DynamicFormWidget;
<div
class=
"clearfix"
></div>
</div>
<div
class=
"panel-body"
>
<?php
// necessary for update action.
if
(
!
$modelFile
->
isNewRecord
)
{
echo
Html
::
activeHiddenInput
(
$modelFile
,
"[
{
$i
}
]category_id"
);
}
?>
<div
class=
"row"
>
<div
class=
"col-sm-4"
>
<?=
$form
->
field
(
$modelFile
,
"[
{
$i
}
]name"
)
->
textInput
([
'maxlength'
=>
true
])
?>
</div>
<div
class=
"col-sm-4"
>
<?=
$form
->
field
(
$modelFile
,
"[
{
$i
}
]code"
)
->
textInput
([
'maxlength'
=>
true
])
?>
</div>
<div
class=
"col-sm-4"
>
<!--
<?
//= $form->field($modelFile, "[{$i}]type")->textInput(['maxlength' => true]) ?> -->
<?=
$form
->
field
(
$modelFile
,
"[
{
$i
}
]type"
)
->
dropDownList
(
$modelFile
::
getfiles
(),
[
'prompt'
=>
''
])
?>
<?=
$form
->
field
(
$modelFile
,
"[
{
$i
}
]type"
)
->
dropDownList
(
$modelFile
::
getfiles
(),
[
'prompt'
=>
''
])
?>
</div>
</div>
<div
class=
"hidden"
>
<?=
$form
->
field
(
$modelFile
,
"[
{
$i
}
]category_id"
)
->
hiddenInput
()
?>
</div>
</div>
</div>
<?php
endforeach
;
?>
</div>
<?php
DynamicFormWidget
::
end
();
?>
</div>
</div>
<div
class=
"form-group"
>
<?=
Html
::
submitButton
(
'Save'
,
[
'class'
=>
'btn btn-primary'
])
?>
</div>
<?php
ActiveForm
::
end
();
?>
...
...
common/config/web.php
View file @
804166af
...
...
@@ -17,13 +17,13 @@ if (YII_DEBUG) {
$config
[
'bootstrap'
][]
=
'debug'
;
$config
[
'modules'
][
'debug'
]
=
[
'class'
=>
'yii\debug\Module'
,
'allowedIPs'
=>
[
'127.0.0.1'
,
'::1'
,
'192.168.33.1'
,
'172.17.42.1'
,
'172.17.0.1
'
],
'allowedIPs'
=>
[
'127.0.0.1'
,
'::1'
,
'192.168.1.123
'
],
];
}
if
(
YII_ENV_DEV
)
{
$config
[
'modules'
][
'gii'
]
=
[
'allowedIPs'
=>
[
'127.0.0.1'
,
'::1'
,
'192.168.33.1'
,
'172.17.42.1'
,
'172.17.0.1
'
],
'allowedIPs'
=>
[
'127.0.0.1'
,
'::1'
,
'192.168.1.123
'
],
];
}
...
...
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