-
Notifications
You must be signed in to change notification settings - Fork 555
Expand file tree
/
Copy pathStatementRepository.php
More file actions
77 lines (65 loc) · 1.93 KB
/
Copy pathStatementRepository.php
File metadata and controls
77 lines (65 loc) · 1.93 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace XApi\Repository\ORM;
use Doctrine\ORM\EntityRepository;
use XApi\Repository\Doctrine\Mapping\Context;
use XApi\Repository\Doctrine\Mapping\Statement;
use XApi\Repository\Doctrine\Repository\Mapping\StatementRepository as BaseStatementRepository;
/**
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StatementRepository extends EntityRepository implements BaseStatementRepository
{
/**
* {@inheritdoc}
*/
public function findStatement(array $criteria)
{
return parent::findOneBy($criteria);
}
/**
* {@inheritdoc}
*/
public function findStatements(array $criteria)
{
if (!empty($criteria['registration'])) {
$contexts = $this->_em->getRepository(Context::class)->findBy([
'registration' => $criteria['registration'],
]);
$criteria['context'] = $contexts;
}
if (!empty($criteria['verb'])) {
$verbs = $this->_em->getRepository(Verb::class)->findBy(['id' => $criteria['verb']]);
$criteria['verb'] = $verbs;
}
unset(
$criteria['registration'],
$criteria['related_activities'],
$criteria['related_agents'],
$criteria['ascending'],
);
return parent::findBy(
$criteria,
['created' => 'ASC'],
$criteria['limit'] ?? null,
$criteria['cursor'] ?? null
);
}
/**
* {@inheritdoc}
*/
public function storeStatement(Statement $mappedStatement, $flush = true)
{
$this->_em->persist($mappedStatement);
if ($flush) {
$this->_em->flush();
}
}
}