Skip to content

Commit ddae50d

Browse files
committed
Include with function
1 parent c035c79 commit ddae50d

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

lib/Tmdb/Model/Query/Discover/DiscoverTvQuery.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
*/
2424
class DiscoverTvQuery extends QueryParametersCollection
2525
{
26+
/** Transform args to an AND query */
27+
public const MODE_AND = 0;
28+
29+
/** Transform args to an OR query */
30+
public const MODE_OR = 1;
31+
2632
/**
2733
* Minimum value is 1, expected value is an integer.
2834
*
@@ -152,6 +158,44 @@ public function voteAverageGte($average)
152158
return $this;
153159
}
154160

161+
/**
162+
* Format the with compatible parameters.
163+
*
164+
* @param array|string $with
165+
* @param int $mode
166+
*
167+
* @return null|string
168+
*/
169+
protected function with($with = null, $mode = self::MODE_OR): ?string
170+
{
171+
if ($with instanceof GenericCollection) {
172+
$with = $with->toArray();
173+
}
174+
175+
if (is_array($with)) {
176+
return $this->andWith((array)$with, $mode);
177+
}
178+
179+
return $with;
180+
}
181+
182+
/**
183+
* Creates an and query to combine an AND or an OR expression.
184+
*
185+
* @param array $with
186+
* @param int $mode
187+
* @return string
188+
*/
189+
protected function andWith(array $with, $mode)
190+
{
191+
return (
192+
implode(
193+
$mode === self::MODE_OR ? '|' : ',',
194+
array_map([$this, 'normalize'], $with)
195+
)
196+
);
197+
}
198+
155199
/**
156200
* Creates an OR query for genres
157201
*

0 commit comments

Comments
 (0)