1 | <?php |
||
19 | class Import extends Controller |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * File transfer model class instance |
||
24 | * @var \gplcart\core\models\FileTransfer $file_transfer |
||
25 | */ |
||
26 | protected $file_transfer; |
||
27 | |||
28 | /** |
||
29 | * CSV helper class |
||
30 | * @var \gplcart\modules\import\helpers\Csv $csv |
||
31 | */ |
||
32 | protected $csv; |
||
33 | |||
34 | /** |
||
35 | * @param FileTransfer $file_transfer |
||
36 | * @param Csv $csv |
||
37 | */ |
||
38 | public function __construct(FileTransfer $file_transfer, Csv $csv) |
||
45 | |||
46 | /** |
||
47 | * Displays the import page |
||
48 | */ |
||
49 | public function doImport() |
||
50 | { |
||
51 | $this->downloadErrorsImport(); |
||
52 | |||
53 | $settings = $this->module->getSettings('import'); |
||
54 | $this->setData('settings', $settings); |
||
55 | |||
56 | unset($settings['header']['product_id']); |
||
57 | $this->setData('columns', $settings['header']); |
||
58 | |||
59 | $this->submitImport(); |
||
60 | $this->setTitleDoImport(); |
||
61 | $this->setBreadcrumbDoImport(); |
||
62 | |||
63 | $this->outputDoImport(); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Sets titles on the import page |
||
68 | */ |
||
69 | protected function setTitleDoImport() |
||
70 | { |
||
71 | $this->setTitle($this->text('Import')); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Sets breadcrumbs on the import page |
||
76 | */ |
||
77 | protected function setBreadcrumbDoImport() |
||
78 | { |
||
79 | $breadcrumb = array( |
||
80 | 'text' => $this->text('Dashboard'), |
||
81 | 'url' => $this->url('admin') |
||
82 | ); |
||
83 | |||
84 | $this->setBreadcrumb($breadcrumb); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Renders the import page |
||
89 | */ |
||
90 | protected function outputDoImport() |
||
91 | { |
||
92 | $this->output('import|import'); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Downloads an error log file |
||
97 | */ |
||
98 | protected function downloadErrorsImport() |
||
99 | { |
||
100 | $file = gplcart_file_private_temp('import_module_errors.csv'); |
||
101 | |||
102 | if ($this->isQuery('download_errors') && is_file($file)) { |
||
103 | $this->download($file); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Start import |
||
109 | */ |
||
110 | protected function submitImport() |
||
116 | |||
117 | /** |
||
118 | * Validates submitted import data |
||
119 | * @return boolean |
||
120 | */ |
||
121 | protected function validateImport() |
||
129 | |||
130 | /** |
||
131 | * Validate uploaded CSV file |
||
132 | * @return boolean |
||
133 | */ |
||
134 | protected function validateFileImport() |
||
156 | |||
157 | /** |
||
158 | * Validates CSV header |
||
159 | */ |
||
160 | public function validateHeaderImport() |
||
178 | |||
179 | /** |
||
180 | * Sets up import |
||
181 | */ |
||
182 | protected function setJobImport() |
||
208 | |||
209 | } |
||
210 |