Total Complexity | 12 |
Total Lines | 91 |
Duplicated Lines | 0 % |
Coverage | 51.85% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
4 | class Order extends Dto |
||
5 | { |
||
6 | const ASC = 'ASC'; |
||
7 | const DESC = 'DESC'; |
||
8 | /** |
||
9 | * Fields to use to order |
||
10 | * @var array fields |
||
11 | */ |
||
12 | protected $fields = array(); |
||
13 | |||
14 | /** |
||
15 | * Add new order to dto |
||
16 | * |
||
17 | * @param string $field |
||
18 | * @param string $direction |
||
19 | */ |
||
20 | 1 | public function addOrder($field, $direction = self::ASC) |
|
21 | { |
||
22 | 1 | $this->fields[$field] = $direction; |
|
23 | 1 | } |
|
24 | |||
25 | /** |
||
26 | * Remove existing order |
||
27 | * |
||
28 | * @param string $fieldToRemove |
||
29 | */ |
||
30 | 1 | public function removeOrder($fieldToRemove) |
|
31 | { |
||
32 | 1 | $order = array(); |
|
33 | 1 | if (count($order) > 0) { |
|
34 | foreach ($this->fields as $field => $direction) { |
||
35 | if (strtolower($fieldToRemove) === strtolower($field)) { |
||
36 | continue; |
||
37 | } |
||
38 | $order[$field] = $direction; |
||
39 | } |
||
40 | } |
||
41 | 1 | $this->fields = $order; |
|
42 | 1 | } |
|
43 | |||
44 | /** |
||
45 | * Set an order field |
||
46 | * |
||
47 | * @param string $field |
||
48 | * @param string $direction |
||
49 | */ |
||
50 | public function setOrder($field, $direction = self::ASC) |
||
51 | { |
||
52 | $this->fields = [$field => $direction]; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Parse direction string |
||
57 | * @param string $direction |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | public static function parseDirection($direction = self::ASC) |
||
62 | { |
||
63 | if (preg_match('/^asc$/i', $direction)) { |
||
64 | return self::ASC; |
||
65 | } else { |
||
66 | return self::DESC; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Return all order fields |
||
72 | * @return array |
||
73 | */ |
||
74 | public function getOrders() |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param array $object |
||
81 | */ |
||
82 | 1 | public function fromArray(array $object = array()) |
|
86 | } |
||
87 | 1 | } |
|
88 | |||
89 | /** |
||
90 | * @return array |
||
91 | */ |
||
92 | 1 | public function toArray() |
|
95 | } |
||
96 | } |