Skip to content

Commit 1208be8

Browse files
committed
Add more options to ModFilesOptions
1 parent d69fbcf commit 1208be8

File tree

9 files changed

+291
-166
lines changed

9 files changed

+291
-166
lines changed

lib/Api/FilesApi.php

Lines changed: 33 additions & 33 deletions
Large diffs are not rendered by default.

lib/Api/ModsApi.php

Lines changed: 37 additions & 37 deletions
Large diffs are not rendered by default.

lib/Client/CurseForgeAPIClient.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ public function searchMods(ModSearchOptions $options): PaginatedModList
235235
{
236236
return new PaginatedModList($this, $this->mods->searchMods(
237237
$options->getGameId(),
238+
$options->getOffset(),
239+
PaginatedModList::getAllowedPageSize($options->getOffset(), $options->getPageSize()),
238240
$options->getClassId(),
239241
null,
240242
null,
@@ -250,8 +252,6 @@ public function searchMods(ModSearchOptions $options): PaginatedModList
250252
$options->getEncodedModLoaderTypes(),
251253
$options->getPrimaryAuthorId(),
252254
$options->getPremiumType(),
253-
$options->getOffset(),
254-
PaginatedModList::getAllowedPageSize($options->getOffset(), $options->getPageSize()),
255255
), $options);
256256
}
257257

@@ -317,11 +317,14 @@ public function getModFiles(ModFilesOptions $options): PaginatedFilesList
317317
{
318318
return new PaginatedFilesList($this, $this->files->getModFiles(
319319
$options->getModId(),
320+
$options->getOffset(),
321+
PaginatedFilesList::getAllowedPageSize($options->getOffset(), $options->getPageSize()),
320322
$options->getGameVersion(),
321323
$options->getModLoaderType()?->value,
322324
$options->getGameVersionTypeId(),
323-
$options->getOffset(),
324-
PaginatedFilesList::getAllowedPageSize($options->getOffset(), $options->getPageSize()),
325+
$options->getOlderThanProjectFileId(),
326+
$options->getReleaseTypes(),
327+
$options->getPlatformType()?->value,
325328
), $options);
326329
}
327330

lib/Client/Options/ModFiles/ModFilesOptions.php

Lines changed: 105 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,28 @@
77

88
class ModFilesOptions
99
{
10+
/**
11+
* Create new options for filtering mod files
12+
* @param int $modId id of the mod to get files for
13+
* @param int $offset offset to start page at
14+
* @param int $pageSize number of files to return
15+
* @param string|null $gameVersion game version to filter files by
16+
* @param ModLoaderType|null $modLoaderType mod loader type to filter files by
17+
* @param int|null $gameVersionTypeId show only files that are tagged with versions of the given gameVersionTypeId
18+
* @param int|null $olderThanProjectFileId show only files that are older than the given projectFileId
19+
* @param array|null $releaseTypes array of release types to filter files by
20+
* @param PlatformType|null $platformType platform type to filter files by
21+
*/
1022
public function __construct(
1123
protected int $modId,
24+
protected int $offset = 0,
25+
protected int $pageSize = PaginatedFilesList::MAX_PAGE_SIZE,
1226
protected ?string $gameVersion = null,
1327
protected ?ModLoaderType $modLoaderType = null,
1428
protected ?int $gameVersionTypeId = null,
15-
protected int $offset = 0,
16-
protected int $pageSize = PaginatedFilesList::MAX_PAGE_SIZE,
29+
protected ?int $olderThanProjectFileId = null,
30+
protected ?array $releaseTypes = null,
31+
protected ?PlatformType $platformType = null,
1732
)
1833
{
1934
}
@@ -36,6 +51,42 @@ public function setModId(int $modId): static
3651
return $this;
3752
}
3853

54+
/**
55+
* @return int
56+
*/
57+
public function getOffset(): int
58+
{
59+
return $this->offset;
60+
}
61+
62+
/**
63+
* @param int $offset
64+
* @return $this
65+
*/
66+
public function setOffset(int $offset): static
67+
{
68+
$this->offset = $offset;
69+
return $this;
70+
}
71+
72+
/**
73+
* @return int
74+
*/
75+
public function getPageSize(): int
76+
{
77+
return $this->pageSize;
78+
}
79+
80+
/**
81+
* @param int $pageSize
82+
* @return $this
83+
*/
84+
public function setPageSize(int $pageSize): static
85+
{
86+
$this->pageSize = $pageSize;
87+
return $this;
88+
}
89+
3990
/**
4091
* @return string|null
4192
*/
@@ -91,38 +142,77 @@ public function setGameVersionTypeId(?int $gameVersionTypeId): static
91142
}
92143

93144
/**
94-
* @return int
145+
* @return int|null
95146
*/
96-
public function getOffset(): int
147+
public function getOlderThanProjectFileId(): ?int
97148
{
98-
return $this->offset;
149+
return $this->olderThanProjectFileId;
99150
}
100151

101152
/**
102-
* @param int $offset
153+
* @param int|null $olderThanProjectFileId
103154
* @return $this
104155
*/
105-
public function setOffset(int $offset): static
156+
public function setOlderThanProjectFileId(?int $olderThanProjectFileId): static
106157
{
107-
$this->offset = $offset;
158+
$this->olderThanProjectFileId = $olderThanProjectFileId;
108159
return $this;
109160
}
110161

111162
/**
112-
* @return int
163+
* @return ReleaseType[]|null
113164
*/
114-
public function getPageSize(): int
165+
public function getReleaseTypes(): ?array
115166
{
116-
return $this->pageSize;
167+
return $this->releaseTypes;
117168
}
118169

