|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright © Thomas Klein, All rights reserved. |
|
4
|
|
|
*/ |
|
5
|
|
|
declare(strict_types=1); |
|
6
|
|
|
|
|
7
|
|
|
namespace Zoho\Desk\Model; |
|
8
|
|
|
|
|
9
|
|
|
use function implode; |
|
10
|
|
|
|
|
11
|
|
|
final class ListCriteria implements ListCriteriaInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var string[] |
|
15
|
|
|
*/ |
|
16
|
|
|
private array $fields; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string[] |
|
20
|
|
|
*/ |
|
21
|
|
|
private array $filters; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string[] |
|
25
|
|
|
*/ |
|
26
|
|
|
private array $include; |
|
27
|
|
|
|
|
28
|
|
|
private ?int $from; |
|
29
|
|
|
|
|
30
|
|
|
private ?int $limit; |
|
31
|
|
|
|
|
32
|
|
|
private ?string $sortBy; |
|
33
|
|
|
|
|
34
|
|
|
private ?string $sortOrder; |
|
35
|
|
|
|
|
36
|
|
|
private ?int $viewId; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct( |
|
39
|
|
|
array $filters, |
|
40
|
|
|
array $fields, |
|
41
|
|
|
array $include, |
|
42
|
|
|
?int $from, |
|
43
|
|
|
?int $limit, |
|
44
|
|
|
?string $sortBy, |
|
45
|
|
|
?string $sortOrder, |
|
46
|
|
|
?int $viewId |
|
47
|
|
|
) { |
|
48
|
|
|
$this->filters = $filters; |
|
49
|
|
|
$this->fields = $fields; |
|
50
|
|
|
$this->include = $include; |
|
51
|
|
|
$this->from = $from; |
|
52
|
|
|
$this->limit = $limit; |
|
53
|
|
|
$this->sortBy = $sortBy; |
|
54
|
|
|
$this->sortOrder = $sortOrder; |
|
55
|
|
|
$this->viewId = $viewId; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getFilters(): array |
|
59
|
|
|
{ |
|
60
|
|
|
return (array) $this->filters; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getFields(): array |
|
64
|
|
|
{ |
|
65
|
|
|
return (array) $this->fields; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getInclude(): array |
|
69
|
|
|
{ |
|
70
|
|
|
return (array) $this->include; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getFrom(): ?int |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->from ? (int) $this->from : null; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getLimit(): ?int |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->limit ? (int) $this->limit : null; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getSortBy(): ?string |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->sortBy ? (string) $this->sortBy : null; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getSortOrder(): ?string |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->sortOrder ? (string) $this->sortOrder : null; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getViewId(): ?int |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->viewId ? (int) $this->viewId : null; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function getQueryParams(): array |
|
99
|
|
|
{ |
|
100
|
|
|
$query = $this->getFilters(); |
|
101
|
|
|
|
|
102
|
|
|
if (!$query) { |
|
|
|
|
|
|
103
|
|
|
if ($this->getFields()) { |
|
104
|
|
|
$query['fields'] = implode(',', $this->getFields()); |
|
105
|
|
|
} |
|
106
|
|
|
if ($this->getInclude()) { |
|
107
|
|
|
$query['include'] = implode(',', $this->getInclude()); |
|
108
|
|
|
} |
|
109
|
|
|
if ($this->getViewId()) { |
|
|
|
|
|
|
110
|
|
|
$query['viewId'] = $this->getViewId(); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
if ($this->getFrom()) { |
|
|
|
|
|
|
114
|
|
|
$query['from'] = $this->getFrom(); |
|
115
|
|
|
} |
|
116
|
|
|
if ($this->getLimit()) { |
|
|
|
|
|
|
117
|
|
|
$query['limit'] = $this->getLimit(); |
|
118
|
|
|
} |
|
119
|
|
|
if ($this->getSortBy()) { |
|
120
|
|
|
$query['sortBy'] = ($this->getSortOrder() === 'DESC' ? '-' : '') . $this->getSortBy(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return $query; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.