1 | <?php |
||
9 | class SortOperation implements OperationInterface |
||
10 | { |
||
11 | const ASC = 'asc'; |
||
12 | const DESC = 'desc'; |
||
13 | |||
14 | protected $order; |
||
15 | |||
16 | protected $field; |
||
17 | |||
18 | /** |
||
19 | * Creates operation for sorting rows ascending based on values of target field. |
||
20 | * |
||
21 | * @param string $field name of data field to sort rows by its value |
||
22 | * @return SortOperation |
||
23 | */ |
||
24 | public static function asc($field) |
||
28 | |||
29 | /** |
||
30 | * Creates operation for sorting rows ascending based on values of target field. |
||
31 | * |
||
32 | * @param string $field name of data field to sort rows by its value |
||
33 | * @return SortOperation |
||
34 | */ |
||
35 | public static function desc($field) |
||
39 | |||
40 | /** |
||
41 | * Constructor. |
||
42 | * |
||
43 | * @param string|null $field name of data field to sort rows by its value |
||
44 | * @param string $order (optional, default value: 'asc'), |
||
45 | * please use SortOperation::ASC and SortOperation::DESC constants. |
||
46 | */ |
||
47 | 3 | public function __construct($field = null, $order = SortOperation::ASC) |
|
52 | |||
53 | /** |
||
54 | * Returns sorting order ('asc' or 'desc'). |
||
55 | * @return string |
||
56 | */ |
||
57 | 3 | public function getOrder() |
|
61 | |||
62 | /** |
||
63 | * Sets sorting order. |
||
64 | * |
||
65 | * @param string $order 'asc' (ascending) or 'desc' (descending), |
||
66 | * please use SortOperation::ASC and SortOperation::DESC constants. |
||
67 | * @return $this |
||
68 | */ |
||
69 | 3 | public function setOrder($order) |
|
74 | |||
75 | /** |
||
76 | * Returns name of data field to sort rows by its value. |
||
77 | * @return string |
||
78 | */ |
||
79 | 3 | public function getField() |
|
83 | |||
84 | /** |
||
85 | * Sets name of data field to sort rows by its value. |
||
86 | * |
||
87 | * @param string $field |
||
88 | * @return $this |
||
89 | */ |
||
90 | 3 | public function setField($field) |
|
95 | } |
||
96 |