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
5c3ec24b
Commit
5c3ec24b
authored
Sep 20, 2016
by
Junaid Rahman pv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edited theme module
parent
13cf417b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
166 additions
and
108 deletions
+166
-108
ThemeController.php
backend/modules/theme/controllers/ThemeController.php
+32
-3
UploadForm.php
backend/modules/theme/models/UploadForm.php
+38
-0
file.php
backend/modules/theme/views/theme/file.php
+2
-0
layout.php
backend/modules/theme/views/theme/layout.php
+1
-1
_form.php
backend/modules/theme/views/theme_file/_form.php
+37
-57
Theme.php
common/models/Theme.php
+30
-31
ThemeFiles.php
common/models/ThemeFiles.php
+26
-16
No files found.
backend/modules/theme/controllers/ThemeController.php
View file @
5c3ec24b
...
...
@@ -9,6 +9,12 @@ use backend\modules\theme\models\search\ThemeSearch;
use
yii\web\Controller
;
use
yii\web\NotFoundHttpException
;
use
yii\filters\VerbFilter
;
use
yii\helpers\ArrayHelper
;
use
common\models\Model
;
use
yii\httpclient\Response
;
use
yii\widgets\ActiveForm
;
use
app\models\UploadForm
;
use
yii\web\UploadedFile
;
/**
* ThemeController implements the CRUD actions for Theme model.
...
...
@@ -125,10 +131,10 @@ class ThemeController extends Controller
throw
new
NotFoundHttpException
(
'The requested page does not exist.'
);
}
}
public
function
actionFiles
(
$id
)
{
$model
=
$this
->
findModel
(
$id
);
$modelFiles
=
$model
->
themeFiles
;
...
...
@@ -176,10 +182,12 @@ class ThemeController extends Controller
}
}
}
$categoryFiles
=
$this
->
findCategoryFiles
(
$model
->
category_id
);
return
$this
->
render
(
'file'
,
[
'model'
=>
$model
,
'modelFiles'
=>
(
empty
(
$modelFiles
))
?
[
new
ThemeFiles
()]
:
$modelFiles
'modelFiles'
=>
(
empty
(
$modelFiles
))
?
[
new
ThemeFiles
()]
:
$modelFiles
,
'categoryFiles'
=>
$categoryFiles
]);
}
...
...
@@ -232,4 +240,25 @@ 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
]);
}
protected
function
findCategoryFiles
(
$id
){
$fileDetails
=
Yii
::
$app
->
db
->
createCommand
(
'SELECT * FROM lw_category_files WHERE category_id='
.
$id
)
->
queryAll
();
return
$fileDetails
;
}
}
backend/modules/theme/models/UploadForm.php
0 → 100644
View file @
5c3ec24b
<?php
/**
* Created by PhpStorm.
* User: Junaid Rahman
* Date: 20-09-2016
* Time: 05:08 PM
*/
namespace
app\models
;
use
yii
;
use
yii\base\Model
;
use
yii\web\UploadedFile
;
class
UploadForm
extends
Model
{
/**
* @var UploadedFile
*/
public
$themeFile
;
public
function
rules
()
{
return
[
[[
'themeFile'
],
'file'
,
'skipOnEmpty'
=>
false
,
'extensions'
=>
'js, css, html'
],
];
}
public
function
upload
()
{
if
(
$this
->
validate
())
{
$this
->
themeFile
->
saveAs
(
Yii
::
$app
->
params
[
'uploadPath'
]);
return
true
;
}
else
{
return
false
;
}
}
}
\ No newline at end of file
backend/modules/theme/views/theme/file.php
View file @
5c3ec24b
...
...
@@ -2,6 +2,7 @@
/* @var $this yii\web\View */
/* @var $model common\models\Theme */
/* @var $modelFiles common\models\ThemeFiles */
/* @var $categoryFiles array */
$this
->
params
[
'themeId'
]
=
false
;
$this
->
title
=
'Create Theme File'
;
...
...
@@ -14,6 +15,7 @@ $this->params['breadcrumbs'][] = $this->title;
<?=
$this
->
render
(
'..\theme_file\_form'
,
[
'model'
=>
$model
,
'modelFiles'
=>
$modelFiles
,
'categoryFiles'
=>
$categoryFiles
,
])
?>
</div>
backend/modules/theme/views/theme/layout.php
View file @
5c3ec24b
...
...
@@ -18,7 +18,7 @@ Menu::widget([
[
'label'
=>
'Files'
,
'url'
=>
$this
->
params
[
'themeId'
]
?
[
'theme/file'
,
'id'
=>
$this
->
params
[
'themeId'
]]
[
'theme/file
s
'
,
'id'
=>
$this
->
params
[
'themeId'
]]
:
'#'
,
'options'
=>
[
'class'
=>
$this
->
params
[
'themeId'
]
?
''
:
'disabled'
]
],
...
...
backend/modules/theme/views/theme_file/_form.php
View file @
5c3ec24b
<?php
/* @var $modelFiles common\models\ThemeFiles */
/* @var $categoryFiles array */
?>
<?php
use
yii\helpers\Html
;
use
yii\widgets\ActiveForm
;
use
wbraganca\dynamicform\DynamicFormWidget
;
?>
<div
class=
"customer-form"
>
<?php
$form
=
ActiveForm
::
begin
([
'id'
=>
'dynamic-form'
]);
?>
<?php
$form
=
ActiveForm
::
begin
([
'
options'
=>
[
'enctype'
=>
'multipart/form-data'
],
'
id'
=>
'dynamic-form'
]);
?>
<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
'model'
=>
$modelFiles
[
0
],
'formId'
=>
'dynamic-form'
,
'formFields'
=>
[
'theme_code'
,
'file_code'
,
'base_url'
,
'base_path'
,
],
]);
?>
<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>
<div
class=
"pull-right"
>
<button
type=
"button"
class=
"add-item btn btn-success btn-xs"
><i
class=
"glyphicon glyphicon-plus"
></i></button>
<button
type=
"button"
class=
"remove-item btn btn-danger btn-xs"
><i
class=
"glyphicon glyphicon-minus"
></i></button>
</div>
<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
::
getTheme
(),
[
'prompt'
=>
''
])
?>
</div>
</div>
</div>
</div>
<?php
endforeach
;
?>
</div>
<?php
DynamicFormWidget
::
end
();
?>
<table>
<tr>
<th>
File Name
</th>
<th>
Options
</th>
</tr>
<?php
foreach
(
$categoryFiles
as
$value
)
{
?>
<tr>
<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
))
{
?>
<td>
<?=
'edit'
?>
</td>
<?php
}
else
{
?>
<td>
<?=
$form
->
field
(
$model
,
'themeFile'
)
->
fileInput
()
?>
</td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
</div>
</div>
...
...
common/models/Theme.php
View file @
5c3ec24b
...
...
@@ -3,8 +3,6 @@
namespace
common\models
;
use
Yii
;
use
yii\behaviors\SluggableBehavior
;
use
yii\behaviors\TimestampBehavior
;
/**
* This is the model class for table "{{%theme}}".
...
...
@@ -21,11 +19,17 @@ use yii\behaviors\TimestampBehavior;
*
* @property Category $category
* @property ThemeFiles[] $themeFiles
* @property Website[] $websites
*/
class
Theme
extends
\yii\db\ActiveRecord
{
const
STATUS_ACTIVE
=
1
;
const
STATUS_IN_ACTIVE
=
2
;
const
STATUS_IN_ACTIVE
=
0
;
/*
* @upload file
*/
public
$themeFile
;
/**
* @inheritdoc
*/
...
...
@@ -40,7 +44,7 @@ class Theme extends \yii\db\ActiveRecord
public
function
rules
()
{
return
[
[[
'category_id'
,
'code'
,
'name'
,
'status'
],
'required'
],
[[
'category_id'
,
'code'
,
'
slug'
,
'
name'
,
'status'
],
'required'
],
[[
'category_id'
,
'status'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'code'
,
'slug'
,
'name'
],
'string'
,
'max'
=>
32
],
[[
'description'
],
'string'
,
'max'
=>
512
],
...
...
@@ -48,37 +52,21 @@ class Theme extends \yii\db\ActiveRecord
];
}
public
function
behaviors
()
{
return
[
[
'class'
=>
SluggableBehavior
::
className
(),
'attribute'
=>
'name'
,
],
[
'class'
=>
TimestampBehavior
::
className
(),
'createdAtAttribute'
=>
'created_at'
,
'updatedAtAttribute'
=>
'updated_at'
]
];
}
/**
* @inheritdoc
*/
public
function
attributeLabels
()
{
return
[
'id'
=>
Yii
::
t
(
'
app
'
,
'ID'
),
'category_id'
=>
Yii
::
t
(
'
app'
,
'Category
'
),
'code'
=>
Yii
::
t
(
'
app
'
,
'Code'
),
'slug'
=>
Yii
::
t
(
'
app
'
,
'Slug'
),
'name'
=>
Yii
::
t
(
'
app
'
,
'Name'
),
'description'
=>
Yii
::
t
(
'
app
'
,
'Description'
),
'status'
=>
Yii
::
t
(
'
app
'
,
'Status'
),
'created_at'
=>
Yii
::
t
(
'
app
'
,
'Created At'
),
'updated_at'
=>
Yii
::
t
(
'
app
'
,
'Updated At'
),
'id'
=>
Yii
::
t
(
'
common
'
,
'ID'
),
'category_id'
=>
Yii
::
t
(
'
common'
,
'Category ID
'
),
'code'
=>
Yii
::
t
(
'
common
'
,
'Code'
),
'slug'
=>
Yii
::
t
(
'
common
'
,
'Slug'
),
'name'
=>
Yii
::
t
(
'
common
'
,
'Name'
),
'description'
=>
Yii
::
t
(
'
common
'
,
'Description'
),
'status'
=>
Yii
::
t
(
'
common
'
,
'Status'
),
'created_at'
=>
Yii
::
t
(
'
common
'
,
'Created At'
),
'updated_at'
=>
Yii
::
t
(
'
common
'
,
'Updated At'
),
];
}
...
...
@@ -95,7 +83,15 @@ class Theme extends \yii\db\ActiveRecord
*/
public
function
getThemeFiles
()
{
return
$this
->
hasMany
(
ThemeFiles
::
className
(),
[
'theme_id'
=>
'id'
]);
return
$this
->
hasMany
(
ThemeFiles
::
className
(),
[
'theme_code'
=>
'id'
]);
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getWebsites
()
{
return
$this
->
hasMany
(
Website
::
className
(),
[
'theme_id'
=>
'id'
]);
}
/**
...
...
@@ -106,7 +102,10 @@ class Theme extends \yii\db\ActiveRecord
{
return
new
\common\models\query\ThemeQuery
(
get_called_class
());
}
/**
* List all status
* @return array
*/
public
static
function
statuses
()
{
return
[
...
...
common/models/ThemeFiles.php
View file @
5c3ec24b
...
...
@@ -8,17 +8,19 @@ use Yii;
* This is the model class for table "{{%theme_files}}".
*
* @property integer $id
* @property integer $theme_
id
* @property
string $file_id
* @property integer $theme_
code
* @property
integer $file_code
* @property string $base_url
* @property string $base_path
* @property integer $created_at
* @property integer $updated_at
*
* @property Theme $theme
* @property CategoryFiles $fileCode
* @property Theme $themeCode
*/
class
ThemeFiles
extends
\yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
...
...
@@ -33,11 +35,11 @@ class ThemeFiles extends \yii\db\ActiveRecord
public
function
rules
()
{
return
[
[[
'theme_id'
,
'file_id'
],
'required'
],
[[
'theme_id'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'file_id'
],
'string'
,
'max'
=>
32
],
[[
'theme_code'
,
'file_code'
],
'required'
],
[[
'theme_code'
,
'file_code'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'base_url'
,
'base_path'
],
'string'
,
'max'
=>
1024
],
[[
'theme_id'
],
'exist'
,
'skipOnError'
=>
true
,
'targetClass'
=>
Theme
::
className
(),
'targetAttribute'
=>
[
'theme_id'
=>
'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'
]],
];
}
...
...
@@ -47,22 +49,30 @@ class ThemeFiles extends \yii\db\ActiveRecord
public
function
attributeLabels
()
{
return
[
'id'
=>
Yii
::
t
(
'
app
'
,
'ID'
),
'theme_
id'
=>
Yii
::
t
(
'app'
,
'Theme ID
'
),
'file_
id'
=>
Yii
::
t
(
'app'
,
'File ID
'
),
'base_url'
=>
Yii
::
t
(
'
app
'
,
'Base Url'
),
'base_path'
=>
Yii
::
t
(
'
app
'
,
'Base Path'
),
'created_at'
=>
Yii
::
t
(
'
app
'
,
'Created At'
),
'updated_at'
=>
Yii
::
t
(
'
app
'
,
'Updated At'
),
'id'
=>
Yii
::
t
(
'
common
'
,
'ID'
),
'theme_
code'
=>
Yii
::
t
(
'common'
,
'Theme Code
'
),
'file_
code'
=>
Yii
::
t
(
'common'
,
'File Code
'
),
'base_url'
=>
Yii
::
t
(
'
common
'
,
'Base Url'
),
'base_path'
=>
Yii
::
t
(
'
common
'
,
'Base Path'
),
'created_at'
=>
Yii
::
t
(
'
common
'
,
'Created At'
),
'updated_at'
=>
Yii
::
t
(
'
common
'
,
'Updated At'
),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
get
Them
e
()
public
function
get
FileCod
e
()
{
return
$this
->
hasOne
(
Theme
::
className
(),
[
'id'
=>
'theme_id'
]);
return
$this
->
hasOne
(
CategoryFiles
::
className
(),
[
'id'
=>
'file_code'
]);
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getThemeCode
()
{
return
$this
->
hasOne
(
Theme
::
className
(),
[
'id'
=>
'theme_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