-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathHasActivitiesTrait.php
More file actions
53 lines (47 loc) · 1.41 KB
/
HasActivitiesTrait.php
File metadata and controls
53 lines (47 loc) · 1.41 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
49
50
51
52
53
<?php
namespace Platformsh\Client\Model\Activities;
use Platformsh\Client\Model\Activity;
/**
* A trait meant to be added to a Resource so it can implement HasActivitiesInterface.
*
* @see HasActivitiesInterface
*/
trait HasActivitiesTrait {
/**
* {@inheritDoc}
*/
public function getActivity($id)
{
return Activity::get($id, $this->getUri() . '/activities', $this->client);
}
/**
* {@inheritDoc}
*/
public function getActivities($limit = 0, $type = null, $startsAt = null, $state = null, $result = null)
{
$query = '';
if ($type !== null) {
$query .= '&type=' . \rawurlencode($type);
}
if ($startsAt !== null) {
$query .= '&starts_at=' . Activity::formatStartsAt($startsAt);
}
if (!empty($limit)) {
$query .= '&count=' . $limit;
}
if ($result !== null) {
foreach ((array) $result as $resultItem) {
$query .= '&result=' . \rawurlencode($resultItem);
}
}
if ($state !== null) {
foreach ((array) $state as $stateItem) {
$query .= '&state=' . \rawurlencode($stateItem);
}
}
if ($query !== '') {
$query = '?' . \substr($query, 1);
}
return Activity::getCollection($this->getUri() . '/activities' . $query, $limit, [], $this->client);
}
}