-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathExhibitionRepository.php
63 lines (51 loc) · 1.77 KB
/
ExhibitionRepository.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace App\Repositories\Api;
use App\Models\Api\Exhibition;
use App\Repositories\EventRepository;
use App\Models\Api\Search;
class ExhibitionRepository extends BaseApiRepository
{
public const RELATED_EVENTS_PER_PAGE = 3;
public function __construct(Exhibition $model)
{
$this->model = $model;
}
/**
* Upcoming exhibitions
*/
public function upcoming()
{
return $this->model->query()->upcoming()->getSearch();
}
public function history($year = null, $q = null, $perPage = 20)
{
return $this->model->query()->history($year)->search($q)->getPaginatedModel($perPage, \App\Models\Api\Exhibition::SEARCH_FIELDS);
}
/**
* Show data, moved here to allow preview
*/
public function getShowData($item, $slug = null, $previewPage = null)
{
$collection = app(EventRepository::class)->getRelatedEvents($item, self::RELATED_EVENTS_PER_PAGE);
$relatedEventsByDay = app(EventRepository::class)->groupByDate($collection);
return [
'contrastHeader' => $item->present()->contrastHeader,
'item' => $item,
'relatedEventsByDay' => $relatedEventsByDay,
];
}
public function searchApi($string, $perPage = null, $time = null)
{
$search = Search::query()->search($string)->resources(['exhibitions']);
// WEB-2264: `upcoming` and `past` might be dead code. Remove?
if ($time == 'upcoming') {
$search->exhibitionUpcoming();
} elseif ($time == 'past') {
$search->exhibitionHistory();
} else {
$search->exhibitionGlobal();
}
$results = $search->getPaginatedModel($perPage, \App\Models\Api\Exhibition::SEARCH_FIELDS);
return $results;
}
}