|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SpeckCatalog; |
|
4
|
|
|
|
|
5
|
|
|
class Module |
|
6
|
|
|
{ |
|
7
|
|
|
protected $serviceManager; |
|
8
|
|
|
|
|
9
|
|
|
public function getAutoloaderConfig() |
|
10
|
|
|
{ |
|
11
|
|
|
return array( |
|
12
|
|
|
'Zend\Loader\StandardAutoloader' => array( |
|
13
|
|
|
'namespaces' => array( |
|
14
|
|
|
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, |
|
15
|
|
|
), |
|
16
|
|
|
), |
|
17
|
|
|
); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function getConfig() |
|
21
|
|
|
{ |
|
22
|
|
|
$config = array(); |
|
23
|
|
|
$configFiles = array( |
|
24
|
|
|
__DIR__ . '/config/module.config.php', |
|
25
|
|
|
__DIR__ . '/config/module.config.routes.php', |
|
26
|
|
|
__DIR__ . '/config/module.config.servicemanager.php', |
|
27
|
|
|
); |
|
28
|
|
|
foreach($configFiles as $configFile) { |
|
|
|
|
|
|
29
|
|
|
$config = \Zend\Stdlib\ArrayUtils::merge($config, include $configFile); |
|
30
|
|
|
} |
|
31
|
|
|
return $config; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getViewHelperConfig() |
|
35
|
|
|
{ |
|
36
|
|
|
return include(__DIR__ . '/config/services/viewhelpers.php'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getServiceConfig() |
|
40
|
|
|
{ |
|
41
|
|
|
return include(__DIR__ . '/config/services/servicemanager.php'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function onBootstrap($e) |
|
45
|
|
|
{ |
|
46
|
|
|
if($e->getRequest() instanceof \Zend\Console\Request){ |
|
|
|
|
|
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$app = $e->getParam('application'); |
|
51
|
|
|
|
|
52
|
|
|
$locator = $app->getServiceManager(); |
|
53
|
|
|
$this->setServiceManager($locator); |
|
54
|
|
|
|
|
55
|
|
|
$em = $app->getEventManager()->getSharedManager(); |
|
56
|
|
|
|
|
57
|
|
|
$em->attach('ImageUploader\Service\Uploader', 'fileupload.pre', array('SpeckCatalog\Event\FileUpload', 'preFileUpload')); |
|
|
|
|
|
|
58
|
|
|
$em->attach('ImageUploader\Service\Uploader', 'fileupload.post', array('SpeckCatalog\Event\FileUpload', 'postFileUpload')); |
|
59
|
|
|
|
|
60
|
|
|
$em->attach('SpeckCatalog\Service\ProductUom', 'insert.post', function ($e) { |
|
61
|
|
|
$eventClass = new Event\FrontendEnabled; |
|
62
|
|
|
$eventClass->insertProductUom($e); |
|
63
|
|
|
}); |
|
64
|
|
|
$em->attach('SpeckCatalog\Service\ProductUom', 'update.post', function ($e) { |
|
65
|
|
|
$eventClass = new Event\FrontendEnabled; |
|
66
|
|
|
$eventClass->updateProductUom($e); |
|
67
|
|
|
}); |
|
68
|
|
|
$em->attach('SpeckCatalog\Service\Product', 'update.post', array('SpeckCatalog\Event\FrontendEnabled', 'updateProduct')); |
|
69
|
|
|
$em->attach('SpeckCatalog\Service\Product', 'insert.post', array('SpeckCatalog\Event\FrontendEnabled', 'insertProduct')); |
|
70
|
|
|
|
|
71
|
|
|
//install event listeners |
|
72
|
|
|
$em->attach('SpeckInstall\Controller\InstallController', 'install.create_tables.post', array($this, 'constraints'),1); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function constraints($e) |
|
76
|
|
|
{ |
|
77
|
|
|
try { |
|
78
|
|
|
$mapper = $e->getParam('mapper'); |
|
79
|
|
|
|
|
80
|
|
|
//check dependencies |
|
81
|
|
|
$tables = $mapper->query("show tables like 'contact_company'"); |
|
82
|
|
|
if(!count($tables)) { |
|
|
|
|
|
|
83
|
|
|
return array(false, 'SpeckCatalog could not add table constraints - missing table contact_company from SpeckContact'); |
|
84
|
|
|
} |
|
85
|
|
|
$tables = $mapper->query("show tables like 'catalog_product'"); |
|
86
|
|
|
if(!count($tables)) { |
|
|
|
|
|
|
87
|
|
|
return array(false, 'SpeckCatalog could not add table constraints - missing tables provided by SpeckCatalog'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$alter = file_get_contents(__DIR__ .'/data/alter.sql'); |
|
91
|
|
|
$mapper->query($alter); |
|
92
|
|
|
|
|
|
|
|
|
|
93
|
|
|
} catch (\Exception $e) { |
|
94
|
|
|
return array(false, "SpeckCatalog could not add table constraints - " . $e->getMessage()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return array(true, "SpeckCatalog added table constraints"); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return serviceManager |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getServiceManager() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->serviceManager; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param $serviceManager |
|
110
|
|
|
* @return self |
|
111
|
|
|
*/ |
|
112
|
|
|
public function setServiceManager($serviceManager) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->serviceManager = $serviceManager; |
|
115
|
|
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|