Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de36b68
commit 663e927
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
namespace AppBundle\Service\Csv; | ||
|
||
use AppBundle\Entity\Inquiry; | ||
use League\Csv\Writer; | ||
|
||
class InquiryCsvBuilder | ||
{ | ||
private $encoding; | ||
private $inquiryRepository; | ||
|
||
public function __construct($encoding, $inquiryRepository) { | ||
$this->encoding = $encoding; | ||
$this->inquiryRepository = $inquiryRepository; | ||
} | ||
|
||
/** | ||
* CSV形式の文字列を作成する | ||
*/ | ||
public function build($keyword) { | ||
$inquiryList = $this->inquiryRepository->findAllByKeyword($keyword); | ||
|
||
/** @var Writer $writer */ | ||
$writer = Writer::createFromString('',''); | ||
$writer->setNewline("\r\n"); | ||
|
||
foreach ($inquiryList as $inquiry) { | ||
/** @var Inquiry $inquiry */ | ||
$writer->insertOne([ | ||
$inquiry->getId(), | ||
$inquiry->getName(), | ||
$inquiry->getEmail() | ||
]); | ||
} | ||
|
||
return mb_convert_encoding((string)$writer, $this->encoding, 'UTF-8'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
namespace AppBundle\Service\Csv; | ||
|
||
use AppBundle\Entity\Inquiry; | ||
use League\Csv\Writer; | ||
|
||
class InquiryCsvBuilder | ||
{ | ||
private $encoding; | ||
private $inquiryRepository; | ||
|
||
public function __construct($encoding, $inquiryRepository) { | ||
$this->encoding = $encoding; | ||
$this->inquiryRepository = $inquiryRepository; | ||
} | ||
|
||
/** | ||
* CSV形式の文字列を作成する | ||
*/ | ||
public function build($keyword) { | ||
$inquiryList = $this->inquiryRepository->findAllByKeyword($keyword); | ||
|
||
/** @var Writer $writer */ | ||
$writer = Writer::createFromString('',''); | ||
$writer->setNewline("\r\n"); | ||
|
||
foreach ($inquiryList as $inquiry) { | ||
/** @var Inquiry $inquiry */ | ||
$writer->insertOne([ | ||
$inquiry->getId(), | ||
$inquiry->getName(), | ||
$inquiry->getEmail() | ||
]); | ||
} | ||
|
||
return mb_convert_encoding((string)$writer, $this->encoding, 'UTF-8'); | ||
} | ||
} |