Skip to content

Commit f308acf

Browse files
committed
resolvendo problema do diretorio
1 parent 5493031 commit f308acf

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

src/VMBDataExport/Export/CSVExport.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ class CSVExport implements ExportDataServiceInterface
1616
private $resultFormatedData;
1717
private $headers;
1818

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

23-
public function writeData(array $dados) {
24+
public function writeData(array $dados)
25+
{
2426

2527
$entity = null;
2628
$criteria = Json::decode($dados['criteria'], Json::TYPE_ARRAY);
@@ -31,15 +33,15 @@ public function writeData(array $dados) {
3133
$resultFormated = array();
3234
$entityData = array();
3335

34-
if(empty($criteria)) {
36+
if (empty($criteria)) {
3537
$entityData = $this->em->getRepository($entity)->findAll();
36-
}else{
38+
} else {
3739
$entityData = $this->em->getRepository($entity)->findBy($criteria);
3840
}
3941

40-
foreach($entityData as $data) {
42+
foreach ($entityData as $data) {
4143
$arrayData = $data->toArray();
42-
foreach($this->headers as $head) {
44+
foreach ($this->headers as $head) {
4345
$resultFormated['result'][$head] = $arrayData[$head];
4446
}
4547

@@ -50,19 +52,23 @@ public function writeData(array $dados) {
5052

5153
}
5254

53-
public function export() {
55+
public function export()
56+
{
5457

55-
$path = dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/public/csv/';
56-
$fileName = str_replace("/",".",base64_encode(Rand::getBytes(6,true)).'_'.date("Y-m-d-H:i:s").'.csv');
57-
$file = fopen($path.$fileName,"w");
58+
$path = __DIR__ . '/../../../../../../public/csv/';
59+
if (!is_dir($path)) {
60+
throw new \Exception("Please make sure that 'public/csv' directory exists");
61+
}
62+
$fileName = str_replace("/", ".", base64_encode(Rand::getBytes(6, true)) . '_' . date("Y-m-d-H:i:s") . '.csv');
63+
$file = fopen($path . $fileName, "w");
5864

59-
fputcsv($file,$this->headers);
60-
foreach($this->resultFormatedData as $data) {
61-
fputcsv($file,$data);
65+
fputcsv($file, $this->headers);
66+
foreach ($this->resultFormatedData as $data) {
67+
fputcsv($file, $data);
6268
}
6369

6470
fclose($file);
65-
return '/csv/'.$fileName;
71+
return '/csv/' . $fileName;
6672

6773
}
6874

src/VMBDataExport/Export/PDFExport.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@ class PDFExport implements ExportDataServiceInterface
1111
*/
1212
private $em;
1313

14-
public function __construct(EntityManager $em) {
14+
public function __construct(EntityManager $em)
15+
{
1516
$this->em = $em;
1617
}
17-
18-
19-
public function writeData(array $dados) {
20-
echo '<pre> pdf';
21-
print_r($dados);
22-
exit;
18+
19+
public function writeData(array $dados)
20+
{
21+
//TODO implement this action
2322
}
2423

25-
public function export() {
26-
27-
28-
24+
public function export()
25+
{
26+
//TODO implement this action
2927
}
30-
31-
3228
}

0 commit comments

Comments
 (0)