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
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
164 additions
and
106 deletions
+164
-106
ThemeController.php
backend/modules/theme/controllers/ThemeController.php
+31
-2
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
+36
-56
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;
...
@@ -9,6 +9,12 @@ use backend\modules\theme\models\search\ThemeSearch;
use
yii\web\Controller
;
use
yii\web\Controller
;
use
yii\web\NotFoundHttpException
;
use
yii\web\NotFoundHttpException
;
use
yii\filters\VerbFilter
;
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.
* ThemeController implements the CRUD actions for Theme model.
...
@@ -126,9 +132,9 @@ class ThemeController extends Controller
...
@@ -126,9 +132,9 @@ class ThemeController extends Controller
}
}
}
}
public
function
actionFiles
(
$id
)
public
function
actionFiles
(
$id
)
{
{
$model
=
$this
->
findModel
(
$id
);
$model
=
$this
->
findModel
(
$id
);
$modelFiles
=
$model
->
themeFiles
;
$modelFiles
=
$model
->
themeFiles
;
...
@@ -177,9 +183,11 @@ class ThemeController extends Controller
...
@@ -177,9 +183,11 @@ class ThemeController extends Controller
}
}
}
}
$categoryFiles
=
$this
->
findCategoryFiles
(
$model
->
category_id
);
return
$this
->
render
(
'file'
,
[
return
$this
->
render
(
'file'
,
[
'model'
=>
$model
,
'model'
=>
$model
,
'modelFiles'
=>
(
empty
(
$modelFiles
))
?
[
new
ThemeFiles
()]
:
$modelFiles
'modelFiles'
=>
(
empty
(
$modelFiles
))
?
[
new
ThemeFiles
()]
:
$modelFiles
,
'categoryFiles'
=>
$categoryFiles
]);
]);
}
}
...
@@ -232,4 +240,25 @@ class ThemeController extends Controller
...
@@ -232,4 +240,25 @@ 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
(
'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 @@
...
@@ -2,6 +2,7 @@
/* @var $this yii\web\View */
/* @var $this yii\web\View */
/* @var $model common\models\Theme */
/* @var $model common\models\Theme */
/* @var $modelFiles common\models\ThemeFiles */
/* @var $modelFiles common\models\ThemeFiles */
/* @var $categoryFiles array */
$this
->
params
[
'themeId'
]
=
false
;
$this
->
params
[
'themeId'
]
=
false
;
$this
->
title
=
'Create Theme File'
;
$this
->
title
=
'Create Theme File'
;
...
@@ -14,6 +15,7 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -14,6 +15,7 @@ $this->params['breadcrumbs'][] = $this->title;
<?=
$this
->
render
(
'..\theme_file\_form'
,
[
<?=
$this
->
render
(
'..\theme_file\_form'
,
[
'model'
=>
$model
,
'model'
=>
$model
,
'modelFiles'
=>
$modelFiles
,
'modelFiles'
=>
$modelFiles
,
'categoryFiles'
=>
$categoryFiles
,
])
?>
])
?>
</div>
</div>
backend/modules/theme/views/theme/layout.php
View file @
5c3ec24b
...
@@ -18,7 +18,7 @@ Menu::widget([
...
@@ -18,7 +18,7 @@ Menu::widget([
[
[
'label'
=>
'Files'
,
'label'
=>
'Files'
,
'url'
=>
$this
->
params
[
'themeId'
]
?
'url'
=>
$this
->
params
[
'themeId'
]
?
[
'theme/file'
,
'id'
=>
$this
->
params
[
'themeId'
]]
[
'theme/file
s
'
,
'id'
=>
$this
->
params
[
'themeId'
]]
:
'#'
,
:
'#'
,
'options'
=>
[
'class'
=>
$this
->
params
[
'themeId'
]
?
''
:
'disabled'
]
'options'
=>
[
'class'
=>
$this
->
params
[
'themeId'
]
?
''
:
'disabled'
]
],
],
...
...
backend/modules/theme/views/theme_file/_form.php
View file @
5c3ec24b
<?php
<?php
/* @var $modelFiles common\models\ThemeFiles */
/* @var $categoryFiles array */
?>
?>
<?php
<?php
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\widgets\ActiveForm
;
use
yii\widgets\ActiveForm
;
use
wbraganca\dynamicform\DynamicFormWidget
;
?>
?>
<div
class=
"customer-form"
>
<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 panel-default"
>
<div
class=
"panel-body"
>
<div
class=
"panel-body"
>
<?php
DynamicFormWidget
::
begin
([
<table>
'widgetContainer'
=>
'dynamicform_wrapper'
,
// required: only alphanumeric characters plus "_" [A-Za-z0-9_]
<tr>
'widgetBody'
=>
'.container-items'
,
// required: css class selector
<th>
File Name
</th>
'widgetItem'
=>
'.item'
,
// required: css class
<th>
Options
</th>
'limit'
=>
4
,
// the maximum times, an element can be cloned (default 999)
</tr>
'min'
=>
1
,
// 0 or 1 (default 1)
'insertButton'
=>
'.add-item'
,
// css class
<?php
foreach
(
$categoryFiles
as
$value
)
{
?>
'deleteButton'
=>
'.remove-item'
,
// css class
'model'
=>
$modelFiles
[
0
],
<tr>
'formId'
=>
'dynamic-form'
,
<td>
<?=
$value
[
'name'
]
?>
</td>
'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
<?php
// necessary for update action.
if
(
!
$modelFile
->
isNewRecord
)
{
$filePath
=
yii
::
getAlias
(
'@storage/private/theme-assets/'
);
echo
Html
::
activeHiddenInput
(
$modelFile
,
"[
{
$i
}
]category_id"
);
$folderName
=
$model
->
code
.
'/'
;
//theme code
}
$fileCode
=
$value
[
'code'
];
//file code
?>
$file
=
$filePath
.
$folderName
.
$fileCode
;
<div
class=
"row"
>
Yii
::
$app
->
params
[
'uploadPath'
]
=
$file
;
//saving to global parameter
<div
class=
"col-sm-4"
>
if
(
file_exists
(
$file
))
{
?
>
<?=
$form
->
field
(
$modelFile
,
"[
{
$i
}
]name"
)
->
textInput
([
'maxlength'
=>
true
])
?>
</div
>
<td>
<?=
'edit'
?>
</td
>
<div
class=
"col-sm-4"
>
<?=
$form
->
field
(
$modelFile
,
"[
{
$i
}
]code"
)
->
textInput
([
'maxlength'
=>
true
])
?>
<?php
}
else
{
?>
</div>
<div
class=
"col-sm-4"
>
<td>
<?=
$form
->
field
(
$model
,
'themeFile'
)
->
fileInput
()
?>
</td
>
<!--
<?
//= $form->field($modelFile, "[{$i}]type")->textInput(['maxlength' => true]) ?> -->
<?=
$form
->
field
(
$modelFile
,
"[
{
$i
}
]type"
)
->
dropDownList
(
$modelFile
::
getTheme
(),
[
'prompt'
=>
''
])
?>
<?php
}
?>
</div>
</div
>
</tr
>
</div>
</div
>
<?php
}
?
>
<?php
endforeach
;
?>
</
div
>
</
table
>
<?php
DynamicFormWidget
::
end
();
?>
</div>
</div>
</div>
</div>
...
...
common/models/Theme.php
View file @
5c3ec24b
...
@@ -3,8 +3,6 @@
...
@@ -3,8 +3,6 @@
namespace
common\models
;
namespace
common\models
;
use
Yii
;
use
Yii
;
use
yii\behaviors\SluggableBehavior
;
use
yii\behaviors\TimestampBehavior
;
/**
/**
* This is the model class for table "{{%theme}}".
* This is the model class for table "{{%theme}}".
...
@@ -21,11 +19,17 @@ use yii\behaviors\TimestampBehavior;
...
@@ -21,11 +19,17 @@ use yii\behaviors\TimestampBehavior;
*
*
* @property Category $category
* @property Category $category
* @property ThemeFiles[] $themeFiles
* @property ThemeFiles[] $themeFiles
* @property Website[] $websites
*/
*/
class
Theme
extends
\yii\db\ActiveRecord
class
Theme
extends
\yii\db\ActiveRecord
{
{
const
STATUS_ACTIVE
=
1
;
const
STATUS_ACTIVE
=
1
;
const
STATUS_IN_ACTIVE
=
2
;
const
STATUS_IN_ACTIVE
=
0
;
/*
* @upload file
*/
public
$themeFile
;
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
...
@@ -40,7 +44,7 @@ class Theme extends \yii\db\ActiveRecord
...
@@ -40,7 +44,7 @@ class Theme extends \yii\db\ActiveRecord
public
function
rules
()
public
function
rules
()
{
{
return
[
return
[
[[
'category_id'
,
'code'
,
'name'
,
'status'
],
'required'
],
[[
'category_id'
,
'code'
,
'
slug'
,
'
name'
,
'status'
],
'required'
],
[[
'category_id'
,
'status'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'category_id'
,
'status'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'code'
,
'slug'
,
'name'
],
'string'
,
'max'
=>
32
],
[[
'code'
,
'slug'
,
'name'
],
'string'
,
'max'
=>
32
],
[[
'description'
],
'string'
,
'max'
=>
512
],
[[
'description'
],
'string'
,
'max'
=>
512
],
...
@@ -48,37 +52,21 @@ class Theme extends \yii\db\ActiveRecord
...
@@ -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
* @inheritdoc
*/
*/
public
function
attributeLabels
()
public
function
attributeLabels
()
{
{
return
[
return
[
'id'
=>
Yii
::
t
(
'
app
'
,
'ID'
),
'id'
=>
Yii
::
t
(
'
common
'
,
'ID'
),
'category_id'
=>
Yii
::
t
(
'
app'
,
'Category
'
),
'category_id'
=>
Yii
::
t
(
'
common'
,
'Category ID
'
),
'code'
=>
Yii
::
t
(
'
app
'
,
'Code'
),
'code'
=>
Yii
::
t
(
'
common
'
,
'Code'
),
'slug'
=>
Yii
::
t
(
'
app
'
,
'Slug'
),
'slug'
=>
Yii
::
t
(
'
common
'
,
'Slug'
),
'name'
=>
Yii
::
t
(
'
app
'
,
'Name'
),
'name'
=>
Yii
::
t
(
'
common
'
,
'Name'
),
'description'
=>
Yii
::
t
(
'
app
'
,
'Description'
),
'description'
=>
Yii
::
t
(
'
common
'
,
'Description'
),
'status'
=>
Yii
::
t
(
'
app
'
,
'Status'
),
'status'
=>
Yii
::
t
(
'
common
'
,
'Status'
),
'created_at'
=>
Yii
::
t
(
'
app
'
,
'Created At'
),
'created_at'
=>
Yii
::
t
(
'
common
'
,
'Created At'
),
'updated_at'
=>
Yii
::
t
(
'
app
'
,
'Updated At'
),
'updated_at'
=>
Yii
::
t
(
'
common
'
,
'Updated At'
),
];
];
}
}
...
@@ -95,7 +83,15 @@ class Theme extends \yii\db\ActiveRecord
...
@@ -95,7 +83,15 @@ class Theme extends \yii\db\ActiveRecord
*/
*/
public
function
getThemeFiles
()
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
...
@@ -106,7 +102,10 @@ class Theme extends \yii\db\ActiveRecord
{
{
return
new
\common\models\query\ThemeQuery
(
get_called_class
());
return
new
\common\models\query\ThemeQuery
(
get_called_class
());
}
}
/**
* List all status
* @return array
*/
public
static
function
statuses
()
public
static
function
statuses
()
{
{
return
[
return
[
...
...
common/models/ThemeFiles.php
View file @
5c3ec24b
...
@@ -8,17 +8,19 @@ use Yii;
...
@@ -8,17 +8,19 @@ use Yii;
* This is the model class for table "{{%theme_files}}".
* This is the model class for table "{{%theme_files}}".
*
*
* @property integer $id
* @property integer $id
* @property integer $theme_
id
* @property integer $theme_
code
* @property
string $file_id
* @property
integer $file_code
* @property string $base_url
* @property string $base_url
* @property string $base_path
* @property string $base_path
* @property integer $created_at
* @property integer $created_at
* @property integer $updated_at
* @property integer $updated_at
*
*
* @property Theme $theme
* @property CategoryFiles $fileCode
* @property Theme $themeCode
*/
*/
class
ThemeFiles
extends
\yii\db\ActiveRecord
class
ThemeFiles
extends
\yii\db\ActiveRecord
{
{
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
...
@@ -33,11 +35,11 @@ class ThemeFiles extends \yii\db\ActiveRecord
...
@@ -33,11 +35,11 @@ class ThemeFiles extends \yii\db\ActiveRecord
public
function
rules
()
public
function
rules
()
{
{
return
[
return
[
[[
'theme_id'
,
'file_id'
],
'required'
],
[[
'theme_code'
,
'file_code'
],
'required'
],
[[
'theme_id'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'theme_code'
,
'file_code'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'file_id'
],
'string'
,
'max'
=>
32
],
[[
'base_url'
,
'base_path'
],
'string'
,
'max'
=>
1024
],
[[
'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
...
@@ -47,22 +49,30 @@ class ThemeFiles extends \yii\db\ActiveRecord
public
function
attributeLabels
()
public
function
attributeLabels
()
{
{
return
[
return
[
'id'
=>
Yii
::
t
(
'
app
'
,
'ID'
),
'id'
=>
Yii
::
t
(
'
common
'
,
'ID'
),
'theme_
id'
=>
Yii
::
t
(
'app'
,
'Theme ID
'
),
'theme_
code'
=>
Yii
::
t
(
'common'
,
'Theme Code
'
),
'file_
id'
=>
Yii
::
t
(
'app'
,
'File ID
'
),
'file_
code'
=>
Yii
::
t
(
'common'
,
'File Code
'
),
'base_url'
=>
Yii
::
t
(
'
app
'
,
'Base Url'
),
'base_url'
=>
Yii
::
t
(
'
common
'
,
'Base Url'
),
'base_path'
=>
Yii
::
t
(
'
app
'
,
'Base Path'
),
'base_path'
=>
Yii
::
t
(
'
common
'
,
'Base Path'
),
'created_at'
=>
Yii
::
t
(
'
app
'
,
'Created At'
),
'created_at'
=>
Yii
::
t
(
'
common
'
,
'Created At'
),
'updated_at'
=>
Yii
::
t
(
'
app
'
,
'Updated At'
),
'updated_at'
=>
Yii
::
t
(
'
common
'
,
'Updated At'
),
];
];
}
}
/**
/**
* @return \yii\db\ActiveQuery
* @return \yii\db\ActiveQuery
*/
*/
public
function
getTheme
()
public
function
getFileCode
()
{
return
$this
->
hasOne
(
CategoryFiles
::
className
(),
[
'id'
=>
'file_code'
]);
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getThemeCode
()
{
{
return
$this
->
hasOne
(
Theme
::
className
(),
[
'id'
=>
'theme_
id
'
]);
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