-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from fphgov/develop
v1.0.1
- Loading branch information
Showing
30 changed files
with
506 additions
and
113 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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Entity; | ||
|
||
use App\Traits\EntityTrait; | ||
use DateTime; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Serializer\Annotation\Groups; | ||
|
||
/** | ||
* @ORM\Entity(repositoryClass="App\Repository\StatRepository") | ||
* @ORM\Table(name="stats") | ||
*/ | ||
class Stat implements StatInterface | ||
{ | ||
use EntityTrait; | ||
|
||
/** | ||
* @ORM\Column(name="date", type="date") | ||
* | ||
* @Groups({"stat", "full_detail"}) | ||
*/ | ||
private DateTime $date; | ||
|
||
/** | ||
* @ORM\Id | ||
* @ORM\Column(name="day", type="integer", options={"unsigned"=true}) | ||
* @ORM\GeneratedValue(strategy="IDENTITY") | ||
* | ||
* @Groups({"stat", "full_detail"}) | ||
*/ | ||
private int $day; | ||
|
||
/** | ||
* @ORM\Column(name="count", type="integer") | ||
* | ||
* @Groups({"stat", "full_detail"}) | ||
*/ | ||
private int $count; | ||
|
||
public function getDate(): DateTime | ||
{ | ||
return $this->date; | ||
} | ||
|
||
public function setDate(DateTime $date): void | ||
{ | ||
$this->date = $date; | ||
} | ||
|
||
public function getDay(): int | ||
{ | ||
return $this->day; | ||
} | ||
|
||
public function setDay(int $day): void | ||
{ | ||
$this->day = $day; | ||
} | ||
|
||
public function getCount(): int | ||
{ | ||
return $this->count; | ||
} | ||
|
||
public function setCount(int $count): void | ||
{ | ||
$this->count = $count; | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Entity; | ||
|
||
use DateTime; | ||
|
||
interface StatInterface | ||
{ | ||
public function getDate(): DateTime; | ||
|
||
public function setDate(DateTime $date): void; | ||
|
||
public function getDay(): int; | ||
|
||
public function setDay(int $day): void; | ||
|
||
public function getCount(): int; | ||
|
||
public function setCount(int $count): void; | ||
} |
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
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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Handler\Stat; | ||
|
||
use App\Model\StatExportModel; | ||
use Laminas\Diactoros\Stream; | ||
use Laminas\Diactoros\Response; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
use function ob_start; | ||
use function ob_get_clean; | ||
use function fopen; | ||
use function fputcsv; | ||
use function rewind; | ||
use function strval; | ||
|
||
final class GetHistoryHandler implements RequestHandlerInterface | ||
{ | ||
public function __construct( | ||
private StatExportModel $statExportModel, | ||
) { | ||
$this->statExportModel = $statExportModel; | ||
} | ||
|
||
public function handle(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
$exportData = $this->statExportModel->getCsvData(); | ||
|
||
ob_start(); | ||
ob_get_clean(); | ||
|
||
$stream = fopen('php://memory', 'wb+'); | ||
|
||
foreach ($exportData as $fields) { | ||
fputcsv($stream, $fields, ";"); | ||
} | ||
|
||
rewind($stream); | ||
|
||
$body = new Stream($stream); | ||
|
||
return new Response($body, 200, [ | ||
'Content-Type' => 'text/csv; charset=utf-8', | ||
'Content-Disposition' => "attachment; filename=\"votes.csv\"", | ||
'Content-Description' => 'File Transfer', | ||
'Pragma' => 'public', | ||
'Expires' => '0', | ||
'Cache-Control' => 'must-revalidate', | ||
'Content-Length' => strval($body->getSize()), | ||
]); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Handler\Stat; | ||
|
||
use App\Model\StatExportModel; | ||
use Psr\Container\ContainerInterface; | ||
|
||
final class GetHistoryHandlerFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): GetHistoryHandler | ||
{ | ||
return new GetHistoryHandler( | ||
$container->get(StatExportModel::class) | ||
); | ||
} | ||
} |
Oops, something went wrong.