function ViewsKernelTestBase::orderResultSet

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/ViewsKernelTestBase.php \Drupal\Tests\views\Kernel\ViewsKernelTestBase::orderResultSet()
  2. 10 core/modules/views/tests/src/Kernel/ViewsKernelTestBase.php \Drupal\Tests\views\Kernel\ViewsKernelTestBase::orderResultSet()
  3. 11.x core/modules/views/tests/src/Kernel/ViewsKernelTestBase.php \Drupal\Tests\views\Kernel\ViewsKernelTestBase::orderResultSet()

Orders a nested array containing a result set based on a given column.

Parameters

array $result_set: An array of rows from a result set, with each row as an associative array keyed by column name.

string $column: The column name by which to sort the result set.

bool $reverse: (optional) Boolean indicating whether to sort the result set in reverse order. Defaults to FALSE.

Return value

array The sorted result set.

2 calls to ViewsKernelTestBase::orderResultSet()
SortTest::testNumericOrdering in core/modules/views/tests/src/Kernel/Handler/SortTest.php
Tests numeric ordering of the result set.
SortTest::testStringOrdering in core/modules/views/tests/src/Kernel/Handler/SortTest.php
Tests string ordering of the result set.

File

core/modules/views/tests/src/Kernel/ViewsKernelTestBase.php, line 109

Class

ViewsKernelTestBase
Defines a base class for Views kernel testing.

Namespace

Drupal\Tests\views\Kernel

Code

protected function orderResultSet($result_set, $column, $reverse = FALSE) {
    $order = $reverse ? -1 : 1;
    usort($result_set, function ($a, $b) use ($column, $order) {
        if ($a[$column] == $b[$column]) {
            return 0;
        }
        return $order * ($a[$column] < $b[$column] ? -1 : 1);
    });
    return $result_set;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.