|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Blast Project package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) 2015-2017 Libre Informatique |
|
7
|
|
|
* |
|
8
|
|
|
* This file is licenced under the GNU LGPL v3. |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Blast\Bundle\CoreBundle\DataSource; |
|
14
|
|
|
|
|
15
|
|
|
use Exporter\Source\DoctrineORMQuerySourceIterator; |
|
16
|
|
|
use Doctrine\ORM\PersistentCollection; |
|
17
|
|
|
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; |
|
18
|
|
|
|
|
19
|
|
|
class Iterator extends DoctrineORMQuerySourceIterator |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
* Allows to get back embedded arrays, in 2 dimensions max. |
|
24
|
|
|
* e.g.: fields positions.name & positions.organism.name will be returned as : |
|
25
|
|
|
* [ |
|
26
|
|
|
* 'name' => 'myEntity', |
|
27
|
|
|
* 'positions' => [ |
|
28
|
|
|
* ['name' => 'XXX', 'organism.name' => 'YYY'], |
|
29
|
|
|
* ['name' => 'AAA', 'organism.name' => 'BBB'], |
|
30
|
|
|
* ] |
|
31
|
|
|
* ];. |
|
32
|
|
|
*/ |
|
33
|
|
|
public function current() |
|
34
|
|
|
{ |
|
35
|
|
|
$data = []; |
|
36
|
|
|
$propertyPaths = $this->propertyPaths; |
|
37
|
|
|
|
|
38
|
|
|
// then complete it for "fields" representing a collection of sub-entities |
|
39
|
|
|
foreach ($this->propertyPaths as $i => $propertyPath) { |
|
40
|
|
|
try { |
|
41
|
|
|
if (($property = $this->propertyAccessor->getValue($this->iterator->current()[0], $propertyPath)) instanceof PersistentCollection) { |
|
|
|
|
|
|
42
|
|
View Code Duplication |
if (!(isset($data[(string) $propertyPath]) && is_array($data[(string) $propertyPath]))) { |
|
|
|
|
|
|
43
|
|
|
$data[(string) $propertyPath] = []; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
foreach ($property as $subEntity) { |
|
47
|
|
|
$data[(string) $propertyPath][] = (string) $subEntity; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
unset($this->propertyPaths[$i]); |
|
51
|
|
|
} |
|
52
|
|
|
} catch (NoSuchPropertyException $e) { |
|
53
|
|
|
$collection = preg_replace('/\..+$/', '', $propertyPath); |
|
54
|
|
|
$subProperty = preg_replace('/^.+\./U', '', $propertyPath); |
|
55
|
|
|
if ($collection != (string) $propertyPath && $subProperty) { |
|
56
|
|
|
if (($property = $this->propertyAccessor->getValue($this->iterator->current()[0], $collection)) instanceof PersistentCollection) { |
|
|
|
|
|
|
57
|
|
View Code Duplication |
if (!(isset($data[$collection]) && is_array($data[$collection]))) { |
|
|
|
|
|
|
58
|
|
|
$data[$collection] = []; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
foreach ($property as $subEntity) { |
|
62
|
|
|
$data[$collection][spl_object_hash($subEntity)][$subProperty] = (string) $this->propertyAccessor->getValue($subEntity, $subProperty); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
unset($this->propertyPaths[$i]); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
// first do the "normal" stuff |
|
71
|
|
|
$data = array_merge($data, parent::current()); |
|
72
|
|
|
|
|
73
|
|
|
$this->propertyPaths = $propertyPaths; |
|
74
|
|
|
|
|
75
|
|
|
return $data; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* getQuery(). |
|
80
|
|
|
* |
|
81
|
|
|
* @return Doctrine\ORM\Query |
|
82
|
|
|
**/ |
|
83
|
|
|
public function getQuery() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->query; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.