1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SpeckCatalog\Event; |
4
|
|
|
|
5
|
|
|
class FileUpload |
6
|
|
|
{ |
7
|
|
|
public function preFileUpload($e) |
8
|
|
|
{ |
9
|
|
|
$formData = $e->getParam('params'); |
10
|
|
|
$getter = 'get' . ucfirst($formData['file_type']) . 'Upload'; |
11
|
|
|
|
12
|
|
|
$catalogOptions = $this->getServiceManager()->get('speckcatalog_module_options'); |
|
|
|
|
13
|
|
|
|
14
|
|
|
if ($formData['file_type'] === 'productDocument') { |
15
|
|
|
$e->getParam('options')->setAllowedFileTypes(array('pdf' => 'pdf')); |
16
|
|
|
$e->getParam('options')->setUseMin(false); |
17
|
|
|
$e->getParam('options')->setUseMax(false); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
$appRoot = __DIR__ . '/../..'; |
21
|
|
|
$path = $appRoot . $catalogOptions->$getter(); |
22
|
|
|
$e->getParam('options')->setDestination($path); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function postFileUpload($e) |
26
|
|
|
{ |
27
|
|
|
$params = $e->getParams(); |
28
|
|
|
switch ($params['params']['file_type']) { |
29
|
|
|
case 'productImage': |
30
|
|
|
$imageService = $this->getServiceManager()->get('speckcatalog_product_image_service'); |
|
|
|
|
31
|
|
|
$image = $imageService->getEntity(); |
32
|
|
|
$image->setProductId($params['params']['product_id']) |
33
|
|
|
->setFileName($params['fileName']); |
34
|
|
|
$imageService->persist($image); |
35
|
|
|
break; |
36
|
|
|
case 'productDocument': |
37
|
|
|
$documentService = $this->getServiceManager()->get('speckcatalog_document_service'); |
|
|
|
|
38
|
|
|
$document = $documentService->getEntity(); |
39
|
|
|
$document->setProductId($params['params']['product_id']) |
40
|
|
|
->setFileName($params['fileName']); |
41
|
|
|
$documentService->persist($document); |
42
|
|
|
break; |
43
|
|
|
case 'optionImage': |
44
|
|
|
$imageService = $this->getServiceManager()->get('speckcatalog_option_image_service'); |
|
|
|
|
45
|
|
|
$image = $imageService->getEntity(); |
46
|
|
|
$image->setOptionId($params['params']['option_id']) |
47
|
|
|
->setFileName($params['fileName']); |
48
|
|
|
$imageService->persist($image); |
49
|
|
|
break; |
50
|
|
|
default: |
51
|
|
|
throw new \Exception('no handler for file type - ' . $params['params']['file_type']); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.