1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-13 00:24:15 +02:00

feat(element-queries): update collect_filter helper function #436

This commit is contained in:
Awilum
2020-07-21 09:20:11 +03:00
parent 2b3a2d0d79
commit 63f2f7a7d9

View File

@@ -42,7 +42,13 @@ if (! function_exists('collect_filter')) {
$bind_set_first_result = $filter['set_first_result'] ?? false;
// Bind: set max result
$bind_set_max_result = $filter['set_max_result'] ?? false;
$bind_set_max_result = $filter['limit'] ?? false;
// Bind: return
$bind_return = $filter['return'] ?? 'all';
// Bind: random_value
$bind_random_value = $filter['random_value'] ?? 1;
// Bind: where
$bind_where = [];
@@ -120,7 +126,26 @@ if (! function_exists('collect_filter')) {
}
// Gets a native PHP array representation of the collection.
$items = $collection->all();
switch ($bind_return) {
case 'first':
$items = $collection->first();
break;
case 'last':
$items = $collection->last();
break;
case 'next':
$items = $collection->next();
break;
case 'random':
$items = $collection->random($bind_random_value);
break;
case 'shuffle':
$items = $collection->shuffle();
break;
default:
$items = $collection->all();
break;
}
// Return entries
return $items;