@@ -9,29 +9,33 @@ class ModSearchOptions
9
9
/**
10
10
* @param int $gameId
11
11
* @param int|null $classId
12
- * @param int|null $categoryId
13
- * @param string|null $gameVersion
12
+ * @param int[] |null $categoryIds
13
+ * @param string[] |null $gameVersions
14
14
* @param string|null $searchFilter Filter by free text search in the mod name and author
15
15
* @param ModSearchSortField|null $sortField
16
16
* @param SortOrder|null $sortOrder
17
- * @param ModLoaderType|null $modLoaderType Filter only mods associated to a given modloader (Forge, Fabric ...). Must be coupled with gameVersion.
17
+ * @param ModLoaderType[] |null $modLoaderTypes Filter only mods associated to a given modloader (Forge, Fabric ...). Must be coupled with gameVersion.
18
18
* @param int|null $gameVersionTypeId Filter only mods that contain files tagged with versions of the given gameVersionTypeId
19
- * @param int|null $authorId
19
+ * @param int|null $authorId Filter only mods that the given authorId is a member of
20
+ * @param int|null $primaryAuthorId Filter only mods that have the given author as primary author
21
+ * @param PremiumType|null $premiumType Filter only mods that are Premium or not
20
22
* @param string|null $slug Filter by slug (coupled with classId will result in a unique result).
21
23
* @param int $offset
22
24
* @param int $pageSize
23
25
*/
24
26
public function __construct (
25
27
protected int $ gameId ,
26
28
protected ?int $ classId = null ,
27
- protected ?int $ categoryId = null ,
28
- protected ?string $ gameVersion = null ,
29
+ protected ?array $ categoryIds = null ,
30
+ protected ?array $ gameVersions = null ,
29
31
protected ?string $ searchFilter = null ,
30
32
protected ?ModSearchSortField $ sortField = null ,
31
33
protected ?SortOrder $ sortOrder = null ,
32
- protected ?ModLoaderType $ modLoaderType = null ,
34
+ protected ?array $ modLoaderTypes = null ,
33
35
protected ?int $ gameVersionTypeId = null ,
34
36
protected ?int $ authorId = null ,
37
+ protected ?int $ primaryAuthorId = null ,
38
+ protected ?PremiumType $ premiumType = null ,
35
39
protected ?string $ slug = null ,
36
40
protected int $ offset = 0 ,
37
41
protected int $ pageSize = PaginatedModList::MAX_PAGE_SIZE ,
@@ -76,38 +80,111 @@ public function setClassId(?int $classId): static
76
80
}
77
81
78
82
/**
79
- * @return int|null
83
+ * @return int[]|null
84
+ */
85
+ public function getCategoryIds (): ?array
86
+ {
87
+ return $ this ->categoryIds ;
88
+ }
89
+
90
+ /**
91
+ * Get the categories encoded for the API request
92
+ * @return string|null
80
93
*/
81
- public function getCategoryId (): ?int
94
+ public function getEncodedCategoryIds (): ?string
82
95
{
83
- return $ this ->categoryId ;
96
+ if ($ this ->categoryIds === null ) {
97
+ return null ;
98
+ }
99
+
100
+ return json_encode ($ this ->categoryIds );
101
+ }
102
+
103
+ /**
104
+ * Set the category IDs to filter the search results
105
+ * @param int[]|null $categoryIds
106
+ * @return $this
107
+ */
108
+ public function setCategoryIds (?array $ categoryIds ): static
109
+ {
110
+ $ this ->categoryIds = $ categoryIds ;
111
+ return $ this ;
112
+ }
113
+
114
+ /**
115
+ * Add a category ID to filter the search results
116
+ * @param int $categoryId
117
+ * @return $this
118
+ */
119
+ public function addCategoryId (int $ categoryId ): static
120
+ {
121
+ $ this ->categoryIds ??= [];
122
+ $ this ->categoryIds [] = $ categoryId ;
123
+ return $ this ;
84
124
}
85
125
86
126
/**
87
- * @param int|null $categoryId
127
+ * Remove a category ID from the filter
128
+ * @param int $categoryId
88
129
* @return $this
89
130
*/
90
- public function setCategoryId (? int $ categoryId ): static
131
+ public function removeCategoryId ( int $ categoryId ): static
91
132
{
92
- $ this ->categoryId = $ categoryId ;
133
+ $ this ->categoryIds = array_filter ( $ this -> categoryIds , fn ( $ value ) => $ value !== $ categoryId) ;
93
134
return $ this ;
94
135
}
95
136
96
137
/**
138
+ * @return string[]|null
139
+ */
140
+ public function getGameVersions (): ?array
141
+ {
142
+ return $ this ->gameVersions ;
143
+ }
144
+
145
+ /**
146
+ * Get the game versions encoded for the API request
97
147
* @return string|null
98
148
*/
99
- public function getGameVersion (): ?string
149
+ public function getEncodedGameVersions (): ?string
100
150
{
101
- return $ this ->gameVersion ;
151
+ if ($ this ->gameVersions === null ) {
152
+ return null ;
153
+ }
154
+
155
+ return json_encode ($ this ->gameVersions );
102
156
}
103
157
104
158
/**
105
- * @param string|null $gameVersion
159
+ * @param string[] |null $gameVersions
106
160
* @return $this
107
161
*/
108
- public function setGameVersion (? string $ gameVersion ): static
162
+ public function setGameVersions (? array $ gameVersions ): static
109
163
{
110
- $ this ->gameVersion = $ gameVersion ;
164
+ $ this ->gameVersions = $ gameVersions ;
165
+ return $ this ;
166
+ }
167
+
168
+ /**
169
+ * Add a game version to the filter
170
+ * @param string $gameVersion
171
+ * @return $this
172
+ */
173
+ public function addGameVersion (string $ gameVersion ): static
174
+ {
175
+ $ this ->gameVersions ??= [];
176
+ $ this ->gameVersions [] = $ gameVersion ;
177
+ return $ this ;
178
+ }
179
+
180
+ /**
181
+ * Remove a game version from the filter
182
+ * @param string $gameVersion
183
+ * @return $this
184
+ */
185
+ public function removeGameVersion (string $ gameVersion ): static
186
+ {
187
+ $ this ->gameVersions = array_filter ($ this ->gameVersions , fn ($ value ) => $ value !== $ gameVersion );
111
188
return $ this ;
112
189
}
113
190
@@ -166,20 +243,61 @@ public function setSortOrder(?SortOrder $sortOrder): static
166
243
}
167
244
168
245
/**
169
- * @return ModLoaderType|null
246
+ * @return ModLoaderType[] |null
170
247
*/
171
- public function getModLoaderType (): ?ModLoaderType
248
+ public function getModLoaderTypes (): ?array
172
249
{
173
- return $ this ->modLoaderType ;
250
+ return $ this ->modLoaderTypes ;
174
251
}
175
252
176
253
/**
177
- * @param ModLoaderType|null $modLoaderType
254
+ * @return string|null
255
+ */
256
+ public function getEncodedModLoaderTypes (): ?string
257
+ {
258
+ if ($ this ->modLoaderTypes === null ) {
259
+ return null ;
260
+ }
261
+
262
+ $ result = [];
263
+
264
+ foreach ($ this ->modLoaderTypes as $ modLoaderType ) {
265
+ $ result [] = $ modLoaderType ->value ;
266
+ }
267
+
268
+ return json_encode ($ result );
269
+ }
270
+
271
+ /**
272
+ * @param ModLoaderType[]|null $modLoaderTypes
178
273
* @return $this
179
274
*/
180
- public function setModLoaderType (? ModLoaderType $ modLoaderType ): static
275
+ public function setModLoaderTypes (? array $ modLoaderTypes ): static
181
276
{
182
- $ this ->modLoaderType = $ modLoaderType ;
277
+ $ this ->modLoaderTypes = $ modLoaderTypes ;
278
+ return $ this ;
279
+ }
280
+
281
+ /**
282
+ * Add a mod loader type to the filter
283
+ * @param ModLoaderType $modLoaderType
284
+ * @return $this
285
+ */
286
+ public function addModLoaderType (ModLoaderType $ modLoaderType ): static
287
+ {
288
+ $ this ->modLoaderTypes ??= [];
289
+ $ this ->modLoaderTypes [] = $ modLoaderType ;
290
+ return $ this ;
291
+ }
292
+
293
+ /**
294
+ * Remove a mod loader type from the filter
295
+ * @param ModLoaderType $modLoaderType
296
+ * @return $this
297
+ */
298
+ public function removeModLoaderType (ModLoaderType $ modLoaderType ): static
299
+ {
300
+ $ this ->modLoaderTypes = array_filter ($ this ->modLoaderTypes , fn ($ value ) => $ value !== $ modLoaderType );
183
301
return $ this ;
184
302
}
185
303
@@ -219,6 +337,42 @@ public function setAuthorId(?int $authorId): static
219
337
return $ this ;
220
338
}
221
339
340
+ /**
341
+ * @return int|null
342
+ */
343
+ public function getPrimaryAuthorId (): ?int
344
+ {
345
+ return $ this ->primaryAuthorId ;
346
+ }
347
+
348
+ /**
349
+ * @param int|null $primaryAuthorId
350
+ * @return $this
351
+ */
352
+ public function setPrimaryAuthorId (?int $ primaryAuthorId ): static
353
+ {
354
+ $ this ->primaryAuthorId = $ primaryAuthorId ;
355
+ return $ this ;
356
+ }
357
+
358
+ /**
359
+ * @return PremiumType|null
360
+ */
361
+ public function getPremiumType (): ?PremiumType
362
+ {
363
+ return $ this ->premiumType ;
364
+ }
365
+
366
+ /**
367
+ * @param PremiumType|null $premiumType
368
+ * @return $this
369
+ */
370
+ public function setPremiumType (?PremiumType $ premiumType ): static
371
+ {
372
+ $ this ->premiumType = $ premiumType ;
373
+ return $ this ;
374
+ }
375
+
222
376
/**
223
377
* @return string|null
224
378
*/
0 commit comments