119170
/**
120-
* @param int $pageSize
171+
* @param ReleaseType[]|null $releaseTypes
121172
* @return $this
122173
*/
123-
public function setPageSize(int $pageSize): static
174+
public function setReleaseTypes(?array $releaseTypes): static
124175
{
125-
$this->pageSize = $pageSize;
176+
$this->releaseTypes = $releaseTypes;
177+
return $this;
178+
}
179+
180+
/**
181+
* @param ReleaseType $releaseType
182+
* @return $this
183+
*/
184+
public function addReleaseType(ReleaseType $releaseType): static
185+
{
186+
$this->releaseTypes ??= [];
187+
$this->releaseTypes[] = $releaseType;
188+
return $this;
189+
}
190+
191+
/**
192+
* @param ReleaseType $releaseType
193+
* @return $this
194+
*/
195+
public function removeReleaseType(ReleaseType $releaseType): static
196+
{
197+
$this->releaseTypes = array_filter($this->releaseTypes, fn($type) => $type !== $releaseType);
198+
return $this;
199+
}
200+
201+
/**
202+
* @return PlatformType|null
203+
*/
204+
public function getPlatformType(): ?PlatformType
205+
{
206+
return $this->platformType;
207+
}
208+
209+
/**
210+
* @param PlatformType|null $platformType
211+
* @return $this
212+
*/
213+
public function setPlatformType(?PlatformType $platformType): static
214+
{
215+
$this->platformType = $platformType;
126216
return $this;
127217
}
128-
}
218+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Aternos\CurseForgeApi\Client\Options\ModFiles;
4+
5+
enum PlatformType: int
6+
{
7+
case EMPTY = 0;
8+
case WINDOWS = 1;
9+
case XBOX_ONE = 2;
10+
case XBOX_XS = 3;
11+
case LINUX = 4;
12+
case PS4 = 5;
13+
case PS5 = 6;
14+
case MAC = 7;
15+
case IOS = 8;
16+
case TVOS = 9;
17+
case ANDROID = 10;
18+
case SWITCH = 11;
19+
case WINDOWS_SERVER = 12;
20+
case LINUX_SERVER = 13;
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Aternos\CurseForgeApi\Client\Options\ModFiles;
4+
5+
enum ReleaseType: int
6+
{
7+
case RELEASE = 1;
8+
case BETA = 2;
9+
case ALPHA = 3;
10+
}

lib/Client/Options/ModSearch/ModSearchOptions.php

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class ModSearchOptions
2525
*/
2626
public function __construct(
2727
protected int $gameId,
28+
protected int $offset = 0,
29+
protected int $pageSize = PaginatedModList::MAX_PAGE_SIZE,
2830
protected ?int $classId = null,
2931
protected ?array $categoryIds = null,
3032
protected ?array $gameVersions = null,
@@ -37,8 +39,6 @@ public function __construct(
3739
protected ?int $primaryAuthorId = null,
3840
protected ?PremiumType $premiumType = null,
3941
protected ?string $slug = null,
40-
protected int $offset = 0,
41-
protected int $pageSize = PaginatedModList::MAX_PAGE_SIZE,
4242
)
4343
{
4444
}
@@ -61,6 +61,42 @@ public function setGameId(int $gameId): static
6161
return $this;
6262
}
6363

64+
/**
65+
* @return int
66+
*/
67+
public function getOffset(): int
68+
{
69+
return $this->offset;
70+
}
71+
72+
/**
73+
* @param int $offset
74+
* @return $this
75+
*/
76+
public function setOffset(int $offset): static
77+
{
78+
$this->offset = $offset;
79+
return $this;
80+
}
81+
82+
/**
83+
* @return int
84+
*/
85+
public function getPageSize(): int
86+
{
87+
return $this->pageSize;
88+
}
89+
90+
/**
91+
* @param int $pageSize
92+
* @return $this
93+
*/
94+
public function setPageSize(int $pageSize): static
95+
{
96+
$this->pageSize = $pageSize;
97+
return $this;
98+
}
99+
64100
/**
65101
* @return int|null
66102
*/
@@ -251,6 +287,7 @@ public function getModLoaderTypes(): ?array
251287
}
252288

253289
/**
290+
* Get the mod loader types encoded for the API request
254291
* @return string|null
255292
*/
256293
public function getEncodedModLoaderTypes(): ?string
@@ -390,40 +427,4 @@ public function setSlug(?string $slug): static
390427
$this->slug = $slug;
391428
return $this;
392429
}
393-
394-
/**
395-
* @return int
396-
*/
397-
public function getOffset(): int
398-
{
399-
return $this->offset;
400-
}
401-
402-
/**
403-
* @param int $offset
404-
* @return $this
405-
*/
406-
public function setOffset(int $offset): static
407-
{
408-
$this->offset = $offset;
409-
return $this;
410-
}
411-
412-
/**
413-
* @return int
414-
*/
415-
public function getPageSize(): int
416-
{
417-
return $this->pageSize;
418-
}
419-
420-
/**
421-
* @param int $pageSize
422-
* @return $this
423-
*/
424-
public function setPageSize(int $pageSize): static
425-
{
426-
$this->pageSize = $pageSize;
427-
return $this;
428-
}
429430
}

lib/Client/Options/ModSearch/PremiumType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
enum PremiumType: int
66
{
7-
case All = 0;
8-
case Premium = 1;
9-
case Free = 2;
7+
case ALL = 0;
8+
case PREMIUM = 1;
9+
case FREE = 2;
1010
}

0 commit comments

Comments
 (0)