|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Sulu. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) MASSIVE ART WebServices GmbH |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sulu\Bundle\ElasticsearchActivityLogBundle\Storage; |
|
13
|
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\Result\DocumentIterator; |
|
15
|
|
|
use Sulu\Bundle\ElasticsearchActivityLogBundle\Document\ActivityLoggerViewDocument; |
|
16
|
|
|
use Sulu\Component\Security\Authentication\UserInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Take result iterator, parents and creator - and combines them. |
|
20
|
|
|
*/ |
|
21
|
|
|
class ResultIterator extends \IteratorIterator |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var ActivityLoggerViewDocument[] |
|
25
|
|
|
*/ |
|
26
|
|
|
private $parents = []; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var UserInterface[] |
|
30
|
|
|
*/ |
|
31
|
|
|
private $creators = []; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param DocumentIterator $iterator |
|
35
|
|
|
* @param DocumentIterator $parents |
|
36
|
|
|
* @param array $creators |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(DocumentIterator $iterator, DocumentIterator $parents = null, array $creators = null) |
|
39
|
|
|
{ |
|
40
|
|
|
parent::__construct($iterator); |
|
41
|
|
|
|
|
42
|
|
|
if (null !== $parents) { |
|
43
|
|
|
foreach ($parents as $parent) { |
|
44
|
|
|
$this->parents[$parent->getUuid()] = $parent; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if (null !== $creators) { |
|
49
|
|
|
foreach ($creators as $creator) { |
|
50
|
|
|
$this->creators[$creator->getId()] = $creator; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Set creator and parent to document. |
|
57
|
|
|
* |
|
58
|
|
|
* @return ActivityLoggerViewDocument |
|
59
|
|
|
*/ |
|
60
|
|
|
public function current() |
|
61
|
|
|
{ |
|
62
|
|
|
$result = parent::current(); |
|
63
|
|
|
if (!$result) { |
|
64
|
|
|
return $result; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$result->setParent( |
|
68
|
|
|
array_key_exists($result->getParentUuid(), $this->parents) ? $this->parents[$result->getParentUuid()] : null |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
$result->setCreator( |
|
72
|
|
|
array_key_exists($result->getCreatorId(), $this->creators) ? $this->creators[$result->getCreatorId()] : null |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
return $result; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|