Skip to content

Commit d63f8e7

Browse files
committed
add mapping classes for statements and verbs
This commit reflects the latest changes from the php-xapi/model package where the MappedStatement and MappedVerb classes have been removed as they are purely related to Doctrine based repository implementations.
1 parent 2f57a27 commit d63f8e7

File tree

11 files changed

+314
-88
lines changed

11 files changed

+314
-88
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ CHANGELOG
44
0.3.0
55
-----
66

7+
* The `MappedStatement` and `MappedVerb` classes have been removed from the
8+
`php-xapi/model` package. They have been replaced with the new `Statement`
9+
and `Verb` classes in the `XApi\Repository\Doctrine\Mapping` namespace of
10+
this package. Consequently, the `MappedStatementRepository` class has been
11+
removed. It was replaced with a new `StatementRepository` class in the
12+
`XApi\Repository\Doctrine\Repository\Mapping` namespace.
13+
714
* The requirements for `php-xapi/model` and `php-xapi/test-fixtures` have
815
been bumped to `^1.0` to make use of their stable releases.
916

UPGRADE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ UPGRADE
44
Upgrading from 0.2 to 0.3
55
-------------------------
66

7+
* The `MappedStatement` and `MappedVerb` classes have been removed from the
8+
`php-xapi/model` package. They have been replaced with the new `Statement`
9+
and `Verb` classes in the `XApi\Repository\Doctrine\Mapping` namespace of
10+
this package. Consequently, the `MappedStatementRepository` class has been
11+
removed. It was replaced with a new `StatementRepository` class in the
12+
`XApi\Repository\Doctrine\Repository\Mapping` namespace.
13+
714
* The requirements for `php-xapi/model` and `php-xapi/test-fixtures` have
815
been bumped to `^1.0` to make use of their stable releases.
916

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"require": {
1414
"doctrine/common": "~2.4",
1515
"php-xapi/model": "^1.0",
16-
"php-xapi/repository-api": "^0.3@dev"
16+
"php-xapi/repository-api": "^0.3@dev",
17+
"ramsey/uuid": "^2.9"
1718
},
1819
"require-dev": {
1920
"php-xapi/test-fixtures": "^1.0"

src/Mapping/Statement.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 XApi\Repository\Doctrine\Mapping;
13+
14+
use Xabbuh\XApi\Model\Actor;
15+
use Xabbuh\XApi\Model\Result;
16+
use Xabbuh\XApi\Model\Statement as StatementModel;
17+
use Xabbuh\XApi\Model\StatementId;
18+
19+
/**
20+
* A {@link Statement} mapped to a storage backend.
21+
*
22+
* @author Christian Flothmann <[email protected]>
23+
*/
24+
class Statement
25+
{
26+
/**
27+
* @var string
28+
*/
29+
public $id;
30+
31+
/**
32+
* @var Actor
33+
*/
34+
public $actor;
35+
36+
/**
37+
* @var Verb
38+
*/
39+
public $verb;
40+
41+
/**
42+
* @var \Xabbuh\XApi\Model\Object
43+
*/
44+
public $object;
45+
46+
/**
47+
* @var Result
48+
*/
49+
public $result;
50+
51+
/**
52+
* @var Actor
53+
*/
54+
public $authority;
55+
56+
/**
57+
* @var \DateTime
58+
*/
59+
public $created;
60+
61+
/**
62+
* @var \DateTime
63+
*/
64+
public $stored;
65+
66+
public function getModel()
67+
{
68+
return new StatementModel(StatementId::fromString($this->id), $this->actor, $this->verb->getModel(), $this->object, $this->result, $this->authority, $this->created, $this->stored);
69+
}
70+
71+
public static function fromModel(StatementModel $statement)
72+
{
73+
$mappedStatement = new self();
74+
$mappedStatement->id = $statement->getId()->getValue();
75+
$mappedStatement->actor = $statement->getActor();
76+
$mappedStatement->verb = Verb::fromModel($statement->getVerb());
77+
$mappedStatement->object = $statement->getObject();
78+
$mappedStatement->result = $statement->getResult();
79+
$mappedStatement->authority = $statement->getAuthority();
80+
$mappedStatement->created = $statement->getCreated();
81+
$mappedStatement->stored = $statement->getStored();
82+
83+
return $mappedStatement;
84+
}
85+
}

src/Mapping/Verb.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 XApi\Repository\Doctrine\Mapping;
13+
14+
use Xabbuh\XApi\Model\Verb as VerbModel;
15+
16+
/**
17+
* A {@link Verb} mapped to a storage backend.
18+
*
19+
* @author Christian Flothmann <[email protected]>
20+
*/
21+
class Verb
22+
{
23+
public $identifier;
24+
public $id;
25+
public $display;
26+
27+
public function getModel()
28+
{
29+
return new VerbModel($this->id, $this->display);
30+
}
31+
32+
public function equals(Verb $verb)
33+
{
34+
if ($this->identifier !== $verb->identifier) {
35+
return false;
36+
}
37+
38+
if ($this->id !== $verb->id) {
39+
return false;
40+
}
41+
42+
if ($this->display !== $verb->display) {
43+
return false;
44+
}
45+
46+
return true;
47+
}
48+
49+
public static function fromModel(VerbModel $verb)
50+
{
51+
$mappedVerb = new self();
52+
$mappedVerb->id = $verb->getId();
53+
$mappedVerb->display = $verb->getDisplay();
54+
55+
return $mappedVerb;
56+
}
57+
}

src/Repository/MappedStatementRepository.php

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 XApi\Repository\Doctrine\Repository\Mapping;
13+
14+
use XApi\Repository\Doctrine\Mapping\Statement;
15+
16+
/**
17+
* {@link Statement} repository interface definition.
18+
*
19+
* @author Christian Flothmann <[email protected]>
20+
*/
21+
interface StatementRepository
22+
{
23+
/**
24+
* @param array $criteria
25+
*
26+
* @return Statement The statement or null if no matching statement
27+
* has been found
28+
*/
29+
public function findStatement(array $criteria);
30+
31+
/**
32+
* @param array $criteria
33+
*
34+
* @return Statement[] The statements matching the given criteria
35+
*/
36+
public function findStatements(array $criteria);
37+
38+
/**
39+
* Saves a {@link Statement} in the underlying storage.
40+
*
41+
* @param Statement $statement The statement being stored
42+
* @param bool $flush Whether or not to flush the managed objects
43+
* (i.e. write them to the data storage immediately)
44+
*/
45+
public function storeStatement(Statement $statement, $flush = true);
46+
}

0 commit comments

Comments
 (0)