public function LdapQuery::sortResults in Lightweight Directory Access Protocol (LDAP) 8.4
Same name and namespace in other branches
- 8.3 ldap_query/src/Plugin/views/query/LdapQuery.php \Drupal\ldap_query\Plugin\views\query\LdapQuery::sortResults()
Sort the results.
@todo Should be private, public for easier testing.
Parameters
array $rows: Results to operate on.
Return value
array Result data.
1 call to LdapQuery::sortResults()
- LdapQuery::execute in ldap_query/
src/ Plugin/ views/ query/ LdapQuery.php - Execute the query.
File
- ldap_query/
src/ Plugin/ views/ query/ LdapQuery.php, line 149
Class
- LdapQuery
- Views query plugin for an SQL query.
Namespace
Drupal\ldap_query\Plugin\views\queryCode
public function sortResults(array $rows) : array {
$sorts = $this->orderby;
foreach ($sorts as $sort) {
foreach ($rows as $key => $row) {
$rows[$key]['sort_' . $sort['field']] = $row[$sort['field']][0] ?? '';
}
}
$multisortParameters = [];
foreach ($sorts as $sort) {
$multisortParameters[] = array_column($rows, 'sort_' . $sort['field']);
$multisortParameters[] = mb_strtoupper($sort['direction']) === 'ASC' ? SORT_ASC : SORT_DESC;
}
$multisortParameters[] =& $rows;
array_multisort(...$multisortParameters);
return $rows;
}