mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix sort() not working.
This commit is contained in:
parent
57d50cd018
commit
771efd950e
2 changed files with 10 additions and 32 deletions
|
@ -804,7 +804,6 @@ class Set2Test extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testSort() {
|
||||
$this->markTestIncomplete('Not done, sort() is broken.');
|
||||
$a = array(
|
||||
0 => array(
|
||||
'Person' => array('name' => 'Jeff'),
|
||||
|
@ -882,36 +881,6 @@ class Set2Test extends CakeTestCase {
|
|||
$a = Set2::sort($a, '{n}.Person.name', 'asc');
|
||||
$this->assertEquals($a, $b);
|
||||
|
||||
$a = array(
|
||||
array(7,6,4),
|
||||
array(3,4,5),
|
||||
array(3,2,1),
|
||||
);
|
||||
|
||||
$b = array(
|
||||
array(3,2,1),
|
||||
array(3,4,5),
|
||||
array(7,6,4),
|
||||
);
|
||||
|
||||
$a = Set2::sort($a, '{n}.{n}', 'asc');
|
||||
$this->assertEquals($a, $b);
|
||||
|
||||
$a = array(
|
||||
array(7,6,4),
|
||||
array(3,4,5),
|
||||
array(3,2,array(1,1,1)),
|
||||
);
|
||||
|
||||
$b = array(
|
||||
array(3,2,array(1,1,1)),
|
||||
array(3,4,5),
|
||||
array(7,6,4),
|
||||
);
|
||||
|
||||
$a = Set2::sort($a, '{n}', 'asc');
|
||||
$this->assertEquals($a, $b);
|
||||
|
||||
$a = array(
|
||||
0 => array('Person' => array('name' => 'Jeff')),
|
||||
1 => array('Shirt' => array('color' => 'black'))
|
||||
|
|
|
@ -538,7 +538,16 @@ class Set2 {
|
|||
if (is_numeric(implode('', $originalKeys))) {
|
||||
$data = array_values($data);
|
||||
}
|
||||
$result = self::_squash(self::extract($data, $path));
|
||||
$sortValues = self::extract($data, $path);
|
||||
$sortCount = count($sortValues);
|
||||
$dataCount = count($data);
|
||||
|
||||
// Make sortValues match the data length, as some keys could be missing
|
||||
// the sorted value path.
|
||||
if ($sortCount < $dataCount) {
|
||||
$sortValues = array_pad($sortValues, $dataCount, null);
|
||||
}
|
||||
$result = self::_squash($sortValues);
|
||||
$keys = self::extract($result, '{n}.id');
|
||||
$values = self::extract($result, '{n}.value');
|
||||
|
||||
|
|
Loading…
Reference in a new issue