Skip to content

Commit

Permalink
Fix sorting on the Member: Activation field, apply sorting tweaks to …
Browse files Browse the repository at this point in the history
…Activation & Role fields
  • Loading branch information
Brendan Abbott committed Jun 17, 2011
1 parent 9903bea commit 6ddff55
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
17 changes: 15 additions & 2 deletions fields/field.memberactivation.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,21 @@ public function prepareTableValue($data, XMLElement $link=NULL) {
-------------------------------------------------------------------------*/

public function buildSortingSQL(&$joins, &$where, &$sort, $order='ASC') {
$joins .= "INNER JOIN `tbl_entries_data_".$this->get('id')."` AS `ed` ON (`e`.`id` = `ed`.`entry_id`) ";
$sort .= 'ORDER BY ' . (strtolower($order) == 'random' ? 'RAND()' : "`ed`.`activated` $order");
if(in_array(strtolower($order), array('random', 'rand'))) {
$sort = 'ORDER BY RAND()';
}
else {
$sort = sprintf(
'ORDER BY (
SELECT %s
FROM tbl_entries_data_%d AS `ed`
WHERE entry_id = e.id
) %s',
'`ed`.activated',
$this->get('id'),
$order
);
}
}

/*-------------------------------------------------------------------------
Expand Down
17 changes: 15 additions & 2 deletions fields/field.memberrole.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,21 @@ public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation=false
-------------------------------------------------------------------------*/

public function buildSortingSQL(&$joins, &$where, &$sort, $order='ASC') {
$joins .= "INNER JOIN `tbl_entries_data_".$this->get('id')."` AS `ed` ON (`e`.`id` = `ed`.`entry_id`) ";
$sort .= 'ORDER BY ' . (strtolower($order) == 'random' ? 'RAND()' : "`ed`.`role_id` $order");
if(in_array(strtolower($order), array('random', 'rand'))) {
$sort = 'ORDER BY RAND()';
}
else {
$sort = sprintf(
'ORDER BY (
SELECT %s
FROM tbl_entries_data_%d AS `ed`
WHERE entry_id = e.id
) %s',
'`ed`.role_id',
$this->get('id'),
$order
);
}
}

/*-------------------------------------------------------------------------
Expand Down

0 comments on commit 6ddff55

Please sign in to comment.