|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace AmoCRM\Filters; |
| 6 | + |
| 7 | +use AmoCRM\Filters\Interfaces\HasPagesInterface; |
| 8 | +use AmoCRM\Filters\Traits\ArrayOrNumericFilterTrait; |
| 9 | +use AmoCRM\Filters\Traits\ArrayOrStringFilterTrait; |
| 10 | +use AmoCRM\Filters\Traits\IntOrIntRangeFilterTrait; |
| 11 | +use AmoCRM\Filters\Traits\PagesFilterTrait; |
| 12 | + |
| 13 | +use function implode; |
| 14 | +use function is_null; |
| 15 | + |
| 16 | +class FilesFilter extends BaseEntityFilter implements HasPagesInterface |
| 17 | +{ |
| 18 | + use ArrayOrNumericFilterTrait; |
| 19 | + use ArrayOrStringFilterTrait; |
| 20 | + use IntOrIntRangeFilterTrait; |
| 21 | + use PagesFilterTrait; |
| 22 | + |
| 23 | + /** @var array|null */ |
| 24 | + private $uuid; |
| 25 | + |
| 26 | + /** @var string|null */ |
| 27 | + private $name; |
| 28 | + |
| 29 | + /** @var array|null */ |
| 30 | + private $extensions; |
| 31 | + |
| 32 | + /** @var string|null */ |
| 33 | + private $term; |
| 34 | + |
| 35 | + /** @var int|null */ |
| 36 | + private $sourceId; |
| 37 | + |
| 38 | + /** @var bool */ |
| 39 | + private $deleted = false; |
| 40 | + |
| 41 | + /** @var array|null */ |
| 42 | + private $size; |
| 43 | + |
| 44 | + /** @var array|null */ |
| 45 | + private $date; |
| 46 | + |
| 47 | + /** @var array|null */ |
| 48 | + private $createdBy; |
| 49 | + |
| 50 | + /** @var array|null */ |
| 51 | + private $updatedBy; |
| 52 | + |
| 53 | + public function getUuid(): ?array |
| 54 | + { |
| 55 | + return $this->uuid; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @param array|string|null $uuid |
| 60 | + * @return FilesFilter |
| 61 | + */ |
| 62 | + public function setUuid($uuid): self |
| 63 | + { |
| 64 | + $this->uuid = $this->parseArrayOrStringFilter($uuid); |
| 65 | + |
| 66 | + return $this; |
| 67 | + } |
| 68 | + |
| 69 | + public function getName(): ?string |
| 70 | + { |
| 71 | + return $this->name; |
| 72 | + } |
| 73 | + |
| 74 | + public function setName(?string $name): self |
| 75 | + { |
| 76 | + $this->name = $name; |
| 77 | + |
| 78 | + return $this; |
| 79 | + } |
| 80 | + |
| 81 | + public function getExtensions(): ?array |
| 82 | + { |
| 83 | + return $this->extensions; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @param array|string|null $extensions |
| 88 | + * @return FilesFilter |
| 89 | + */ |
| 90 | + public function setExtensions($extensions): self |
| 91 | + { |
| 92 | + $this->extensions = $this->parseArrayOrStringFilter($extensions); |
| 93 | + |
| 94 | + return $this; |
| 95 | + } |
| 96 | + |
| 97 | + public function getTerm(): ?string |
| 98 | + { |
| 99 | + return $this->term; |
| 100 | + } |
| 101 | + |
| 102 | + public function setTerm(?string $term): self |
| 103 | + { |
| 104 | + $this->term = $term; |
| 105 | + |
| 106 | + return $this; |
| 107 | + } |
| 108 | + |
| 109 | + public function getSourceId(): ?int |
| 110 | + { |
| 111 | + return $this->sourceId; |
| 112 | + } |
| 113 | + |
| 114 | + public function setSourceId(?int $sourceId): self |
| 115 | + { |
| 116 | + $this->sourceId = $sourceId; |
| 117 | + |
| 118 | + return $this; |
| 119 | + } |
| 120 | + |
| 121 | + public function getDeleted(): bool |
| 122 | + { |
| 123 | + return $this->deleted; |
| 124 | + } |
| 125 | + |
| 126 | + public function setDeleted(bool $deleted): self |
| 127 | + { |
| 128 | + $this->deleted = $deleted; |
| 129 | + |
| 130 | + return $this; |
| 131 | + } |
| 132 | + |
| 133 | + public function getSize(): ?array |
| 134 | + { |
| 135 | + return $this->size; |
| 136 | + } |
| 137 | + |
| 138 | + public function setSize(?BaseRangeFilter $sizeRange = null, ?int $sizeUnit = null): self |
| 139 | + { |
| 140 | + $size = null; |
| 141 | + |
| 142 | + if (!is_null($sizeRange)) { |
| 143 | + $size = $this->parseIntOrIntRangeFilter($sizeRange); |
| 144 | + } |
| 145 | + |
| 146 | + if (!is_null($sizeUnit)) { |
| 147 | + $size['unit'] = $sizeUnit; |
| 148 | + } |
| 149 | + |
| 150 | + $this->size = $size; |
| 151 | + |
| 152 | + return $this; |
| 153 | + } |
| 154 | + |
| 155 | + public function getDate(): ?array |
| 156 | + { |
| 157 | + return $this->date; |
| 158 | + } |
| 159 | + |
| 160 | + public function setDate( |
| 161 | + ?BaseRangeFilter $dateRange = null, |
| 162 | + ?string $dateType = null, |
| 163 | + ?string $datePreset = null |
| 164 | + ): self { |
| 165 | + $date = null; |
| 166 | + |
| 167 | + if (!is_null($dateRange)) { |
| 168 | + $date = $this->parseIntOrIntRangeFilter($dateRange); |
| 169 | + } |
| 170 | + |
| 171 | + if (!is_null($dateType)) { |
| 172 | + $date['type'] = $dateType; |
| 173 | + } |
| 174 | + |
| 175 | + if (!is_null($datePreset)) { |
| 176 | + $date['date_preset'] = $datePreset; |
| 177 | + } |
| 178 | + |
| 179 | + $this->date = $date; |
| 180 | + |
| 181 | + return $this; |
| 182 | + } |
| 183 | + |
| 184 | + public function getCreatedBy(): ?array |
| 185 | + { |
| 186 | + return $this->createdBy; |
| 187 | + } |
| 188 | + |
| 189 | + /** |
| 190 | + * @param array|int|null $createdBy |
| 191 | + * @return FilesFilter |
| 192 | + */ |
| 193 | + public function setCreatedBy($createdBy): self |
| 194 | + { |
| 195 | + $this->createdBy = $this->parseArrayOrNumberFilter($createdBy); |
| 196 | + |
| 197 | + return $this; |
| 198 | + } |
| 199 | + |
| 200 | + public function getUpdatedBy(): ?array |
| 201 | + { |
| 202 | + return $this->updatedBy; |
| 203 | + } |
| 204 | + |
| 205 | + /** |
| 206 | + * @param array|int|null $updatedBy |
| 207 | + * @return FilesFilter |
| 208 | + */ |
| 209 | + public function setUpdatedBy($updatedBy): self |
| 210 | + { |
| 211 | + $this->updatedBy = $this->parseArrayOrNumberFilter($updatedBy); |
| 212 | + |
| 213 | + return $this; |
| 214 | + } |
| 215 | + |
| 216 | + public function buildFilter(): array |
| 217 | + { |
| 218 | + $filter = []; |
| 219 | + |
| 220 | + if (!is_null($this->getUuid())) { |
| 221 | + $filter['filter']['uuid'] = implode(',', $this->getUuid()); |
| 222 | + } |
| 223 | + |
| 224 | + if (!is_null($this->getName())) { |
| 225 | + $filter['filter']['name'] = $this->getName(); |
| 226 | + } |
| 227 | + |
| 228 | + if (!is_null($this->getExtensions())) { |
| 229 | + $filter['filter']['extensions'] = $this->getExtensions(); |
| 230 | + } |
| 231 | + |
| 232 | + if (!is_null($this->getTerm())) { |
| 233 | + $filter['filter']['term'] = $this->getTerm(); |
| 234 | + } |
| 235 | + |
| 236 | + if (!is_null($this->getSourceId())) { |
| 237 | + $filter['filter']['source_id'] = $this->getSourceId(); |
| 238 | + } |
| 239 | + |
| 240 | + if ($this->getDeleted()) { |
| 241 | + $filter['filter']['deleted'] = $this->getDeleted(); |
| 242 | + } |
| 243 | + |
| 244 | + if (!is_null($this->getSize())) { |
| 245 | + $filter['filter']['size'] = $this->getSize(); |
| 246 | + } |
| 247 | + |
| 248 | + if (!is_null($this->getDate())) { |
| 249 | + $filter['filter']['date'] = $this->getDate(); |
| 250 | + } |
| 251 | + |
| 252 | + if (!is_null($this->getCreatedBy())) { |
| 253 | + $filter['filter']['created_by'] = $this->getCreatedBy(); |
| 254 | + } |
| 255 | + |
| 256 | + if (!is_null($this->getUpdatedBy())) { |
| 257 | + $filter['filter']['updated_by'] = $this->getUpdatedBy(); |
| 258 | + } |
| 259 | + |
| 260 | + return $this->buildPagesFilter($filter); |
| 261 | + } |
| 262 | +} |
0 commit comments