forked from thelia/thelia
/
Export.php
99 lines (80 loc) · 2.65 KB
/
Export.php
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Thelia\Model;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Core\Translation\Translator;
use Thelia\ImportExport\Export\DocumentsExportInterface;
use Thelia\ImportExport\Export\ExportHandler;
use Thelia\ImportExport\Export\ImagesExportInterface;
use Thelia\Model\Base\Export as BaseExport;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\Model\Tools\PositionManagementTrait;
class Export extends BaseExport
{
use PositionManagementTrait;
use ModelEventDispatcherTrait;
protected static $cache;
/**
* @param ContainerInterface $container
* @return \Thelia\ImportExport\Export\ExportHandler
* @throws \ErrorException
*/
public function getHandleClassInstance(ContainerInterface $container)
{
$class = $this->getHandleClass();
if ($class[0] !== "\\") {
$class = "\\" . $class;
}
if (!class_exists($class)) {
$this->delete();
throw new \ErrorException(
Translator::getInstance()->trans(
"The class \"%class\" doesn't exist",
[
"%class" => $class
]
)
);
}
$instance = new $class($container);
if (!$instance instanceof ExportHandler) {
$this->delete();
throw new \ErrorException(
Translator::getInstance()->trans(
"The class \"%class\" must extend %baseClass",
[
"%class" => $class,
"%baseClass" => "Thelia\\ImportExport\\Export\\ExportHandler",
]
)
);
}
return static::$cache = $instance;
}
public function hasImages(ContainerInterface $container)
{
if (static::$cache === null) {
$this->getHandleClassInstance($container);
}
return static::$cache instanceof ImagesExportInterface;
}
public function hasDocuments(ContainerInterface $container)
{
if (static::$cache === null) {
$this->getHandleClassInstance($container);
}
return static::$cache instanceof DocumentsExportInterface;
}
/**
* {@inheritDoc}
*/
public function preInsert(ConnectionInterface $con = null)
{
$this->setPosition($this->getNextPosition());
return true;
}
public function addCriteriaToPositionQuery($query)
{
$query->filterByExportCategoryId($this->getExportCategoryId());
}
}