Skip to content

Commit f445eb7

Browse files
committed
adicionando funcao custom de export
1 parent 2ff7a1e commit f445eb7

File tree

7 files changed

+69
-39
lines changed

7 files changed

+69
-39
lines changed

src/VMBDataExport/Export/CSVExport.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,11 @@ public function export()
7272

7373
/**
7474
* @param array $data
75+
* @param array $headers
7576
* @return mixed
7677
*/
77-
public function writeCustomData(array $data)
78+
public function writeCustomData(array $data, array $headers)
7879
{
7980
// TODO: Implement writeCustomData() method.
8081
}
81-
82-
/**
83-
* @return mixed
84-
*/
85-
public function exportCustomData()
86-
{
87-
// TODO: Implement exportCustomData() method.
88-
}
8982
}

src/VMBDataExport/Export/ExportDataServiceInterface.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ public function writeData(array $data);
1616

1717
/**
1818
* @param array $data
19+
* @param array $headers
1920
* @return mixed
2021
*/
21-
public function writeCustomData(array $data);
22-
23-
/**
24-
* @return mixed
25-
*/
26-
public function exportCustomData();
22+
public function writeCustomData(array $data, array $headers);
2723
}

src/VMBDataExport/Export/PDFExport.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,11 @@ public function export()
2828

2929
/**
3030
* @param array $data
31+
* @param array $headers
3132
* @return mixed
3233
*/
33-
public function writeCustomData(array $data)
34+
public function writeCustomData(array $data, array $headers)
3435
{
3536
// TODO: Implement writeCustomData() method.
3637
}
37-
38-
/**
39-
* @return mixed
40-
*/
41-
public function exportCustomData()
42-
{
43-
// TODO: Implement exportCustomData() method.
44-
}
4538
}

src/VMBDataExport/Export/XLSExport.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,13 @@ public function export()
9090

9191
/**
9292
* @param array $data
93+
* @param array $headers
9394
* @return mixed
9495
*/
95-
public function writeCustomData(array $data)
96+
public function writeCustomData(array $data, array $headers)
9697
{
97-
// TODO: Implement writeCustomData() method.
98-
}
99-
100-
/**
101-
* @return mixed
102-
*/
103-
public function exportCustomData()
104-
{
105-
// TODO: Implement exportCustomData() method.
98+
$this->resultFormatedData = $data;
99+
$this->headers = $headers;
100+
return $this;
106101
}
107102
}

src/VMBDataExport/Module.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace VMBDataExport;
33

4+
use VMBDataExport\Service\CustomExportService;
45
use Zend\Mvc\ModuleRouteListener;
56
use Zend\Mvc\MvcEvent;
67
use VMBDataExport\Service\MainService;
@@ -32,11 +33,13 @@ public function getAutoloaderConfig()
3233

3334
public function getServiceConfig()
3435
{
35-
3636
return array(
3737
'factories' => array(
3838
'VMBDataExport\Service\MainService' => function ($sm) {
3939
return new MainService($sm->get('Doctrine\ORM\EntityManager'));
40+
},
41+
'VMBDataExport\Service\CustomExportService' => function ($sm) {
42+
return new CustomExportService($sm->get('Doctrine\ORM\EntityManager'));
4043
}
4144
),
4245
);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
namespace VMBDataExport\Service;
3+
4+
use Doctrine\ORM\EntityManager;
5+
use VMBDataExport\Export\ExportDataServiceInterface;
6+
7+
class CustomExportService
8+
{
9+
/**
10+
* @var EntityManager
11+
*/
12+
private $em;
13+
14+
/**
15+
* @var ExportDataServiceInterface
16+
*/
17+
private $class;
18+
19+
/**
20+
* CustomExportService constructor.
21+
* @param EntityManager $em
22+
*/
23+
public function __construct(EntityManager $em)
24+
{
25+
$this->em = $em;
26+
}
27+
28+
/**
29+
* @param $query
30+
* @param array $headerFields
31+
* @param $exportClass
32+
* @return bool|mixed
33+
* @throws \Exception
34+
*/
35+
public function export($query, array $headerFields, $exportClass)
36+
{
37+
$result = $this->em->createQuery($query)->getArrayResult();
38+
39+
$type = strtoupper($exportClass);
40+
$class = 'VMBDataExport\\Export\\' . $type . 'Export';
41+
42+
if (class_exists($class)) {
43+
if (null === $this->class) {
44+
$this->class = new $class($this->em);
45+
}
46+
if ($this->class instanceof ExportDataServiceInterface) {
47+
$this->class->writeCustomData($result, $headerFields);
48+
return $this->class->export();
49+
}
50+
throw new \Exception("Class {$class} must implements 'VMBDataExport\\Export\\ExportDataServiceInterface' ");
51+
}
52+
throw new \Exception("Class {$class} does not exist");
53+
}
54+
}

src/VMBDataExport/Service/MainService.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ public function strategy($exportType, array $data)
3434
$this->responsableClass = new $class($this->em);
3535
}
3636
if ($this->responsableClass instanceof Export\ExportDataServiceInterface) {
37-
if (isset($data['custom']) && $data['custom'] != null) {
38-
$this->responsableClass->writeCustomData($data);
39-
return $this->responsableClass->exportCustomData();
40-
}
4137
$this->responsableClass->writeData($data);
4238
return $this->responsableClass->export();
4339
}

0 commit comments

Comments
 (0)