Skip to content

Commit 2ff7a1e

Browse files
committed
pequena manutenção
1 parent f308acf commit 2ff7a1e

File tree

6 files changed

+100
-41
lines changed

6 files changed

+100
-41
lines changed

src/VMBDataExport/Export/CSVExport.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public function writeData(array $dados)
5454

5555
public function export()
5656
{
57-
5857
$path = __DIR__ . '/../../../../../../public/csv/';
5958
if (!is_dir($path)) {
6059
throw new \Exception("Please make sure that 'public/csv' directory exists");
@@ -69,7 +68,22 @@ public function export()
6968

7069
fclose($file);
7170
return '/csv/' . $fileName;
71+
}
7272

73+
/**
74+
* @param array $data
75+
* @return mixed
76+
*/
77+
public function writeCustomData(array $data)
78+
{
79+
// TODO: Implement writeCustomData() method.
7380
}
7481

82+
/**
83+
* @return mixed
84+
*/
85+
public function exportCustomData()
86+
{
87+
// TODO: Implement exportCustomData() method.
88+
}
7589
}

src/VMBDataExport/Export/ExportDataServiceInterface.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33

44
interface ExportDataServiceInterface
55
{
6-
76
/**
8-
* Método que deve ser implementado para os serviços que farão exportação de dados
9-
* @author Vitor Barros
107
* @return mixed
118
*/
129
public function export();
1310

1411
/**
15-
* Método que deve ser implementado para gravar os dados no tipo de arquivo selecionado
16-
* @author Vitor Barros
12+
* @param array $data
13+
* @return mixed
14+
*/
15+
public function writeData(array $data);
16+
17+
/**
18+
* @param array $data
1719
* @return mixed
1820
*/
19-
public function writeData(array $dados);
21+
public function writeCustomData(array $data);
2022

23+
/**
24+
* @return mixed
25+
*/
26+
public function exportCustomData();
2127
}

src/VMBDataExport/Export/PDFExport.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function __construct(EntityManager $em)
1515
{
1616
$this->em = $em;
1717
}
18-
18+
1919
public function writeData(array $dados)
2020
{
2121
//TODO implement this action
@@ -25,4 +25,21 @@ public function export()
2525
{
2626
//TODO implement this action
2727
}
28+
29+
/**
30+
* @param array $data
31+
* @return mixed
32+
*/
33+
public function writeCustomData(array $data)
34+
{
35+
// TODO: Implement writeCustomData() method.
36+
}
37+
38+
/**
39+
* @return mixed
40+
*/
41+
public function exportCustomData()
42+
{
43+
// TODO: Implement exportCustomData() method.
44+
}
2845
}

src/VMBDataExport/Export/XLSExport.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ public function writeData(array $dados)
4444
foreach ($this->headers as $head) {
4545
$resultFormated['result'][$head] = $arrayData[$head];
4646
}
47-
4847
$result[] = $resultFormated['result'];
4948
}
50-
5149
$this->resultFormatedData = $result;
52-
5350
}
5451

5552
public function export()
@@ -90,4 +87,21 @@ public function export()
9087
fclose($file);
9188
return '/xls/' . $fileName;
9289
}
90+
91+
/**
92+
* @param array $data
93+
* @return mixed
94+
*/
95+
public function writeCustomData(array $data)
96+
{
97+
// TODO: Implement writeCustomData() method.
98+
}
99+
100+
/**
101+
* @return mixed
102+
*/
103+
public function exportCustomData()
104+
{
105+
// TODO: Implement exportCustomData() method.
106+
}
93107
}

src/VMBDataExport/Form/Export.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,63 @@
11
<?php
22
namespace VMBDataExport\Form;
33

4-
use Zend\Form\Form;;
4+
use Zend\Form\Form;
5+
6+
;
57

68
class Export extends Form
79
{
810

9-
public function __construct($name = null) {
11+
public function __construct($name = null)
12+
{
1013

1114
parent::__construct('dataExport');
1215

13-
$this->setAttribute('method','post');
16+
$this->setAttribute('method', 'post');
1417

1518
//field de email
1619
$this->add(array(
17-
'name' => 'entity',
20+
'name' => 'entity',
1821
'attributes' => array(
1922
'id' => 'entity',
2023
),
2124
));
2225

2326
$this->add(array(
24-
'name' => 'criteria',
27+
'name' => 'criteria',
2528
'attributes' => array(
2629
'id' => 'criteria',
2730
),
2831
));
2932

3033
$this->add(array(
31-
'name' => 'type',
34+
'name' => 'type',
3235
'attributes' => array(
3336
'id' => 'type',
3437
),
3538
));
3639

3740
$this->add(array(
38-
'name' => 'redirect_to',
41+
'name' => 'redirect_to',
3942
'attributes' => array(
4043
'id' => 'redirect_to',
4144
),
4245
));
4346

4447
$this->add(array(
45-
'name' => 'headers',
48+
'name' => 'headers',
4649
'attributes' => array(
4750
'id' => 'headers',
4851
),
4952
));
5053

54+
$this->add(array(
55+
'name' => 'custom',
56+
'attributes' => array(
57+
'id' => 'custom'
58+
)
59+
));
60+
5161
$this->add(array(
5262
'name' => 'submit',
5363
'type' => 'Zend\Form\Element\Submit',

src/VMBDataExport/Service/MainService.php

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,35 @@ class MainService
1616
*/
1717
protected $responsableClass;
1818

19-
public function __construct(EntityManager $em) {
19+
public function __construct(EntityManager $em)
20+
{
2021
$this->em = $em;
2122
}
2223

23-
public function strategy($exportType, array $dados) {
24-
25-
if($exportType != null) {
24+
public function strategy($exportType, array $data)
25+
{
26+
if ($exportType != null) {
2627

2728
$type = strtoupper($exportType);
28-
$class = 'VMBDataExport\\Export\\'.$type.'Export';
29+
$class = 'VMBDataExport\\Export\\' . $type . 'Export';
2930

30-
if(class_exists($class)) {
31+
if (class_exists($class)) {
3132

32-
if(null === $this->responsableClass) {
33+
if (null === $this->responsableClass) {
3334
$this->responsableClass = new $class($this->em);
3435
}
35-
36-
if($this->responsableClass instanceof Export\ExportDataServiceInterface) {
37-
38-
$this->responsableClass->writeData($dados);
36+
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+
}
41+
$this->responsableClass->writeData($data);
3942
return $this->responsableClass->export();
40-
41-
}else
42-
throw new \Exception("Class {$class} must implements 'DataExport\\Export\\ExportDataServiceInterface' ");
43-
44-
}else
45-
throw new \Exception("Class {$class} does not exist");
46-
47-
}else
48-
throw new \Exception("Type can not be null");
49-
43+
}
44+
throw new \Exception("Class {$class} must implements 'VMBDataExport\\Export\\ExportDataServiceInterface' ");
45+
}
46+
throw new \Exception("Class {$class} does not exist");
47+
}
48+
throw new \Exception("Type can not be null");
5049
}
51-
5250
}

0 commit comments

Comments
 (0)