Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
9339edbd
Commit
9339edbd
authored
May 29, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored Progress.
parent
29464d3f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
40 deletions
+39
-40
Progress.php
framework/yii/bootstrap/Progress.php
+39
-40
No files found.
framework/yii/bootstrap/Progress.php
View file @
9339edbd
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
namespace
yii\bootstrap
;
namespace
yii\bootstrap
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\
base\
ArrayHelper
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
...
@@ -44,11 +44,11 @@ use yii\helpers\Html;
...
@@ -44,11 +44,11 @@ use yii\helpers\Html;
* 'options' => array('class' => 'active progress-striped')
* 'options' => array('class' => 'active progress-striped')
* ));
* ));
*
*
* // stacked
and one with label
* // stacked
bars
* echo Progress::widget(array(
* echo Progress::widget(array(
* '
stacked
' => array(
* '
bars
' => array(
* array('percent' => 30, 'options' => array('class' => 'bar-danger')),
* array('percent' => 30, 'options' => array('class' => 'bar-danger')),
* array('
label'=>'test', 'percent' => 30
, 'options' => array('class' => 'bar-success')),
* array('
percent' => 30, 'label'=>'test'
, 'options' => array('class' => 'bar-success')),
* array('percent' => 35, 'options' => array('class' => 'bar-warning'))
* array('percent' => 35, 'options' => array('class' => 'bar-warning'))
* )
* )
* ));
* ));
...
@@ -72,16 +72,20 @@ class Progress extends Widget
...
@@ -72,16 +72,20 @@ class Progress extends Widget
*/
*/
public
$barOptions
=
array
();
public
$barOptions
=
array
();
/**
/**
* @var array $stacked set to an array of progress bar values to display stacked progress bars
* @var array a set of bars that are stacked together to form a single progress bar.
* Each bar is an array of the following structure:
*
*
* ```php
* ```php
* 'stacked'=>array(
* array(
* array('percent'=>'30', 'options'=>array('class'=>'custom')),
* // required, the amount of progress as a percentage.
* array('percent'=>'30'),
* 'percent' => 30,
* )
* // optional, the label to be displayed on the bar
* ```
* 'label' => '30%',
* // optional, array, additional HTML attributes for the bar tag
* 'options' => array(),
* )
*/
*/
public
$
stacked
=
false
;
public
$
bars
;
/**
/**
...
@@ -90,12 +94,8 @@ class Progress extends Widget
...
@@ -90,12 +94,8 @@ class Progress extends Widget
*/
*/
public
function
init
()
public
function
init
()
{
{
if
(
$this
->
label
===
null
&&
$this
->
stacked
==
false
)
{
throw
new
InvalidConfigException
(
"The 'percent' option is required."
);
}
parent
::
init
();
parent
::
init
();
$this
->
addCssClass
(
$this
->
options
,
'progress'
);
$this
->
addCssClass
(
$this
->
options
,
'progress'
);
$this
->
getView
()
->
registerAssetBundle
(
static
::
$responsive
?
'yii/bootstrap/responsive'
:
'yii/bootstrap'
);
}
}
/**
/**
...
@@ -106,42 +106,42 @@ class Progress extends Widget
...
@@ -106,42 +106,42 @@ class Progress extends Widget
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderProgress
()
.
"
\n
"
;
echo
$this
->
renderProgress
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
$this
->
getView
()
->
registerAssetBundle
(
static
::
$responsive
?
'yii/bootstrap/responsive'
:
'yii/bootstrap'
);
}
}
/**
/**
* Generates a bar
* Renders the progress.
* @param int $percent the percentage of the bar
* @param string $label, optional, the label to display at the bar
* @param array $options the HTML attributes of the bar
* @return string the rendering result.
*/
public
function
bar
(
$percent
,
$label
=
''
,
$options
=
array
())
{
$this
->
addCssClass
(
$options
,
'bar'
);
$options
[
'style'
]
=
"width:
{
$percent
}
%"
;
return
Html
::
tag
(
'div'
,
$label
,
$options
);
}
/**
* @return string the rendering result.
* @return string the rendering result.
* @throws InvalidConfigException
* @throws InvalidConfigException
if the "percent" option is not set in a stacked progress bar.
*/
*/
protected
function
renderProgress
()
protected
function
renderProgress
()
{
{
if
(
$this
->
stacked
===
false
)
{
if
(
empty
(
$this
->
bars
)
)
{
return
$this
->
b
ar
(
$this
->
percent
,
$this
->
label
,
$this
->
barOptions
);
return
$this
->
renderB
ar
(
$this
->
percent
,
$this
->
label
,
$this
->
barOptions
);
}
}
$bars
=
array
();
$bars
=
array
();
foreach
(
$this
->
stacked
as
$item
)
{
foreach
(
$this
->
bars
as
$bar
)
{
$label
=
ArrayHelper
::
getValue
(
$
item
,
'label'
,
''
);
$label
=
ArrayHelper
::
getValue
(
$
bar
,
'label'
,
''
);
if
(
!
isset
(
$
item
[
'percent'
]))
{
if
(
!
isset
(
$
bar
[
'percent'
]))
{
throw
new
InvalidConfigException
(
"The 'percent' option is required."
);
throw
new
InvalidConfigException
(
"The 'percent' option is required."
);
}
}
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
array
());
$options
=
ArrayHelper
::
getValue
(
$bar
,
'options'
,
array
());
$bars
[]
=
$this
->
renderBar
(
$bar
[
'percent'
],
$label
,
$options
);
$bars
[]
=
$this
->
bar
(
$item
[
'percent'
],
$label
,
$options
);
}
}
return
implode
(
"
\n
"
,
$bars
);
return
implode
(
"
\n
"
,
$bars
);
}
}
}
/**
\ No newline at end of file
* Generates a bar
* @param int $percent the percentage of the bar
* @param string $label, optional, the label to display at the bar
* @param array $options the HTML attributes of the bar
* @return string the rendering result.
*/
protected
function
renderBar
(
$percent
,
$label
=
''
,
$options
=
array
())
{
$this
->
addCssClass
(
$options
,
'bar'
);
$options
[
'style'
]
=
"width:
{
$percent
}
%"
;
return
Html
::
tag
(
'div'
,
$label
,
$options
);
}
}
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