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
7eb33d65
Commit
7eb33d65
authored
Jul 21, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored Sort.
parent
02608626
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
10 deletions
+44
-10
Sort.php
framework/yii/data/Sort.php
+22
-9
LinkPager.php
framework/yii/widgets/LinkPager.php
+1
-1
SortTest.php
tests/unit/framework/data/SortTest.php
+21
-0
No files found.
framework/yii/data/Sort.php
View file @
7eb33d65
...
...
@@ -275,8 +275,8 @@ class Sort extends Object
*/
public
function
getAttributeOrder
(
$attribute
)
{
$this
->
getAttributeOrders
();
return
isset
(
$
this
->
_attributeOrders
[
$attribute
])
?
$this
->
_attributeO
rders
[
$attribute
]
:
null
;
$
orders
=
$
this
->
getAttributeOrders
();
return
isset
(
$
orders
[
$attribute
])
?
$o
rders
[
$attribute
]
:
null
;
}
/**
...
...
@@ -300,8 +300,8 @@ class Sort extends Object
}
$url
=
$this
->
createUrl
(
$attribute
);
$
definition
=
$this
->
attributes
[
$attribute
]
;
return
Html
::
a
(
$
definition
[
'label'
],
$url
,
$options
);
$
options
[
'data-sort'
]
=
$this
->
createSortVar
(
$attribute
)
;
return
Html
::
a
(
$
this
->
attributes
[
$attribute
]
[
'label'
],
$url
,
$options
);
}
/**
...
...
@@ -317,6 +317,23 @@ class Sort extends Object
*/
public
function
createUrl
(
$attribute
)
{
$params
=
$this
->
params
===
null
?
$_GET
:
$this
->
params
;
$params
[
$this
->
sortVar
]
=
$this
->
createSortVar
(
$attribute
);
$route
=
$this
->
route
===
null
?
Yii
::
$app
->
controller
->
getRoute
()
:
$this
->
route
;
$urlManager
=
$this
->
urlManager
===
null
?
Yii
::
$app
->
getUrlManager
()
:
$this
->
urlManager
;
return
$urlManager
->
createUrl
(
$route
,
$params
);
}
/**
* Creates the sort variable for the specified attribute.
* The newly created sort variable can be used to create a URL that will lead to
* sorting by the specified attribute.
* @param string $attribute the attribute name
* @return string the value of the sort variable
* @throws InvalidConfigException if the specified attribute is not defined in [[attributes]]
*/
public
function
createSortVar
(
$attribute
)
{
if
(
!
isset
(
$this
->
attributes
[
$attribute
]))
{
throw
new
InvalidConfigException
(
"Unknown attribute:
$attribute
"
);
}
...
...
@@ -339,10 +356,6 @@ class Sort extends Object
foreach
(
$directions
as
$attribute
=>
$descending
)
{
$sorts
[]
=
$descending
?
$attribute
.
$this
->
separators
[
1
]
.
$this
->
descTag
:
$attribute
;
}
$params
=
$this
->
params
===
null
?
$_GET
:
$this
->
params
;
$params
[
$this
->
sortVar
]
=
implode
(
$this
->
separators
[
0
],
$sorts
);
$route
=
$this
->
route
===
null
?
Yii
::
$app
->
controller
->
getRoute
()
:
$this
->
route
;
$urlManager
=
$this
->
urlManager
===
null
?
Yii
::
$app
->
getUrlManager
()
:
$this
->
urlManager
;
return
$urlManager
->
createUrl
(
$route
,
$params
);
return
implode
(
$this
->
separators
[
0
],
$sorts
);
}
}
framework/yii/widgets/LinkPager.php
View file @
7eb33d65
...
...
@@ -183,7 +183,7 @@ class LinkPager extends Widget
}
$class
=
trim
(
$class
);
$options
=
array
(
'class'
=>
$class
===
''
?
null
:
$class
);
return
Html
::
tag
(
'li'
,
Html
::
a
(
$label
,
$this
->
pagination
->
createUrl
(
$page
)),
$options
);
return
Html
::
tag
(
'li'
,
Html
::
a
(
$label
,
$this
->
pagination
->
createUrl
(
$page
)
,
array
(
'data-page'
=>
$page
)
),
$options
);
}
/**
...
...
tests/unit/framework/data/SortTest.php
View file @
7eb33d65
...
...
@@ -93,6 +93,27 @@ class SortTest extends TestCase
$this
->
assertNull
(
$sort
->
getAttributeOrder
(
'xyz'
));
}
public
function
testCreateSortVar
()
{
$sort
=
new
Sort
(
array
(
'attributes'
=>
array
(
'age'
,
'name'
=>
array
(
'asc'
=>
array
(
'first_name'
=>
Sort
::
ASC
,
'last_name'
=>
Sort
::
ASC
),
'desc'
=>
array
(
'first_name'
=>
Sort
::
DESC
,
'last_name'
=>
Sort
::
DESC
),
),
),
'params'
=>
array
(
'sort'
=>
'age.name-desc'
),
'enableMultiSort'
=>
true
,
'route'
=>
'site/index'
,
));
$this
->
assertEquals
(
'age-desc.name-desc'
,
$sort
->
createSortVar
(
'age'
));
$this
->
assertEquals
(
'name.age'
,
$sort
->
createSortVar
(
'name'
));
}
public
function
testCreateUrl
()
{
$manager
=
new
UrlManager
(
array
(
...
...
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