mirror of
https://github.com/koel/koel
synced 2024-11-14 00:17:13 +00:00
fix: create smart playlist parameters
This commit is contained in:
parent
220a0e2623
commit
cab9f28285
1 changed files with 8 additions and 4 deletions
|
@ -14,7 +14,7 @@ class SmartPlaylistRuleParameterFactory
|
||||||
*
|
*
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*
|
*
|
||||||
* @return array
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function createParameters(string $model, string $operator, array $value): array
|
public function createParameters(string $model, string $operator, array $value): array
|
||||||
{
|
{
|
||||||
|
@ -28,8 +28,12 @@ class SmartPlaylistRuleParameterFactory
|
||||||
Rule::OPERATOR_IS_LESS_THAN => [$model, '<', $value[0]],
|
Rule::OPERATOR_IS_LESS_THAN => [$model, '<', $value[0]],
|
||||||
Rule::OPERATOR_IS_GREATER_THAN => [$model, '>', $value[0]],
|
Rule::OPERATOR_IS_GREATER_THAN => [$model, '>', $value[0]],
|
||||||
Rule::OPERATOR_IS_BETWEEN => [$model, $value],
|
Rule::OPERATOR_IS_BETWEEN => [$model, $value],
|
||||||
Rule::OPERATOR_NOT_IN_LAST => [$model, '<', (new Carbon())->subDay($value[0])],
|
Rule::OPERATOR_NOT_IN_LAST => static function () use ($model, $value): array {
|
||||||
Rule::OPERATOR_IN_LAST => [$model, '>=', (new Carbon())->subDay($value[0])],
|
return [$model, '<', (new Carbon())->subDay($value[0])];
|
||||||
|
},
|
||||||
|
Rule::OPERATOR_IN_LAST => static function () use ($model, $value): array {
|
||||||
|
return [$model, '>=', (new Carbon())->subDay($value[0])];
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
throw_unless(array_key_exists($operator, $ruleParameterMap), InvalidArgumentException::class, sprintf(
|
throw_unless(array_key_exists($operator, $ruleParameterMap), InvalidArgumentException::class, sprintf(
|
||||||
|
@ -38,6 +42,6 @@ class SmartPlaylistRuleParameterFactory
|
||||||
implode(', ', array_keys($ruleParameterMap))
|
implode(', ', array_keys($ruleParameterMap))
|
||||||
));
|
));
|
||||||
|
|
||||||
return $ruleParameterMap[$operator];
|
return is_array($ruleParameterMap[$operator]) ? $ruleParameterMap[$operator] : $ruleParameterMap[$operator]();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue