Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
Base | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
sortByName | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
sortWithCollator | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * @package Zmsdldb |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsdldb\Collection; |
9 | |
10 | use BO\Zmsdldb\Helper\Sorter; |
11 | |
12 | class Base extends \ArrayObject |
13 | { |
14 | public function sortByName() |
15 | { |
16 | $itemList = clone $this; |
17 | $itemList->uasort(function ($a, $b) { |
18 | return strcmp(Sorter::toSortableString($a->getName()), Sorter::toSortableString($b->getName())); |
19 | }); |
20 | return $itemList; |
21 | } |
22 | |
23 | public function sortWithCollator($field = 'name', $locale = 'de') |
24 | { |
25 | $collator = collator_create($locale); |
26 | $collator->setStrength(\Collator::QUATERNARY); |
27 | $collator->setAttribute(\Collator::QUATERNARY, \Collator::ON); |
28 | $collator->setAttribute(\Collator::CASE_FIRST, \Collator::ON); |
29 | $collator->setAttribute(\Collator::NUMERIC_COLLATION, \Collator::ON); |
30 | |
31 | $itemList = clone $this; |
32 | $itemList->uasort(function ($itemA, $itemB) use ($collator, $field) { |
33 | return collator_compare($collator, $itemA[$field], $itemB[$field]); |
34 | }); |
35 | return $itemList; |
36 | } |
37 | } |