1 | <?php |
||
19 | class Manager |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | const DEFAULT_SORT_COLUMN = 'date_update'; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | const DEFAULT_SORT_DIRECTION = 'DESC'; |
||
30 | |||
31 | /** |
||
32 | * @var DriverInterface |
||
33 | */ |
||
34 | protected $driver; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | public static $sort_columns = [ |
||
40 | 'name', |
||
41 | 'date_update', |
||
42 | 'rating', |
||
43 | 'date_premiere', |
||
44 | 'date_end', |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | public static $sort_direction = [ |
||
51 | 'DESC', |
||
52 | 'ASC', |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * @param DriverInterface $driver |
||
57 | */ |
||
58 | 13 | public function __construct(DriverInterface $driver) |
|
62 | |||
63 | /** |
||
64 | * @param Search $data |
||
65 | * @param int|null $limit |
||
66 | * @param int|null $offset |
||
67 | * @param string|null $sort_column |
||
68 | * @param string|null $sort_direction |
||
69 | * |
||
70 | * @return array {list:[],total:0} |
||
71 | */ |
||
72 | 3 | public function search( |
|
73 | Search $data, |
||
74 | $limit = 0, |
||
75 | $offset = 0, |
||
76 | $sort_column = self::DEFAULT_SORT_COLUMN, |
||
77 | $sort_direction = self::DEFAULT_SORT_DIRECTION |
||
78 | ) { |
||
79 | 3 | return $this->driver->search( |
|
80 | $data, |
||
81 | 3 | ($limit > 0 ? (int) $limit : 0), |
|
82 | 3 | ($offset > 0 ? (int) $offset : 0), |
|
83 | 3 | $this->getValidSortColumn($sort_column), |
|
84 | 3 | $this->getValidSortDirection($sort_direction) |
|
85 | ); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @param string $name |
||
90 | * @param int $limit |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | 1 | public function searchByName($name, $limit = 0) |
|
98 | |||
99 | /** |
||
100 | * @param string|null $column |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 9 | public function getValidSortColumn($column = self::DEFAULT_SORT_COLUMN) |
|
108 | |||
109 | /** |
||
110 | * @param string|null $direction |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 6 | public function getValidSortDirection($direction = self::DEFAULT_SORT_DIRECTION) |
|
118 | } |
||
119 |