Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
294
Merge Requests
294
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
c1f05ae4
Commit
c1f05ae4
authored
Jun 08, 2012
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1541892
by Rob Loach: Convert TableSort to
PSR-0
.
parent
ede4aee9
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
133 additions
and
115 deletions
+133
-115
core/includes/tablesort.inc
core/includes/tablesort.inc
+0
-95
core/lib/Drupal/Core/Database/Query/TableSortExtender.php
core/lib/Drupal/Core/Database/Query/TableSortExtender.php
+105
-0
core/modules/comment/comment.admin.inc
core/modules/comment/comment.admin.inc
+1
-1
core/modules/dblog/dblog.admin.inc
core/modules/dblog/dblog.admin.inc
+2
-2
core/modules/forum/forum.module
core/modules/forum/forum.module
+3
-2
core/modules/node/node.admin.inc
core/modules/node/node.admin.inc
+1
-1
core/modules/path/path.admin.inc
core/modules/path/path.admin.inc
+1
-1
core/modules/poll/poll.pages.inc
core/modules/poll/poll.pages.inc
+1
-1
core/modules/statistics/statistics.admin.inc
core/modules/statistics/statistics.admin.inc
+4
-4
core/modules/statistics/statistics.pages.inc
core/modules/statistics/statistics.pages.inc
+2
-2
core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php
.../Drupal/system/Tests/Common/TableSortExtenderUnitTest.php
+4
-2
core/modules/system/system.admin.inc
core/modules/system/system.admin.inc
+1
-1
core/modules/system/tests/modules/database_test/database_test.module
...s/system/tests/modules/database_test/database_test.module
+7
-2
core/modules/user/user.admin.inc
core/modules/user/user.admin.inc
+1
-1
No files found.
core/includes/tablesort.inc
View file @
c1f05ae4
...
...
@@ -12,101 +12,6 @@
* column headers that the user can click on to sort the table by that column.
*/
/**
* Query extender class for tablesort queries.
*/
class
TableSort
extends
SelectExtender
{
/**
* The array of fields that can be sorted by.
*
* @var array
*/
protected
$header
=
array
();
public
function
__construct
(
SelectInterface
$query
,
Connection
$connection
)
{
parent
::
__construct
(
$query
,
$connection
);
// Add convenience tag to mark that this is an extended query. We have to
// do this in the constructor to ensure that it is set before preExecute()
// gets called.
$this
->
addTag
(
'tablesort'
);
}
/**
* Order the query based on a header array.
*
* @see theme_table()
* @param $header
* Table header array.
* @return SelectQueryInterface
* The called object.
*/
public
function
orderByHeader
(
Array
$header
)
{
$this
->
header
=
$header
;
$ts
=
$this
->
init
();
if
(
!
empty
(
$ts
[
'sql'
]))
{
// Based on code from db_escape_table(), but this can also contain a dot.
$field
=
preg_replace
(
'/[^A-Za-z0-9_.]+/'
,
''
,
$ts
[
'sql'
]);
// Sort order can only be ASC or DESC.
$sort
=
drupal_strtoupper
(
$ts
[
'sort'
]);
$sort
=
in_array
(
$sort
,
array
(
'ASC'
,
'DESC'
))
?
$sort
:
''
;
$this
->
orderBy
(
$field
,
$sort
);
}
return
$this
;
}
/**
* Initialize the table sort context.
*/
protected
function
init
()
{
$ts
=
$this
->
order
();
$ts
[
'sort'
]
=
$this
->
getSort
();
$ts
[
'query'
]
=
$this
->
getQueryParameters
();
return
$ts
;
}
/**
* Determine the current sort direction.
*
* @param $headers
* An array of column headers in the format described in theme_table().
* @return
* The current sort direction ("asc" or "desc").
*/
protected
function
getSort
()
{
return
tablesort_get_sort
(
$this
->
header
);
}
/**
* Compose a URL query parameter array to append to table sorting requests.
*
* @return
* A URL query parameter array that consists of all components of the current
* page request except for those pertaining to table sorting.
*
* @see tablesort_get_query_parameters()
*/
protected
function
getQueryParameters
()
{
return
tablesort_get_query_parameters
();
}
/**
* Determine the current sort criterion.
*
* @param $headers
* An array of column headers in the format described in theme_table().
* @return
* An associative array describing the criterion, containing the keys:
* - "name": The localized title of the table column.
* - "sql": The name of the database field to sort on.
*/
protected
function
order
()
{
return
tablesort_get_order
(
$this
->
header
);
}
}
/**
* Initialize the table sort context.
*/
...
...
core/lib/Drupal/Core/Database/Query/TableSortExtender.php
0 → 100644
View file @
c1f05ae4
<?php
/**
* @file
* Definition of Drupal\Core\Database\Query\TableSortExtender.
*/
namespace
Drupal\Core\Database\Query
;
use
Drupal\Core\Database\Connection
;
/**
* Query extender class for tablesort queries.
*/
class
TableSortExtender
extends
SelectExtender
{
/**
* The array of fields that can be sorted by.
*/
protected
$header
=
array
();
public
function
__construct
(
SelectInterface
$query
,
Connection
$connection
)
{
parent
::
__construct
(
$query
,
$connection
);
// Add convenience tag to mark that this is an extended query. We have to
// do this in the constructor to ensure that it is set before preExecute()
// gets called.
$this
->
addTag
(
'tablesort'
);
}
/**
* Order the query based on a header array.
*
* @param array $header
* Table header array.
*
* @return SelectQueryInterface
* The called object.
*
* @see theme_table()
*/
public
function
orderByHeader
(
array
$header
)
{
$this
->
header
=
$header
;
$ts
=
$this
->
init
();
if
(
!
empty
(
$ts
[
'sql'
]))
{
// Based on code from db_escape_table(), but this can also contain a dot.
$field
=
preg_replace
(
'/[^A-Za-z0-9_.]+/'
,
''
,
$ts
[
'sql'
]);
// Sort order can only be ASC or DESC.
$sort
=
drupal_strtoupper
(
$ts
[
'sort'
]);
$sort
=
in_array
(
$sort
,
array
(
'ASC'
,
'DESC'
))
?
$sort
:
''
;
$this
->
orderBy
(
$field
,
$sort
);
}
return
$this
;
}
/**
* Initialize the table sort context.
*/
protected
function
init
()
{
$ts
=
$this
->
order
();
$ts
[
'sort'
]
=
$this
->
getSort
();
$ts
[
'query'
]
=
$this
->
getQueryParameters
();
return
$ts
;
}
/**
* Determine the current sort direction.
*
* @return
* The current sort direction ("asc" or "desc").
*
* @see tablesort_get_sort()
*/
protected
function
getSort
()
{
return
tablesort_get_sort
(
$this
->
header
);
}
/**
* Compose a URL query parameter array to append to table sorting requests.
*
* @return
* A URL query parameter array that consists of all components of the current
* page request except for those pertaining to table sorting.
*
* @see tablesort_get_query_parameters()
*/
protected
function
getQueryParameters
()
{
return
tablesort_get_query_parameters
();
}
/**
* Determine the current sort criterion.
*
* @return
* An associative array describing the criterion, containing the keys:
* - "name": The localized title of the table column.
* - "sql": The name of the database field to sort on.
*
* @see tablesort_get_order()
*/
protected
function
order
()
{
return
tablesort_get_order
(
$this
->
header
);
}
}
core/modules/comment/comment.admin.inc
View file @
c1f05ae4
...
...
@@ -81,7 +81,7 @@ function comment_admin_overview($form, &$form_state, $arg) {
$query
=
db_select
(
'comment'
,
'c'
)
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
join
(
'node'
,
'n'
,
'n.nid = c.nid'
);
$query
->
addField
(
'n'
,
'title'
,
'node_title'
);
$query
->
addTag
(
'node_access'
);
...
...
core/modules/dblog/dblog.admin.inc
View file @
c1f05ae4
...
...
@@ -39,7 +39,7 @@ function dblog_overview() {
$query
=
db_select
(
'watchdog'
,
'w'
)
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
leftJoin
(
'users'
,
'u'
,
'w.uid = u.uid'
);
$query
->
fields
(
'w'
,
array
(
'wid'
,
'uid'
,
'severity'
,
'type'
,
'timestamp'
,
'message'
,
'variables'
,
'link'
))
...
...
@@ -100,7 +100,7 @@ function dblog_top($type) {
$query
=
db_select
(
'watchdog'
,
'w'
)
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
addExpression
(
'COUNT(wid)'
,
'count'
);
$query
=
$query
->
fields
(
'w'
,
array
(
'message'
,
'variables'
))
...
...
core/modules/forum/forum.module
View file @
c1f05ae4
...
...
@@ -895,7 +895,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
$query
=
db_select
(
'forum_index'
,
'f'
)
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
fields
(
'f'
);
$query
->
condition
(
'f.tid'
,
$tid
)
...
...
@@ -918,7 +918,8 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
if
(
$nids
)
{
$nodes
=
node_load_multiple
(
$nids
);
$query
=
db_select
(
'node'
,
'n'
)
->
extend
(
'TableSort'
);
$query
=
db_select
(
'node'
,
'n'
)
->
extend
(
'Drupal\Core\Database\Query\TableSortExtender'
);
$query
->
fields
(
'n'
,
array
(
'nid'
));
$query
->
join
(
'node_comment_statistics'
,
'ncs'
,
'n.nid = ncs.nid'
);
...
...
core/modules/node/node.admin.inc
View file @
c1f05ae4
...
...
@@ -449,7 +449,7 @@ function node_admin_nodes() {
$query
=
db_select
(
'node'
,
'n'
)
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
node_build_filter_query
(
$query
);
if
(
!
user_access
(
'bypass node access'
))
{
...
...
core/modules/path/path.admin.inc
View file @
c1f05ae4
...
...
@@ -29,7 +29,7 @@ function path_admin_overview($keys = NULL) {
$query
=
db_select
(
'url_alias'
)
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
if
(
$keys
)
{
// Replace wildcards with PDO wildcards.
$query
->
condition
(
'alias'
,
'%'
.
preg_replace
(
'!\*+!'
,
'%'
,
$keys
)
.
'%'
,
'LIKE'
);
...
...
core/modules/poll/poll.pages.inc
View file @
c1f05ae4
...
...
@@ -58,7 +58,7 @@ function poll_votes($node) {
$select
=
db_select
(
'poll_vote'
,
'pv'
)
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$select
->
join
(
'poll_choice'
,
'pc'
,
'pv.chid = pc.chid'
);
$select
->
join
(
'users'
,
'u'
,
'pv.uid = u.uid'
);
$queried_votes
=
$select
...
...
core/modules/statistics/statistics.admin.inc
View file @
c1f05ae4
...
...
@@ -27,7 +27,7 @@ function statistics_recent_hits() {
$query
=
db_select
(
'accesslog'
,
'a'
,
array
(
'target'
=>
'slave'
))
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
join
(
'users'
,
'u'
,
'a.uid = u.uid'
);
$query
->
fields
(
'a'
,
array
(
'aid'
,
'timestamp'
,
'path'
,
'title'
,
'uid'
))
...
...
@@ -75,7 +75,7 @@ function statistics_top_pages() {
$query
=
db_select
(
'accesslog'
,
'a'
,
array
(
'target'
=>
'slave'
))
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
addExpression
(
'COUNT(path)'
,
'hits'
);
// MAX(title) avoids having empty node titles which otherwise causes
// duplicates in the top pages list.
...
...
@@ -130,7 +130,7 @@ function statistics_top_visitors() {
);
$query
=
db_select
(
'accesslog'
,
'a'
,
array
(
'target'
=>
'slave'
))
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
leftJoin
(
'blocked_ips'
,
'bl'
,
'a.hostname = bl.ip'
);
$query
->
leftJoin
(
'users'
,
'u'
,
'a.uid = u.uid'
);
...
...
@@ -192,7 +192,7 @@ function statistics_top_referrers() {
);
$query
=
db_select
(
'accesslog'
,
'a'
)
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
addExpression
(
'COUNT(url)'
,
'hits'
);
$query
->
addExpression
(
'MAX(timestamp)'
,
'last'
);
...
...
core/modules/statistics/statistics.pages.inc
View file @
c1f05ae4
...
...
@@ -27,7 +27,7 @@ function statistics_node_tracker() {
$query
=
db_select
(
'accesslog'
,
'a'
,
array
(
'target'
=>
'slave'
))
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
join
(
'users'
,
'u'
,
'a.uid = u.uid'
);
$query
...
...
@@ -83,7 +83,7 @@ function statistics_user_tracker() {
array
(
'data'
=>
t
(
'Operations'
)));
$query
=
db_select
(
'accesslog'
,
'a'
,
array
(
'target'
=>
'slave'
))
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
fields
(
'a'
,
array
(
'aid'
,
'timestamp'
,
'path'
,
'title'
))
->
condition
(
'uid'
,
$account
->
uid
)
...
...
core/modules/system/
tests/tablesort.test
→
core/modules/system/
lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php
View file @
c1f05ae4
...
...
@@ -2,15 +2,17 @@
/**
* @file
*
Various tablesort tests
.
*
Definition of Drupal\system\Tests\Common\TableSortExtenderTest
.
*/
namespace
Drupal\system\Tests\Common
;
use
Drupal\simpletest\UnitTestBase
;
/**
* Test unicode handling features implemented in unicode.inc.
*/
class
TableSortTest
extends
UnitTestBase
{
class
TableSort
ExtenderUnit
Test
extends
UnitTestBase
{
/**
* Storage for initial value of $_GET.
...
...
core/modules/system/system.admin.inc
View file @
c1f05ae4
...
...
@@ -2924,7 +2924,7 @@ function system_actions_manage() {
);
$query
=
db_select
(
'actions'
)
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$result
=
$query
->
fields
(
'actions'
)
->
limit
(
50
)
...
...
core/modules/system/tests/modules/database_test/database_test.module
View file @
c1f05ae4
...
...
@@ -161,7 +161,9 @@ function database_test_tablesort() {
$query
->
fields
(
't'
,
array
(
'tid'
,
'pid'
,
'task'
,
'priority'
));
$query
=
$query
->
extend
(
'TableSort'
)
->
orderByHeader
(
$header
);
$query
=
$query
->
extend
(
'Drupal\Core\Database\Query\TableSortExtender'
)
->
orderByHeader
(
$header
);
// We need all the results at once to check the sort.
$tasks
=
$query
->
execute
()
->
fetchAll
();
...
...
@@ -190,7 +192,10 @@ function database_test_tablesort_first() {
$query
->
fields
(
't'
,
array
(
'tid'
,
'pid'
,
'task'
,
'priority'
));
$query
=
$query
->
extend
(
'TableSort'
)
->
orderByHeader
(
$header
)
->
orderBy
(
'priority'
);
$query
=
$query
->
extend
(
'Drupal\Core\Database\Query\TableSortExtender'
)
->
orderByHeader
(
$header
)
->
orderBy
(
'priority'
);
// We need all the results at once to check the sort.
$tasks
=
$query
->
execute
()
->
fetchAll
();
...
...
core/modules/user/user.admin.inc
View file @
c1f05ae4
...
...
@@ -160,7 +160,7 @@ function user_admin_account() {
$query
=
$query
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
extend
(
'
TableSort
'
);
->
extend
(
'
Drupal\Core\Database\Query\TableSortExtender
'
);
$query
->
fields
(
'u'
,
array
(
'uid'
,
'name'
,
'status'
,
'created'
,
'access'
))
->
limit
(
50
)
...
...
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