Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2-widgets2-module
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
hrzg
yii2-widgets2-module
Commits
a012b7e9
Commit
a012b7e9
authored
Aug 18, 2016
by
Christopher Stebe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added global route option, adjust widget content query, add some code docs, cleanup
parent
ae460eb8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
7 deletions
+68
-7
WidgetContent.php
src/models/crud/WidgetContent.php
+27
-0
Cell.php
src/widgets/Cell.php
+41
-7
No files found.
src/models/crud/WidgetContent.php
View file @
a012b7e9
...
...
@@ -3,6 +3,7 @@
namespace
hrzg\widget\models\crud
;
use
hrzg\widget\models\crud\base\Widget
as
BaseWidget
;
use
hrzg\widget\widgets\Cell
;
use
yii\helpers\ArrayHelper
;
/**
...
...
@@ -10,6 +11,10 @@ use yii\helpers\ArrayHelper;
*/
class
WidgetContent
extends
BaseWidget
{
/**
* @inheritdoc
* @return array
*/
public
function
rules
()
{
return
ArrayHelper
::
merge
(
...
...
@@ -20,6 +25,25 @@ class WidgetContent extends BaseWidget
);
}
/**
* Global route needs empty request param
* @param bool $insert
*
* @return bool
*/
public
function
beforeSave
(
$insert
)
{
parent
::
beforeSave
(
$insert
);
if
(
$this
->
route
===
Cell
::
GLOBAL_ROUTE
)
{
$this
->
request_param
=
Cell
::
EMPTY_REQUEST_PARAM
;
}
return
true
;
}
/**
* @return array
*/
public
static
function
optsWidgetTemplateId
()
{
return
ArrayHelper
::
merge
(
...
...
@@ -28,6 +52,9 @@ class WidgetContent extends BaseWidget
);
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getTemplate
()
{
return
$this
->
hasOne
(
WidgetTemplate
::
className
(),
[
'id'
=>
'widget_template_id'
]);
...
...
src/widgets/Cell.php
View file @
a012b7e9
...
...
@@ -21,10 +21,29 @@ use yii\helpers\Url;
class
Cell
extends
Widget
{
/**
* Global route
*/
const
GLOBAL_ROUTE
=
'*'
;
/**
* Empty request param
*/
const
EMPTY_REQUEST_PARAM
=
''
;
/**
* Class prefix
*/
const
CSS_PREFIX
=
'hrzg-widget'
;
/**
* @var string
*/
public
$requestParam
=
'pageId'
;
/**
* @inheritdoc
*/
public
function
init
()
{
\Yii
::
$app
->
trigger
(
'registerMenuItems'
,
new
Event
([
'sender'
=>
$this
]));
...
...
@@ -33,6 +52,10 @@ class Cell extends Widget
}
}
/**
* @inheritdoc
* @return string
*/
public
function
run
()
{
Url
::
remember
(
''
,
$this
->
getRoute
());
...
...
@@ -78,25 +101,32 @@ class Cell extends Widget
->
orderBy
(
'rank ASC'
)
->
andFilterWhere
(
[
'request_param'
=>
\Yii
::
$app
->
request
->
get
(
$this
->
requestParam
)
,
'request_param'
=>
[
\Yii
::
$app
->
request
->
get
(
$this
->
requestParam
),
self
::
EMPTY_REQUEST_PARAM
]
,
]
)
->
andWhere
(
[
'container_id'
=>
$this
->
id
,
'route'
=>
[
$this
->
getRoute
(),
'*'
],
'access_domain'
=>
\Yii
::
$app
->
language
,
'route'
=>
[
$this
->
getRoute
(),
self
::
GLOBAL_ROUTE
],
'access_domain'
=>
mb_strtolower
(
\Yii
::
$app
->
language
)
,
])
->
all
();
return
$models
;
}
/**
* @return string
*/
private
function
getRoute
()
{
return
\Yii
::
$app
->
controller
->
module
->
id
.
'/'
.
\Yii
::
$app
->
controller
->
id
.
'/'
.
\Yii
::
$app
->
controller
->
action
->
id
;
}
/**
* @return string
* @throws \yii\base\InvalidConfigException
*/
private
function
renderWidgets
()
{
$html
=
Html
::
beginTag
(
...
...
@@ -129,10 +159,9 @@ class Cell extends Widget
return
$html
;
}
private
function
createWidget
()
{
}
/**
* @return string
*/
private
function
generateContainerControls
()
{
$html
=
Html
::
beginTag
(
'div'
,
[
'class'
=>
'hrzg-widget-container-controls pull-right'
]);
...
...
@@ -152,6 +181,11 @@ class Cell extends Widget
return
$html
;
}
/**
* @param $widget
*
* @return string
*/
private
function
generateWidgetControls
(
$widget
)
{
$html
=
Html
::
beginTag
(
'div'
,
[
'class'
=>
'hrzg-widget-widget-controls btn-group'
,
'role'
=>
'group'
]);
...
...
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