Conditions | 7 |
Paths | 11 |
Total Lines | 32 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
27 | final protected function addOrder(QueryBuilder $builder, array $sort, string $defaultEntity, array $aliasMapping = [], string $defaultOrder = 'asc'): QueryBuilder |
||
28 | { |
||
29 | foreach ($sort as $field => $order) { |
||
30 | if (\is_int($field)) { |
||
31 | $field = $order; |
||
32 | $order = $defaultOrder; |
||
33 | } |
||
34 | |||
35 | $fieldSpl = explode('.', $field); |
||
36 | |||
37 | if (\count($fieldSpl) > 2) { |
||
38 | continue; |
||
39 | } |
||
40 | |||
41 | $table = $defaultEntity; |
||
42 | |||
43 | // Map entity to table name |
||
44 | if (2 === \count($fieldSpl)) { |
||
45 | foreach ($aliasMapping as $k => $v) { |
||
46 | if ($fieldSpl[0] === $k) { |
||
47 | $table = $v; |
||
48 | $field = $fieldSpl[1]; |
||
49 | |||
50 | break; |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | |||
55 | $builder->addOrderBy($table.'.'.$field, $order); |
||
56 | } |
||
57 | |||
58 | return $builder; |
||
59 | } |
||
61 |