Jump to:
| Project: | Views Alpha Pager |
| Version: | 5.x-1.4 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
It was brought to my attention by a client that the title sort was not being done correctly. After looking at the queries generated on Views with the views_alpha pager, I noticed that the order clause was incorrectly using the following as the first order clause.
ORDER BY
(LEFT(TRIM(LEADING 'AND ' FROM (TRIM(LEADING 'THE ' FROM (TRIM(LEADING 'A ' FROM (TRIM(LEADING '\'' FROM (TRIM(LEADING '"' FROM (TRIM(LEADING ' ' FROM (UPPER(node.title))))))))))))),1) = 'A')I can only assume that it would be best to sort the query by the full value after the Leading Trim words were removed, like so
(TRIM(LEADING 'AND ' FROM (TRIM(LEADING 'THE ' FROM (TRIM(LEADING 'A ' FROM (TRIM(LEADING '\'' FROM (TRIM(LEADING '"' FROM (TRIM(LEADING ' ' FROM (UPPER(node.title)))))))))))))I found the bug at line 138-150 in the views_alpha_pager.module:
$myfield = 'UPPER('. $sort_field .')';
if ($ignore = variable_get('views_alpha_pager_ignore', 'a the and')) {
$trimterms = array(' ', '"', '\\\'');
foreach (explode(' ', $ignore) as $word) {
$trimterms[] = check_plain($word) .' ';
}
// use the ignore words to trim sort field
foreach ($trimterms as $trim) {
$myfield = "TRIM(LEADING '". strtoupper($trim) ."' FROM ($myfield))";
}
}
$myfield = "LEFT($myfield, 1)";However, if you sort by the first character of the field, the sort results we not sorter properly.
So I simply changed line 150 to the following:
$myfield_filter = "LEFT($myfield,1)";I then replaced $myfield with $myfield_filter where $myfield was being used in WHERE statements.
I've attached a patch file for your review.
| Attachment | Size |
|---|---|
| views_alpha_pager.module.patch | 2.16 KB |
Comments
#1
I encountered the same problem, and your patch fixed it quite nicely. Can we get this rolled into the official release?