-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargeCollection.php
More file actions
48 lines (37 loc) · 1.17 KB
/
LargeCollection.php
File metadata and controls
48 lines (37 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Statamic\Addons\LargeCollection;
use Statamic\Addons\LargeCollection\Lib\PaginatableEntryCollection;
use Statamic\API\Entry;
use Statamic\Extend\Addon;
class LargeCollection extends Addon
{
/**
* Get the list of articles
*
* @return array
*/
public function getArticles()
{
$collection = "article";
/** @var PaginatableEntryCollection $articles */
$articles = PaginatableEntryCollection::make( Entry::whereCollection($collection)->sort() )->paginate(25);
return $articles;
}
/**
* Get the list of results
*
* @return array
*/
public function getResults($query)
{
$collection = "article";
$query = strtolower($query);
/** @var PaginatableEntryCollection $articles */
$articles = PaginatableEntryCollection::make( Entry::whereCollection($collection)
->filter(function ($entry) use ($query) {
return str_contains(strtolower($entry->get('title')), $query) || str_contains(strtolower($entry->get('body')), $query);
})
)->paginate(25)->appends(compact('query'));
return $articles;
}
}