1
|
|
|
<?php |
2
|
|
|
/*************************************************************************************/ |
3
|
|
|
/* This file is part of the Thelia package. */ |
4
|
|
|
/* */ |
5
|
|
|
/* email : [email protected] */ |
6
|
|
|
/* web : http://www.thelia.net */ |
7
|
|
|
/* */ |
8
|
|
|
/* file that was distributed with this source code. */ |
9
|
|
|
/*************************************************************************************/ |
10
|
|
|
|
11
|
|
|
namespace Thelia\ImportExport\Export\Type; |
12
|
|
|
|
13
|
|
|
use Propel\Runtime\Propel; |
14
|
|
|
use Thelia\ImportExport\Export\JsonFileAbstractExport; |
15
|
|
|
|
16
|
|
|
class ProductI18nExport extends JsonFileAbstractExport |
17
|
|
|
{ |
18
|
|
|
const FILE_NAME = 'product_i18n'; |
19
|
|
|
|
20
|
|
|
protected $orderAndAliases = [ |
21
|
|
|
'product_ref' => 'ref', |
22
|
|
|
'product_i18n_TITLE' => 'product_title', |
23
|
|
|
'product_i18n_CHAPO' => 'product_chapo', |
24
|
|
|
'product_i18n_DESCRIPTION' => 'product_description', |
25
|
|
|
'product_i18n_POSTSCRIPTUM' => 'product_postscriptum', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
protected $idxStripHtml = [ |
29
|
|
|
'product_i18n_CHAPO', |
30
|
|
|
'product_i18n_DESCRIPTION', |
31
|
|
|
'product_i18n_POSTSCRIPTUM', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
protected function getData() |
35
|
|
|
{ |
36
|
|
|
$locale = $this->language->getLocale(); |
37
|
|
|
|
38
|
|
|
$con = Propel::getConnection(); |
39
|
|
|
|
40
|
|
|
$query = 'SELECT |
41
|
|
|
product.ref as product_ref, |
42
|
|
|
product_i18n.title as "product_i18n_TITLE", |
43
|
|
|
product_i18n.chapo as "product_i18n_CHAPO", |
44
|
|
|
product_i18n.description as "product_i18n_DESCRIPTION", |
45
|
|
|
product_i18n.postscriptum as "product_i18n_POSTSCRIPTUM" |
46
|
|
|
FROM product |
47
|
|
|
LEFT JOIN product_i18n ON (product_i18n.id = product.id AND product_i18n.locale = :locale)' |
48
|
|
|
; |
49
|
|
|
|
50
|
|
|
$stmt = $con->prepare($query); |
51
|
|
|
$stmt->bindValue('locale', $locale); |
52
|
|
|
$stmt->execute(); |
53
|
|
|
|
54
|
|
|
$filename = THELIA_CACHE_DIR . '/export/' . 'product_i18n.json'; |
55
|
|
|
|
56
|
|
|
if(file_exists($filename)){ |
57
|
|
|
unlink($filename); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
61
|
|
|
file_put_contents($filename, json_encode($row) . "\r\n", FILE_APPEND); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $filename; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param array $data |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
public function beforeSerialize(array $data) |
72
|
|
|
{ |
73
|
|
|
foreach ($data as $idx => &$value) { |
74
|
|
|
if (in_array($idx, $this->idxStripHtml) && !empty($value)) { |
75
|
|
|
$value = strip_tags($value); |
76
|
|
|
|
77
|
|
|
$value = html_entity_decode($value, ENT_QUOTES, 'UTF-8'); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return parent::beforeSerialize($data); |
82
|
|
|
} |
83
|
|
|
} |