|
| 1 | +<?php |
| 2 | + |
| 3 | +// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. |
| 4 | +// See the LICENCE file in the repository root for full licence text. |
| 5 | + |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace App\Libraries\Search; |
| 9 | + |
| 10 | +use App\Libraries\Elasticsearch\Utils\ComparatorParam; |
| 11 | +use App\Libraries\Elasticsearch\Utils\SearchAfterParam; |
| 12 | + |
| 13 | +class ArtistTrackSearchRequestParams extends ArtistTrackSearchParams |
| 14 | +{ |
| 15 | + public function __construct(array $rawParams) |
| 16 | + { |
| 17 | + $params = get_params($rawParams, null, [ |
| 18 | + 'album', |
| 19 | + 'artist', |
| 20 | + 'bpm:array', |
| 21 | + 'exclusive_only:bool', |
| 22 | + 'genre', |
| 23 | + 'is_default_sort:bool', |
| 24 | + 'length:array', |
| 25 | + 'limit:int', |
| 26 | + 'query', |
| 27 | + 'sort', |
| 28 | + ], ['null_missing' => true]); |
| 29 | + |
| 30 | + $this->queryString = presence(trim($params['query'] ?? '')); |
| 31 | + $this->album = $params['album']; |
| 32 | + $this->artist = $params['artist']; |
| 33 | + [$this->bpm, $this->bpmInput] = ComparatorParam::make($params['bpm'], 'float', 0.005); |
| 34 | + $this->genre = $params['genre']; |
| 35 | + [$this->length, $this->lengthInput] = ComparatorParam::make($params['length'], 'length', 0.5); |
| 36 | + $this->parseSort($params['sort'], $params['is_default_sort']); |
| 37 | + $this->searchAfter = SearchAfterParam::make($this, cursor_from_params($rawParams)); // TODO: enforce value types |
| 38 | + |
| 39 | + if (isset($params['exclusive_only'])) { |
| 40 | + $this->exclusiveOnly = $params['exclusive_only']; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + public function toArray(): array |
| 45 | + { |
| 46 | + return array_filter([ |
| 47 | + 'album' => $this->album, |
| 48 | + 'artist' => $this->artist, |
| 49 | + 'bpm' => $this->bpmInput, |
| 50 | + 'exclusive_only' => $this->exclusiveOnly, |
| 51 | + 'genre' => $this->genre, |
| 52 | + 'is_default_sort' => $this->isDefaultSort, |
| 53 | + 'length' => $this->lengthInput, |
| 54 | + 'query' => $this->queryString, |
| 55 | + 'sort' => "{$this->sortField}_{$this->sortOrder}", |
| 56 | + ], fn ($value) => $value !== null); |
| 57 | + } |
| 58 | +} |
0 commit comments