1
|
|
|
<?php |
2
|
|
|
/*************************************************************************************/ |
3
|
|
|
/* This file is part of the Thelia package. */ |
4
|
|
|
/* */ |
5
|
|
|
/* Copyright (c) OpenStudio */ |
6
|
|
|
/* email : [email protected] */ |
7
|
|
|
/* web : http://www.thelia.net */ |
8
|
|
|
/* */ |
9
|
|
|
/* For the full copyright and license information, please view the LICENSE.txt */ |
10
|
|
|
/* file that was distributed with this source code. */ |
11
|
|
|
/*************************************************************************************/ |
12
|
|
|
|
13
|
|
|
namespace Thelia\ImportExport\Export; |
14
|
|
|
|
15
|
|
|
use Propel\Runtime\ActiveQuery\ModelCriteria; |
16
|
|
|
use Propel\Runtime\Map\TableMap; |
17
|
|
|
|
18
|
|
|
abstract class PropelCollectionAbstractExport extends AbstractExport |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var \Propel\Runtime\Util\PropelModelPager Data to export |
22
|
|
|
*/ |
23
|
|
|
private $data; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return array|false|mixed|string |
27
|
|
|
* @throws \Exception |
28
|
|
|
*/ |
29
|
|
|
public function current() |
30
|
|
|
{ |
31
|
|
|
$data = $this->data->getIterator()->current()->toArray(TableMap::TYPE_COLNAME, true, [], true); |
32
|
|
|
|
33
|
|
|
foreach ($this->data->getQuery()->getWith() as $withKey => $with) { |
34
|
|
|
$data = array_merge($data, $data[$withKey]); |
35
|
|
|
unset($data[$withKey]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $data; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return bool|float|int|string|null |
43
|
|
|
* @throws \Exception |
44
|
|
|
*/ |
45
|
|
|
public function key() |
46
|
|
|
{ |
47
|
|
|
if ($this->data->getIterator()->key() !== null) { |
48
|
|
|
return $this->data->getIterator()->key() + ($this->data->getPage() - 1) * 1000; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @throws \Exception |
56
|
|
|
*/ |
57
|
|
|
public function next() |
58
|
|
|
{ |
59
|
|
|
$this->data->getIterator()->next(); |
60
|
|
|
if (!$this->valid() && !$this->data->isLastPage()) { |
61
|
|
|
$this->data = $this->data->getQuery()->paginate($this->data->getNextPage(), 1000); |
62
|
|
|
$this->data->getIterator()->rewind(); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @throws \Exception |
68
|
|
|
*/ |
69
|
|
|
public function rewind() |
70
|
|
|
{ |
71
|
|
|
if ($this->data === null) { |
72
|
|
|
$data = $this->getData(); |
73
|
|
|
|
74
|
|
|
if ($data instanceof ModelCriteria) { |
75
|
|
|
$this->data = $data->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->keepQuery(false)->paginate(1, 1000); |
76
|
|
|
$this->data->getIterator()->rewind(); |
77
|
|
|
|
78
|
|
|
return; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
throw new \DomainException( |
82
|
|
|
'Data must be an instance of \\Propel\\Runtime\\ActiveQuery\\ModelCriteria' |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
throw new \LogicException('Export data can\'t be rewinded'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return bool |
91
|
|
|
* @throws \Exception |
92
|
|
|
*/ |
93
|
|
|
public function valid() |
94
|
|
|
{ |
95
|
|
|
return $this->data->getIterator()->valid(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|