|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Osnova\Services\Timeline\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Osnova\Api\ApiProvider; |
|
6
|
|
|
use Osnova\Services\Timeline\Entry; |
|
7
|
|
|
use Osnova\Services\Timeline\Interfaces\TimelineOwnerInterface; |
|
8
|
|
|
use Osnova\Services\Timeline\Requests\TimelineRequest; |
|
9
|
|
|
use Osnova\Services\Timeline\Timeline; |
|
10
|
|
|
|
|
11
|
|
|
trait TimelineService |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var Timeline|null */ |
|
14
|
|
|
private $timeline; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get the resource API Provider instance. |
|
18
|
|
|
* |
|
19
|
|
|
* @return ApiProvider |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract public function getApiProvider(); |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Get the timeline service instance. |
|
25
|
|
|
* |
|
26
|
|
|
* @return Timeline |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getTimelineService() |
|
29
|
|
|
{ |
|
30
|
|
|
if (is_null($this->timeline)) { |
|
31
|
|
|
return $this->timeline = new Timeline($this->getApiProvider()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
return $this->timeline; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get timeline entries list. |
|
39
|
|
|
* This is a proxy method for Timeline::getTimeline(). |
|
40
|
|
|
* |
|
41
|
|
|
* @param TimelineOwnerInterface $owner Timeline owner. |
|
42
|
|
|
* @param TimelineRequest $request = null Timeline request parameters. |
|
43
|
|
|
* |
|
44
|
|
|
* @see Timeline::getTimeline() |
|
45
|
|
|
* |
|
46
|
|
|
* @return array|Entry[] |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getTimelineEntries(TimelineOwnerInterface $owner, TimelineRequest $request = null) |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->getTimelineService()->getTimeline( |
|
51
|
|
|
$owner, |
|
52
|
|
|
$request ?? new TimelineRequest(), |
|
53
|
|
|
$this |
|
|
|
|
|
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get timeline search results. |
|
59
|
|
|
* This is a proxy method for Timeline::getTimelineSearchResults(). |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $query Query string. |
|
62
|
|
|
* @param string $orderBy Ordering method (`relevant` or `date`). |
|
63
|
|
|
* @param int $page = 1 Results page. |
|
64
|
|
|
* |
|
65
|
|
|
* @see Timeline::getTimelineSearchResults() |
|
66
|
|
|
* |
|
67
|
|
|
* @return array|Entry[] |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getTimelineSearchResults(string $query, string $orderBy = 'relevant', int $page = 1) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->getTimelineService()->getTimelineSearchResults($query, $orderBy, $page, $this); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get timeline entry by ID. |
|
76
|
|
|
* This is a proxy method for Timeline::getTimelineEntry(). |
|
77
|
|
|
* |
|
78
|
|
|
* @param int $id Entry ID. |
|
79
|
|
|
* |
|
80
|
|
|
* @see Timeline::getTimeline() |
|
81
|
|
|
* |
|
82
|
|
|
* @return Entry|null |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getTimelineEntry($id) |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->getTimelineService()->getTimelineEntry($id, $this); |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|