|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Oledrion\Exports; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
You may not change or alter any portion of this comment or credits |
|
7
|
|
|
of supporting developers from this source code or any supporting source code |
|
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
|
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* oledrion |
|
17
|
|
|
* |
|
18
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
19
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
|
20
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com/) |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Export au format Dbase 3 |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
use XoopsModules\Oledrion; |
|
28
|
|
|
use XoopsModules\Oledrion\Constants; |
|
29
|
|
|
|
|
30
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Class DbaseExport |
|
34
|
|
|
*/ |
|
35
|
|
|
class DbaseExport extends Export |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* DbaseExport constructor. |
|
39
|
|
|
* @param string|array $parameters |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct($parameters = '') |
|
42
|
|
|
{ |
|
43
|
|
|
if (!is_array($parameters)) { |
|
44
|
|
|
$this->filename = 'oledrion.dbf'; |
|
45
|
|
|
$this->folder = OLEDRION_CSV_PATH; |
|
46
|
|
|
$this->url = OLEDRION_CSV_URL; |
|
47
|
|
|
$this->orderType = Constants::OLEDRION_STATE_VALIDATED; |
|
48
|
|
|
} |
|
49
|
|
|
parent::__construct($parameters); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Export des données |
|
54
|
|
|
* @return bool Vrai si l'export a réussi sinon faux |
|
55
|
|
|
*/ |
|
56
|
|
|
public function doExport() |
|
57
|
|
|
{ |
|
58
|
|
|
$def = [ |
|
59
|
|
|
['o_id', 'N', 10, 0], |
|
60
|
|
|
['o_uid', 'N', 10, 0], |
|
61
|
|
|
['o_date', 'D'], |
|
62
|
|
|
['o_state', 'N', 1, 0], |
|
63
|
|
|
['o_ip', 'C', 32], |
|
64
|
|
|
['o_lastname', 'C', 155], |
|
65
|
|
|
['o_firstnam', 'C', 155], |
|
66
|
|
|
['o_adress', 'C', 155], |
|
67
|
|
|
['o_zip', 'C', 30], |
|
68
|
|
|
['o_town', 'C', 155], |
|
69
|
|
|
['o_country', 'C', 3], |
|
70
|
|
|
['o_telephon', 'C', 30], |
|
71
|
|
|
['o_email', 'C', 155], |
|
72
|
|
|
['o_articles', 'N', 10, 0], |
|
73
|
|
|
['o_total', 'N', 10, 2], |
|
74
|
|
|
['o_shipping', 'N', 10, 2], |
|
75
|
|
|
['o_bill', 'L'], |
|
76
|
|
|
['o_password', 'C', 155], |
|
77
|
|
|
['o_text', 'C', 155], |
|
78
|
|
|
['o_cancel', 'C', 155], |
|
79
|
|
|
['c_id', 'N', 10, 0], |
|
80
|
|
|
['c_prod_id', 'N', 10, 0], |
|
81
|
|
|
['c_qte', 'N', 10, 0], |
|
82
|
|
|
['c_price', 'N', 10, 2], |
|
83
|
|
|
['c_o_id', 'N', 10, 0], |
|
84
|
|
|
['c_shipping', 'N', 10, 2], |
|
85
|
|
|
['c_pass', 'C', 155], |
|
86
|
|
|
]; |
|
87
|
|
|
/* |
|
88
|
|
|
* Correspondances |
|
89
|
|
|
* cmd_id o_id |
|
90
|
|
|
* cmd_uid o_uid |
|
91
|
|
|
* cmd_date o_date |
|
92
|
|
|
* cmd_state o_state |
|
93
|
|
|
* cmd_ip o_ip |
|
94
|
|
|
* cmd_lastname o_lastname |
|
95
|
|
|
* cmd_firstname o_firstnam |
|
96
|
|
|
* cmd_adress o_adress |
|
97
|
|
|
* cmd_zip o_zip |
|
98
|
|
|
* cmd_town o_town |
|
99
|
|
|
* cmd_country o_country |
|
100
|
|
|
* cmd_telephone o_telephon |
|
101
|
|
|
* cmd_email o_email |
|
102
|
|
|
* cmd_articles_count o_articles |
|
103
|
|
|
* cmd_total o_total |
|
104
|
|
|
* cmd_shipping o_shipping |
|
105
|
|
|
* cmd_bill o_bill |
|
106
|
|
|
* cmd_password o_password |
|
107
|
|
|
* cmd_text o_text |
|
108
|
|
|
* cmd_cancel o_cancel |
|
109
|
|
|
* caddy_id c_id |
|
110
|
|
|
* caddy_product_id c_prod_id |
|
111
|
|
|
* caddy_qte c_qte |
|
112
|
|
|
* caddy_price c_price |
|
113
|
|
|
* caddy_cmd_id c_o_id |
|
114
|
|
|
* caddy_shipping c_shipping |
|
115
|
|
|
* caddy_pass c_pass |
|
116
|
|
|
*/ |
|
117
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
118
|
|
|
$caddyHandler = new Oledrion\CaddyHandler($db); |
|
119
|
|
|
$commandsHandler = new Oledrion\CommandsHandler($db); |
|
120
|
|
|
if (!dbase_create($this->folder . '/' . $this->filename, $def)) { |
|
|
|
|
|
|
121
|
|
|
$this->success = false; |
|
122
|
|
|
|
|
123
|
|
|
return false; |
|
124
|
|
|
} |
|
125
|
|
|
$dbf = dbase_open($this->folder . '/' . $this->filename, 2); |
|
|
|
|
|
|
126
|
|
|
if (false === $dbf) { |
|
127
|
|
|
$this->success = false; |
|
128
|
|
|
|
|
129
|
|
|
return false; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$criteria = new \CriteriaCompo(); |
|
133
|
|
|
$criteria->add(new \Criteria('cmd_id', 0, '<>')); |
|
134
|
|
|
$criteria->add(new \Criteria('cmd_state', $this->orderType, '=')); |
|
135
|
|
|
$criteria->setSort('cmd_date'); |
|
136
|
|
|
$criteria->setOrder('DESC'); |
|
137
|
|
|
$orders = $commandsHandler->getObjects($criteria); |
|
138
|
|
|
foreach ($orders as $order) { |
|
139
|
|
|
$carts = []; |
|
|
|
|
|
|
140
|
|
|
$carts = $caddyHandler->getObjects(new \Criteria('caddy_cmd_id', $order->getVar('cmd_id'), '=')); |
|
141
|
|
|
foreach ($carts as $cart) { |
|
142
|
|
|
dbase_add_record($dbf, [ |
|
|
|
|
|
|
143
|
|
|
$order->getVar('cmd_id'), |
|
144
|
|
|
$order->getVar('cmd_uid'), |
|
145
|
|
|
date('Ymd', strtotime($order->getVar('cmd_date'))), |
|
146
|
|
|
$order->getVar('cmd_state'), |
|
147
|
|
|
$order->getVar('cmd_ip'), |
|
148
|
|
|
$order->getVar('cmd_lastname'), |
|
149
|
|
|
$order->getVar('cmd_firstname'), |
|
150
|
|
|
$order->getVar('cmd_adress'), |
|
151
|
|
|
$order->getVar('cmd_zip'), |
|
152
|
|
|
$order->getVar('cmd_town'), |
|
153
|
|
|
$order->getVar('cmd_country'), |
|
154
|
|
|
$order->getVar('cmd_telephone'), |
|
155
|
|
|
$order->getVar('cmd_email'), |
|
156
|
|
|
$order->getVar('cmd_articles_count'), |
|
157
|
|
|
$order->getVar('cmd_total'), |
|
158
|
|
|
$order->getVar('cmd_shipping'), |
|
159
|
|
|
$order->getVar('cmd_bill'), |
|
160
|
|
|
$order->getVar('cmd_password'), |
|
161
|
|
|
$order->getVar('cmd_text'), |
|
162
|
|
|
$order->getVar('cmd_cancel'), |
|
163
|
|
|
$cart->getVar('caddy_id'), |
|
164
|
|
|
$cart->getVar('caddy_product_id'), |
|
165
|
|
|
$cart->getVar('caddy_qte'), |
|
166
|
|
|
$cart->getVar('caddy_price'), |
|
167
|
|
|
$cart->getVar('caddy_cmd_id'), |
|
168
|
|
|
$cart->getVar('caddy_shipping'), |
|
169
|
|
|
$cart->getVar('caddy_pass'), |
|
170
|
|
|
]); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
dbase_close($dbf); |
|
|
|
|
|
|
174
|
|
|
$this->success = true; |
|
175
|
|
|
|
|
176
|
|
|
return true; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Retourne le lien à utiliser pour télécharger le fichier d'export |
|
181
|
|
|
* @return bool|string Le lien à utiliser |
|
182
|
|
|
*/ |
|
183
|
|
|
public function getDownloadUrl() |
|
184
|
|
|
{ |
|
185
|
|
|
if ($this->success) { |
|
186
|
|
|
return $this->url . '/' . $this->filename; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
return false; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @return bool|string |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getDownloadPath() |
|
196
|
|
|
{ |
|
197
|
|
|
if ($this->success) { |
|
198
|
|
|
return $this->folder . DIRECTORY_SEPARATOR . $this->filename; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
return false; |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
|