Completed
Push — master ( 1544c6...bf0179 )
by Christian
04:16
created

StateDocumentsFilter::byActivity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Model;
13
14
/**
15
 * Filter to apply on GET requests to the states API.
16
 *
17
 * @author Jérôme Parmentier <[email protected]>
18
 */
19
class StateDocumentsFilter
20
{
21
    /**
22
     * @var array The generated filter
23
     */
24
    private $filter = array();
25
26
    /**
27
     * Filter by an Activity.
28
     *
29
     * @param Activity $activity The Activity to filter by
30
     *
31
     * @return $this
32
     */
33
    public function byActivity(Activity $activity)
34
    {
35
        $this->filter['activity'] = $activity->getId()->getValue();
36
37
        return $this;
38
    }
39
40
    /**
41
     * Filters by an Agent.
42
     *
43
     * @param Agent $agent The Agent to filter by
44
     *
45
     * @return $this
46
     */
47
    public function byAgent(Agent $agent)
48
    {
49
        $this->filter['agent'] = $agent;
50
51
        return $this;
52
    }
53
54
    /**
55
     * Filters for State documents matching the given registration id.
56
     *
57
     * @param string $registration A registration id
58
     *
59
     * @return $this
60
     */
61
    public function byRegistration($registration)
62
    {
63
        $this->filter['registration'] = $registration;
64
65
        return $this;
66
    }
67
68
    /**
69
     * Filters for State documents stored since the specified timestamp (exclusive).
70
     *
71
     * @param \DateTime $timestamp The timestamp
72
     *
73
     * @return $this
74
     */
75
    public function since(\DateTime $timestamp)
76
    {
77
        $this->filter['since'] = $timestamp->format('c');
78
79
        return $this;
80
    }
81
82
    /**
83
     * Returns the generated filter.
84
     *
85
     * @return array The filter
86
     */
87
    public function getFilter()
88
    {
89
        return $this->filter;
90
    }
91
}
92