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\Client\Api; |
13
|
|
|
|
14
|
|
|
use Xabbuh\XApi\Client\Request\HandlerInterface; |
15
|
|
|
use Xabbuh\XApi\Serializer\ActorSerializerInterface; |
16
|
|
|
use Xabbuh\XApi\Serializer\DocumentDataSerializerInterface; |
17
|
|
|
use Xabbuh\XApi\Model\AgentProfile; |
18
|
|
|
use Xabbuh\XApi\Model\AgentProfileDocument; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Client to access the agent profile API of an xAPI based learning record |
22
|
|
|
* store. |
23
|
|
|
* |
24
|
|
|
* @author Christian Flothmann <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class AgentProfileApiClient extends DocumentApiClient implements AgentProfileApiClientInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var ActorSerializerInterface |
30
|
|
|
*/ |
31
|
|
|
private $actorSerializer; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param HandlerInterface $requestHandler The HTTP request handler |
35
|
|
|
* @param string $version The xAPI version |
36
|
|
|
* @param DocumentDataSerializerInterface $documentDataSerializer The document data serializer |
37
|
|
|
* @param ActorSerializerInterface $actorSerializer The actor serializer |
38
|
|
|
*/ |
39
|
5 |
|
public function __construct( |
40
|
|
|
HandlerInterface $requestHandler, |
41
|
|
|
$version, |
42
|
|
|
DocumentDataSerializerInterface $documentDataSerializer, |
43
|
|
|
ActorSerializerInterface $actorSerializer |
44
|
|
|
) { |
45
|
5 |
|
parent::__construct($requestHandler, $version, $documentDataSerializer); |
46
|
|
|
|
47
|
5 |
|
$this->actorSerializer = $actorSerializer; |
48
|
5 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritDoc} |
52
|
|
|
*/ |
53
|
1 |
|
public function createOrUpdateDocument(AgentProfileDocument $document) |
54
|
|
|
{ |
55
|
1 |
|
$profile = $document->getAgentProfile(); |
56
|
1 |
|
$this->doStoreDocument('post', 'agents/profile', array( |
57
|
1 |
|
'agent' => $this->actorSerializer->serializeActor($profile->getAgent()), |
58
|
1 |
|
'profileId' => $profile->getProfileId(), |
59
|
|
|
), $document); |
60
|
1 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritDoc} |
64
|
|
|
*/ |
65
|
1 |
|
public function createOrReplaceDocument(AgentProfileDocument $document) |
66
|
|
|
{ |
67
|
1 |
|
$profile = $document->getAgentProfile(); |
68
|
1 |
|
$this->doStoreDocument('put', 'agents/profile', array( |
69
|
1 |
|
'agent' => $this->actorSerializer->serializeActor($profile->getAgent()), |
70
|
1 |
|
'profileId' => $profile->getProfileId(), |
71
|
|
|
), $document); |
72
|
1 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritDoc} |
76
|
|
|
*/ |
77
|
|
|
public function deleteDocument(AgentProfile $profile) |
78
|
|
|
{ |
79
|
|
|
$this->doDeleteDocument('agents/profile', array( |
80
|
|
|
'agent' => $this->actorSerializer->serializeActor($profile->getAgent()), |
81
|
|
|
'profileId' => $profile->getProfileId(), |
82
|
|
|
)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritDoc} |
87
|
|
|
*/ |
88
|
1 |
|
public function getDocument(AgentProfile $profile) |
89
|
|
|
{ |
90
|
|
|
/** @var \Xabbuh\XApi\Model\DocumentData $documentData */ |
91
|
1 |
|
$documentData = $this->doGetDocument('agents/profile', array( |
92
|
1 |
|
'agent' => $this->actorSerializer->serializeActor($profile->getAgent()), |
93
|
1 |
|
'profileId' => $profile->getProfileId(), |
94
|
|
|
)); |
95
|
|
|
|
96
|
1 |
|
return new AgentProfileDocument($profile, $documentData); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|