StatementsFilter::disableRelatedAgentFilter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 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 statements API.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
class StatementsFilter
20
{
21
    private $filter = array();
22
23
    /**
24
     * Filters by an Agent or an identified Group.
25
     */
26
    public function byActor(Actor $actor): self
27
    {
28
        $this->filter['agent'] = $actor;
29
30
        return $this;
31
    }
32
33 1
    /**
34
     * Filters by a verb.
35 1
     */
36
    public function byVerb(Verb $verb): self
37 1
    {
38
        $this->filter['verb'] = $verb->getId()->getValue();
39
40
        return $this;
41
    }
42
43
    /**
44
     * Filter by an Activity.
45
     */
46
    public function byActivity(Activity $activity): self
47 1
    {
48
        $this->filter['activity'] = $activity->getId()->getValue();
49 1
50
        return $this;
51 1
    }
52
53
    /**
54
     * Filters for Statements matching the given registration id.
55
     */
56
    public function byRegistration(string $registration): self
57
    {
58
        $this->filter['registration'] = $registration;
59
60
        return $this;
61 1
    }
62
63 1
    /**
64
     * Applies the Activity filter to Sub-Statements.
65 1
     */
66
    public function enableRelatedActivityFilter(): self
67
    {
68
        $this->filter['related_activities'] = 'true';
69
70
        return $this;
71
    }
72
73
    /**
74
     * Don't apply the Activity filter to Sub-Statements.
75 1
     */
76
    public function disableRelatedActivityFilter(): self
77 1
    {
78 1
        $this->filter['related_activities'] = 'false';
79
80
        return $this;
81
    }
82
83
    /**
84
     * Applies the Agent filter to Sub-Statements.
85 1
     */
86
    public function enableRelatedAgentFilter(): self
87 1
    {
88 1
        $this->filter['related_agents'] = 'true';
89
90
        return $this;
91
    }
92
93
    /**
94
     * Don't apply the Agent filter to Sub-Statements.
95 1
     */
96
    public function disableRelatedAgentFilter(): self
97 1
    {
98 1
        $this->filter['related_agents'] = 'false';
99
100
        return $this;
101
    }
102
103
    /**
104
     * Filters for Statements stored since the specified timestamp (exclusive).
105 1
     */
106
    public function since(\DateTime $timestamp): self
107 1
    {
108 1
        $this->filter['since'] = $timestamp->format('c');
109
110
        return $this;
111
    }
112
113
    /**
114
     * Filters for Statements stored at or before the specified timestamp.
115 1
     */
116
    public function until(\DateTime $timestamp): self
117 1
    {
118 1
        $this->filter['until'] = $timestamp->format('c');
119
120
        return $this;
121
    }
122
123
    /**
124
     * Sets the maximum number of Statements to return. The server side sets
125
     * the maximum number of results when this value is not set or when it is 0.
126
     *
127 1
     * @throws \InvalidArgumentException if the limit is not a non-negative
128
     *                                   integer
129 1
     */
130
    public function limit(int $limit): self
131 1
    {
132
        if ($limit < 0) {
133
            throw new \InvalidArgumentException('Limit must be a non-negative integer');
134
        }
135
136
        $this->filter['limit'] = $limit;
137
138
        return $this;
139
    }
140
141 1
    /**
142
     * Return statements in ascending order of stored time.
143 1
     */
144
    public function ascending(): self
145 1
    {
146
        $this->filter['ascending'] = 'true';
147
148
        return $this;
149
    }
150
151
    /**
152
     *Return statements in descending order of stored time (the default behavior).
153
     */
154
    public function descending(): self
155
    {
156
        $this->filter['ascending'] = 'false';
157
158
        return $this;
159 2
    }
160
161 2
    /**
162 1
     * Returns the generated filter.
163
     */
164
    public function getFilter(): array
165 1
    {
166
        return $this->filter;
167 1
    }
168
}
169