Skip to content

Commit

Permalink
Fix #461 - use age bracket rank for sorting, and add age bracket and …
Browse files Browse the repository at this point in the history
…familyid as secondary sort fields
  • Loading branch information
tbar0970 committed Oct 11, 2018
1 parent 0375136 commit 8baa801
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion db_objects/person_query.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,8 @@ function getSQL($select_fields=NULL)
} else if (0 === strpos($params['sort_by'], self::CUSTOMFIELD_PREFIX)) {
$customOrder = substr($params['sort_by'], 14);
}
$query['from'] .= '
JOIN age_bracket absort ON absort.id = p.age_bracketid ';
if ($customOrder) {
$query['from'] .= ' LEFT JOIN custom_field_value cfvorder ON cfvorder.personid = p.id AND cfvorder.fieldid = '.$db->quote($customOrder)."\n";
$query['from'] .= " LEFT JOIN custom_field_option cfoorder ON cfoorder.id = cfvorder.value_optionid \n";
Expand All @@ -1295,6 +1297,8 @@ function getSQL($select_fields=NULL)
$query['from'] .= '
LEFT JOIN congregation cord ON p.congregationid = cord.id ';
$query['order_by'] = 'IF(cord.id IS NULL, 1, 0), IF(LENGTH(cord.meeting_time)>0, 0, 1), cord.meeting_time, cord.name';
} else if ($params['sort_by'] == 'p.age_bracketid') {
$query['order_by'] = 'absort.rank';
} else {
$query['order_by'] = $this->_quoteAliasAndColumn($params['sort_by']);
}
Expand Down Expand Up @@ -1331,7 +1335,7 @@ function getSQL($select_fields=NULL)
';
}
$sql .= "\nGROUP BY ".implode(', ', $query['group_by']);
$sql .= "\nORDER BY ".$query['order_by'].', p.last_name, p.first_name';
$sql .= "\nORDER BY ".$query['order_by'].', p.last_name, p.familyid, absort.rank, IF (absort.is_adult, p.gender, 1) DESC, p.first_name';

return $sql;
}
Expand Down

0 comments on commit 8baa801

Please sign in to comment.