From c5565e28440de08b2c57f39c6720126d6f8169b0 Mon Sep 17 00:00:00 2001 From: fizk Date: Wed, 26 Jun 2024 08:28:05 +0000 Subject: [PATCH] Renames Category to Kind Issues can be either A issues or B issues. This PR changes the name of this type from Category to Kind --- config/route.php | 4 +- docker-compose.yml | 5 +- schema/00005.rename-category.sql | 27 ++++ src/Controller/AssemblyController.php | 2 +- src/Controller/CabinetController.php | 2 +- src/Controller/CategoryController.php | 2 +- src/Controller/CommitteeController.php | 2 +- .../CommitteeDocumentController.php | 9 +- .../CommitteeMeetingAgendaController.php | 2 +- src/Controller/CommitteeMeetingController.php | 2 +- src/Controller/CommitteeSittingController.php | 2 +- src/Controller/CongressmanController.php | 2 +- .../CongressmanDocumentController.php | 5 +- src/Controller/ConstituencyController.php | 2 +- src/Controller/DocumentController.php | 5 +- src/Controller/InflationController.php | 2 +- src/Controller/IssueCategoryController.php | 5 +- src/Controller/IssueController.php | 15 +- src/Controller/MinisterSittingController.php | 2 +- src/Controller/MinistryController.php | 2 +- src/Controller/PartyController.php | 2 +- src/Controller/PlenaryAgendaController.php | 2 +- src/Controller/PlenaryController.php | 2 +- src/Controller/PresidentController.php | 2 +- src/Controller/SessionController.php | 2 +- src/Controller/SpeechController.php | 17 ++- src/Controller/SuperCategoryController.php | 2 +- src/Controller/VoteController.php | 5 +- src/Controller/VoteItemController.php | 5 +- src/Filter/ToNoNullInt.php | 21 +++ src/Form/CommitteeDocument.php | 4 +- src/Form/CommitteeMeetingAgenda.php | 4 +- src/Form/CongressmanDocument.php | 12 +- src/Form/Document.php | 12 +- src/Form/Issue.php | 12 +- src/Form/IssueCategory.php | 8 +- src/Form/IssueLink.php | 4 +- src/Form/PlenaryAgenda.php | 18 ++- src/Form/Speech.php | 4 +- src/Form/Vote.php | 30 ++-- src/Hydrator/CommitteeDocument.php | 3 +- src/Hydrator/CommitteeMeetingAgenda.php | 3 +- src/Hydrator/CongressmanDocument.php | 3 +- src/Hydrator/Document.php | 3 +- src/Hydrator/Issue.php | 3 +- src/Hydrator/IssueAndDate.php | 3 +- src/Hydrator/IssueCategory.php | 3 +- src/Hydrator/IssueLink.php | 5 +- src/Hydrator/IssueValue.php | 3 +- src/Hydrator/Link.php | 3 +- src/Hydrator/PlenaryAgenda.php | 3 +- src/Hydrator/Speech.php | 3 +- src/Hydrator/Vote.php | 3 +- src/Model/CommitteeDocument.php | 27 ++-- src/Model/CommitteeMeetingAgenda.php | 15 +- src/Model/CongressmanDocument.php | 25 ++-- src/Model/Document.php | 25 ++-- src/Model/Issue.php | 49 +++--- src/Model/IssueCategory.php | 19 +-- src/Model/IssueLink.php | 36 ++--- src/Model/KindEnum.php | 20 +++ src/Model/Link.php | 21 ++- src/Model/PlenaryAgenda.php | 47 +++--- src/Model/Speech.php | 13 +- src/Model/Vote.php | 37 ++--- src/Service/Category.php | 9 +- src/Service/CommitteeDocument.php | 11 +- src/Service/Congressman.php | 28 ++-- src/Service/Constituency.php | 2 +- src/Service/DatabaseService.php | 3 + src/Service/Document.php | 4 +- src/Service/Issue.php | 141 ++++++++++-------- src/Service/IssueCategory.php | 16 +- src/Service/IssueLink.php | 13 +- src/Service/Party.php | 11 +- src/Service/Speech.php | 55 +++---- src/Service/Vote.php | 11 +- src/Validator/IssueKind.php | 31 ++++ .../CommitteeDocumentControllerTest.php | 13 +- .../CommitteeMeetingAgendaControllerTest.php | 5 +- .../CongressmanDocumentControllerTest.php | 3 +- .../CongressmanIssueControllerTest.php | 3 +- tests/Controller/DocumentControllerTest.php | 11 +- .../IssueCategoryControllerTest.php | 3 +- tests/Controller/IssueControllerTest.php | 19 +-- .../PlenaryAgendaControllerTest.php | 11 +- tests/Controller/SpeechControllerTest.php | 20 ++- tests/Controller/VoteControllerTest.php | 9 +- tests/Form/PlenaryAgendaTest.php | 6 +- tests/Form/VoteTest.php | 56 ++++--- tests/Service/CategoryTest.php | 23 +-- tests/Service/CommitteeMeetingAgendaTest.php | 39 ++--- tests/Service/CongressmanDocumentTest.php | 37 ++--- tests/Service/CongressmanTest.php | 9 +- tests/Service/DocumentTest.php | 61 ++++---- tests/Service/IssueCategoryTest.php | 29 ++-- tests/Service/IssueTest.php | 54 +++---- tests/Service/PartyTest.php | 5 +- tests/Service/SessionTest.php | 3 +- tests/Service/SpeechTest.php | 71 ++++----- tests/Service/VoteItemTest.php | 25 ++-- tests/Service/VoteTest.php | 63 ++++---- 102 files changed, 885 insertions(+), 670 deletions(-) create mode 100644 schema/00005.rename-category.sql create mode 100644 src/Filter/ToNoNullInt.php create mode 100644 src/Model/KindEnum.php create mode 100644 src/Validator/IssueKind.php diff --git a/config/route.php b/config/route.php index 7f3c83f4..a2f4f414 100644 --- a/config/route.php +++ b/config/route.php @@ -144,10 +144,10 @@ 'thingmal' => [ 'type' => Segment::class, 'options' => [ - 'route' => '/thingmal[/:category[/:issue_id]]', + 'route' => '/thingmal[/:kind[/:issue_id]]', 'constraints' => [ 'issue_id' => '[0-9]+', - 'category' => '[abAB]', + 'kind' => '[abAB]', ], 'defaults' => [ 'controller' => Controller\IssueController::class, diff --git a/docker-compose.yml b/docker-compose.yml index c53edfda..584b47f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -115,9 +115,9 @@ services: environment: - MYSQL_ROOT_PASSWORD=${ENV_DB_PASSWORD:-example} - MYSQL_DATABASE=${ENV_DB_NAME:-althingi} - command: --default-authentication-plugin=mysql_native_password volumes: - local-source-db-volume:/var/lib/mysql + command: --default-authentication-plugin=mysql_native_password database-test: container_name: local-althingi-source-db-test @@ -126,7 +126,10 @@ services: environment: - MYSQL_DATABASE=althingi - MYSQL_ROOT_PASSWORD=example + volumes: + - local-source-db-test-volume:/var/lib/mysql command: --default-authentication-plugin=mysql_native_password volumes: local-source-db-volume: + local-source-db-test-volume: diff --git a/schema/00005.rename-category.sql b/schema/00005.rename-category.sql new file mode 100644 index 00000000..2ccb000c --- /dev/null +++ b/schema/00005.rename-category.sql @@ -0,0 +1,27 @@ +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; + +ALTER TABLE `Category_has_Issue` RENAME COLUMN `category` TO `kind`; +ALTER TABLE `CommitteeMeetingAgenda` RENAME COLUMN `category` TO `kind`; +ALTER TABLE `Congressman_has_Issue` RENAME COLUMN `category` TO `kind`; +ALTER TABLE `Document` RENAME COLUMN `category` TO `kind`; +ALTER TABLE `Document_has_Congressman` RENAME COLUMN `category` TO `kind`; +ALTER TABLE `Document_has_Committee` RENAME COLUMN `category` TO `kind`; +ALTER TABLE `Issue` RENAME COLUMN `category` TO `kind`; +ALTER TABLE `PlenaryAgenda` RENAME COLUMN `category` TO `kind`; +ALTER TABLE `Speech` RENAME COLUMN `category` TO `kind`; +ALTER TABLE `Vote` RENAME COLUMN `category` TO `kind`; + + + +ALTER TABLE `Category_has_Issue` MODIFY `kind` char(1); +ALTER TABLE `CommitteeMeetingAgenda` MODIFY `kind` char(1); +ALTER TABLE `Congressman_has_Issue` MODIFY `kind` char(1); +ALTER TABLE `Document` MODIFY `kind` char(1); +ALTER TABLE `Document_has_Congressman` MODIFY `kind` char(1); +ALTER TABLE `Document_has_Committee` MODIFY `kind` char(1); +ALTER TABLE `Issue` MODIFY `kind` char(1); +ALTER TABLE `PlenaryAgenda` MODIFY `kind` char(1); +ALTER TABLE `Speech` MODIFY `kind` char(1); +ALTER TABLE `Vote` MODIFY `kind` char(1); + +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; diff --git a/src/Controller/AssemblyController.php b/src/Controller/AssemblyController.php index b7dda14a..237affe9 100644 --- a/src/Controller/AssemblyController.php +++ b/src/Controller/AssemblyController.php @@ -109,7 +109,7 @@ public function patch(ServerRequest $request): ResponseInterface { if (($assembly = $this->assemblyService->get($request->getAttribute('id'))) != null) { $form = new Form\Assembly([ - ...(new \Althingi\Hydrator\Assembly())->extract($assembly), + ...$assembly->toArray(), ...$request->getParsedBody(), 'assembly_id' => $request->getAttribute('id'), ]); diff --git a/src/Controller/CabinetController.php b/src/Controller/CabinetController.php index a891d549..dd72fc97 100644 --- a/src/Controller/CabinetController.php +++ b/src/Controller/CabinetController.php @@ -97,7 +97,7 @@ public function patch(ServerRequest $request): ResponseInterface { if (($committee = $this->cabinetService->get($request->getAttribute('id'))) != null) { $form = new Form\Cabinet([ - ...(new \Althingi\Hydrator\Cabinet)->extract($committee), + ...$committee->toArray(), ...$request->getParsedBody(), 'cabinet_id' => $request->getAttribute('id'), ]); diff --git a/src/Controller/CategoryController.php b/src/Controller/CategoryController.php index 68010a78..efb74c96 100644 --- a/src/Controller/CategoryController.php +++ b/src/Controller/CategoryController.php @@ -83,7 +83,7 @@ public function patch(ServerRequest $request): ResponseInterface { if (($category = $this->categoryService->get($request->getAttribute('category_id'))) != null) { $form = new Form\Category([ - ...(new \Althingi\Hydrator\Category)->extract($category), + ...$category->toArray(), ...$request->getParsedBody(), 'super_category_id' => $request->getAttribute('super_category_id'), 'category_id' => $request->getAttribute('category_id') diff --git a/src/Controller/CommitteeController.php b/src/Controller/CommitteeController.php index def87e47..ea856369 100644 --- a/src/Controller/CommitteeController.php +++ b/src/Controller/CommitteeController.php @@ -84,7 +84,7 @@ public function patch(ServerRequest $request): ResponseInterface { if (($committee = $this->committeeService->get($request->getAttribute('committee_id'))) != null) { $form = new Form\Committee([ - ...(new \Althingi\Hydrator\Committee)->extract($committee), + ...$committee->toArray(), ...$request->getParsedBody(), 'assembly_id' => $request->getAttribute('id'), 'committee_id' => $request->getAttribute('committee_id'), diff --git a/src/Controller/CommitteeDocumentController.php b/src/Controller/CommitteeDocumentController.php index 8c35e3cb..495164c0 100644 --- a/src/Controller/CommitteeDocumentController.php +++ b/src/Controller/CommitteeDocumentController.php @@ -11,6 +11,7 @@ use Althingi\Form; use Althingi\Service; use Althingi\Injector\ServiceCommitteeDocumentAwareInterface; +use Althingi\Model\KindEnum; use Althingi\Router\{ RestControllerInterface, RestControllerTrait, @@ -103,7 +104,7 @@ public function post(ServerRequest $request): ResponseInterface ...$request->getParsedBody(), 'assembly_id' => $assemblyId, 'issue_id' => $issueId, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'document_id' => $documentId, ]); @@ -120,7 +121,7 @@ public function post(ServerRequest $request): ResponseInterface $committeeDocument->getDocumentId(), $committeeDocument->getAssemblyId(), $committeeDocument->getIssueId(), - 'A', + KindEnum::A, $committeeDocument->getCommitteeId(), $committeeDocument->getPart() ); @@ -134,7 +135,7 @@ public function post(ServerRequest $request): ResponseInterface 'Location' => $this->router->assemble([ 'id' => $assemblyId, 'issue_id' => $issueId, - 'category' => 'a', + 'kind' => KindEnum::A->value, 'document_id' => $documentId, 'document_committee_id' => $committeeDocumentId ], ['name' => 'loggjafarthing/thingmal/thingskjal/nefndir']) @@ -156,7 +157,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('document_committee_id') )) != null) { $form = new Form\CommitteeDocument([ - ...(new \Althingi\Hydrator\CommitteeDocument)->extract($committeeDocument), + ...$committeeDocument->toArray(), ...$request->getParsedBody(), 'document_committee_id' => $request->getAttribute('document_committee_id'), ]); diff --git a/src/Controller/CommitteeMeetingAgendaController.php b/src/Controller/CommitteeMeetingAgendaController.php index 2ec70048..2207aa8d 100644 --- a/src/Controller/CommitteeMeetingAgendaController.php +++ b/src/Controller/CommitteeMeetingAgendaController.php @@ -93,7 +93,7 @@ public function patch(ServerRequest $request): ResponseInterface if (($committeeMeetingAgenda = $this->committeeMeetingAgendaService ->get($committeeMeetingId, $committeeMeetingAgendaId)) != null) { $form = new Form\CommitteeMeetingAgenda([ - ...(new \Althingi\Hydrator\CommitteeMeetingAgenda())->extract($committeeMeetingAgenda), + ...$committeeMeetingAgenda->toArray(), ...$request->getParsedBody(), 'committee_meeting_id' => $request->getAttribute('committee_meeting_id'), 'committee_meeting_agenda_id' => $request->getAttribute('committee_meeting_agenda_id'), diff --git a/src/Controller/CommitteeMeetingController.php b/src/Controller/CommitteeMeetingController.php index ebd69ec4..96f35bfd 100644 --- a/src/Controller/CommitteeMeetingController.php +++ b/src/Controller/CommitteeMeetingController.php @@ -91,7 +91,7 @@ public function patch(ServerRequest $request): ResponseInterface if (($committeeMeeting = $this->committeeMeetingService->get($committeeMeetingId)) != null) { $form = new Form\CommitteeMeeting([ - ...(new \Althingi\Hydrator\CommitteeMeeting())->extract($committeeMeeting), + ...$committeeMeeting->toArray(), ...$request->getParsedBody(), 'committee_meeting_id' => $request->getAttribute('committee_meeting_id'), ]); diff --git a/src/Controller/CommitteeSittingController.php b/src/Controller/CommitteeSittingController.php index bfaebe92..0ec8edff 100644 --- a/src/Controller/CommitteeSittingController.php +++ b/src/Controller/CommitteeSittingController.php @@ -142,7 +142,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('committee_sitting_id') )) != null) { $form = new Form\CommitteeSitting([ - ...(new \Althingi\Hydrator\CommitteeSitting)->extract($committeeSitting), + ...$committeeSitting->toArray(), ...$request->getParsedBody(), 'committee_sitting_id' =>$request->getAttribute('committee_sitting_id'), ]); diff --git a/src/Controller/CongressmanController.php b/src/Controller/CongressmanController.php index a122e9db..41b4634a 100644 --- a/src/Controller/CongressmanController.php +++ b/src/Controller/CongressmanController.php @@ -90,7 +90,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('congressman_id') )) != null) { $form = new Form\Congressman([ - ...(new \Althingi\Hydrator\Congressman)->extract($congressman), + ...$congressman->toArray(), ...$request->getParsedBody(), 'congressman_id' => $request->getAttribute('congressman_id'), ]); diff --git a/src/Controller/CongressmanDocumentController.php b/src/Controller/CongressmanDocumentController.php index d367b50f..f033a1be 100644 --- a/src/Controller/CongressmanDocumentController.php +++ b/src/Controller/CongressmanDocumentController.php @@ -7,6 +7,7 @@ use Althingi\Service; use Althingi\Utils\ErrorFormResponse; use Althingi\Injector\ServiceProponentAwareInterface; +use Althingi\Model\KindEnum; use Laminas\Diactoros\Response\EmptyResponse; use Laminas\Diactoros\ServerRequest; use Althingi\Router\{ @@ -40,7 +41,7 @@ public function put(ServerRequest $request): ResponseInterface 'issue_id' => $issueId, 'document_id' => $documentId, 'congressman_id' => $congressmanId, - 'category' => 'A', + 'kind' => KindEnum::A->value, ]); if ($form->isValid()) { @@ -67,7 +68,7 @@ public function patch(ServerRequest $request): ResponseInterface if (($congressmanDocument = $this->congressmanDocumentService ->get($assemblyId, $issueId, $documentId, $congressmanId)) != null) { $form = new Form\CongressmanDocument([ - ...(new \Althingi\Hydrator\CongressmanDocument())->extract($congressmanDocument), + ...$congressmanDocument->toArray(), ...$request->getParsedBody(), 'id' => $request->getAttribute('id'), 'issue_id' => $request->getAttribute('issue_id'), diff --git a/src/Controller/ConstituencyController.php b/src/Controller/ConstituencyController.php index 6f8ade4f..4655386a 100644 --- a/src/Controller/ConstituencyController.php +++ b/src/Controller/ConstituencyController.php @@ -72,7 +72,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('id') )) !== null) { $form = new Form\Constituency([ - ...(new \Althingi\Hydrator\Constituency())->extract($constituency), + ...$constituency->toArray(), ...$request->getParsedBody(), 'constituency_id' => $request->getAttribute('id') ]); diff --git a/src/Controller/DocumentController.php b/src/Controller/DocumentController.php index 0da9380c..7b369cca 100644 --- a/src/Controller/DocumentController.php +++ b/src/Controller/DocumentController.php @@ -11,6 +11,7 @@ use Althingi\Service; use Althingi\Form; use Althingi\Injector\ServiceDocumentAwareInterface; +use Althingi\Model\KindEnum; use Althingi\Utils\ErrorFormResponse; use Althingi\Router\{ RestControllerTrait, @@ -71,7 +72,7 @@ public function put(ServerRequest $request): ResponseInterface 'assembly_id' => $assemblyId, 'issue_id' => $issueId, 'document_id' => $documentId, - 'category' => 'A', + 'kind' => KindEnum::A->value, ]); if ($form->isValid()) { @@ -96,7 +97,7 @@ public function patch(ServerRequest $request): ResponseInterface if (($document = $this->documentService->get($assemblyId, $issueId, $documentId)) != null) { $form = new Form\Document([ - ...(new \Althingi\Hydrator\Document())->extract($document), + ...$document->toArray(), ...$request->getParsedBody(), 'id' => $request->getAttribute('id'), 'issue_id' => $request->getAttribute('issue_id'), diff --git a/src/Controller/InflationController.php b/src/Controller/InflationController.php index 935751a6..0b20fa85 100644 --- a/src/Controller/InflationController.php +++ b/src/Controller/InflationController.php @@ -135,7 +135,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('id') )) != null) { $form = new Form\Inflation([ - ...(new \Althingi\Hydrator\Inflation())->extract($committee), + ...$committee->toArray(), ...$request->getParsedBody(), 'id' => $request->getAttribute('id'), ]); diff --git a/src/Controller/IssueCategoryController.php b/src/Controller/IssueCategoryController.php index b5e32f78..0b9585aa 100644 --- a/src/Controller/IssueCategoryController.php +++ b/src/Controller/IssueCategoryController.php @@ -14,6 +14,7 @@ ServiceIssueCategoryAwareInterface, ServiceCategoryAwareInterface }; +use Althingi\Model\KindEnum; use Althingi\Utils\{ ErrorFormResponse }; @@ -82,7 +83,7 @@ public function put(ServerRequest $request): ResponseInterface 'assembly_id' => $assemblyId, 'issue_id' => $issueId, 'category_id' => $categoryId, - 'category' => 'A' + 'kind' => KindEnum::A->value ])); if ($form->isValid()) { @@ -107,7 +108,7 @@ public function patch(ServerRequest $request): ResponseInterface if (($issueCategory = $this->issueCategoryService->get($assemblyId, $issueId, $categoryId)) != null) { $form = new Form\IssueCategory([ - ...(new \Althingi\Hydrator\IssueCategory())->extract($issueCategory), + ...$issueCategory->toArray(), ...$request->getParsedBody(), 'id' => $request->getAttribute('id'), 'issue_id' => $request->getAttribute('issue_id'), diff --git a/src/Controller/IssueController.php b/src/Controller/IssueController.php index f26e930c..34bdc198 100644 --- a/src/Controller/IssueController.php +++ b/src/Controller/IssueController.php @@ -11,6 +11,7 @@ }; use Althingi\Injector\ServiceIssueAwareInterface; use Althingi\Form; +use Althingi\Model\KindEnum; use Althingi\Service; use Althingi\Router\RestControllerTrait; use Althingi\Utils\ErrorFormResponse; @@ -34,9 +35,9 @@ public function get(ServerRequest $request): ResponseInterface { $assemblyId = $request->getAttribute('id', 0); $issueId = $request->getAttribute('issue_id', 0); - $category = strtoupper($request->getAttribute('category', 'a')); + $kind = KindEnum::fromString($request->getAttribute('kind', 'a')); - $issue = $this->issueService->get($issueId, $assemblyId, $category); + $issue = $this->issueService->get($issueId, $assemblyId, $kind); return $issue ? new JsonResponse($issue) @@ -90,14 +91,14 @@ public function getList(ServerRequest $request): ResponseInterface public function put(ServerRequest $request): ResponseInterface { $assemblyId = $request->getAttribute('id'); - $category = strtoupper($request->getAttribute('category', 'a')); + $kind = KindEnum::fromString($request->getAttribute('kind', 'a')); $issueId = $request->getAttribute('issue_id'); $form = new Form\Issue([ ...$request->getParsedBody(), 'assembly_id' => $assemblyId, 'issue_id' => $issueId, - 'category' => $category + 'kind' => $kind->value, ]); if ($form->isValid()) { @@ -119,11 +120,11 @@ public function put(ServerRequest $request): ResponseInterface public function patch(ServerRequest $request): ResponseInterface { $assemblyId = $request->getAttribute('id'); - $category = strtoupper($request->getAttribute('category', 'a')); + $kind = KindEnum::fromString($request->getAttribute('kind', 'a')); $issue = $this->issueService->get( $request->getAttribute('issue_id'), $assemblyId, - $category + $kind, ); if (! $issue) { @@ -131,7 +132,7 @@ public function patch(ServerRequest $request): ResponseInterface } $form = new Form\Issue([ - ...(new \Althingi\Hydrator\Issue())->extract($issue), + ...$issue->toArray(), ...$request->getParsedBody(), 'assembly_id' => $request->getAttribute('id'), 'issue_id' => $request->getAttribute('issue_id'), diff --git a/src/Controller/MinisterSittingController.php b/src/Controller/MinisterSittingController.php index eda611ce..8ebe3a45 100644 --- a/src/Controller/MinisterSittingController.php +++ b/src/Controller/MinisterSittingController.php @@ -129,7 +129,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('ministry_sitting_id') )) != null) { $form = new Form\MinisterSitting([ - ...(new \Althingi\Hydrator\MinisterSitting())->extract($ministerSitting), + ...$ministerSitting->toArray(), ...$request->getParsedBody(), 'ministry_sitting_id' => $request->getAttribute('ministry_sitting_id'), ]); diff --git a/src/Controller/MinistryController.php b/src/Controller/MinistryController.php index 06330e5d..f81faf2b 100644 --- a/src/Controller/MinistryController.php +++ b/src/Controller/MinistryController.php @@ -103,7 +103,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('id') )) !== null) { $form = new Form\Ministry([ - ...(new \Althingi\Hydrator\Ministry())->extract($ministry), + ...$ministry->toArray(), ...$request->getParsedBody(), 'ministry_id' => $request->getAttribute('id'), ]); diff --git a/src/Controller/PartyController.php b/src/Controller/PartyController.php index 557a10a0..df907fab 100644 --- a/src/Controller/PartyController.php +++ b/src/Controller/PartyController.php @@ -101,7 +101,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('id') )) !== null) { $form = new Form\Party([ - ...(new \Althingi\Hydrator\Party())->extract($party), + ...$party->toArray(), ...$request->getParsedBody(), 'party_id' => $request->getAttribute('id'), ]); diff --git a/src/Controller/PlenaryAgendaController.php b/src/Controller/PlenaryAgendaController.php index b54f917c..8328be4f 100644 --- a/src/Controller/PlenaryAgendaController.php +++ b/src/Controller/PlenaryAgendaController.php @@ -95,7 +95,7 @@ public function put(ServerRequest $request): ResponseInterface $this->issueService->create((new IssueModel()) ->setIssueId($data->getIssueId()) ->setAssemblyId($data->getAssemblyId()) - ->setCategory($data->getCategory()) + ->setKind($data->getKind()) ->setName(null) ->setType(null) ->setTypeName(null)); diff --git a/src/Controller/PlenaryController.php b/src/Controller/PlenaryController.php index 4610eb5d..13ebda8f 100644 --- a/src/Controller/PlenaryController.php +++ b/src/Controller/PlenaryController.php @@ -92,7 +92,7 @@ public function patch(ServerRequest $request): ResponseInterface if (($plenary = $this->plenaryService->get($assemblyId, $plenaryId)) != null) { $form = new Form\Plenary([ - ...(new \Althingi\Hydrator\Plenary)->extract($plenary), + ...$plenary->toArray(), ...$request->getParsedBody(), 'assembly_id' => $request->getAttribute('id'), 'plenary_id' => $request->getAttribute('plenary_id'), diff --git a/src/Controller/PresidentController.php b/src/Controller/PresidentController.php index 9989e0f0..3941a0a2 100644 --- a/src/Controller/PresidentController.php +++ b/src/Controller/PresidentController.php @@ -114,7 +114,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('id') )) != null) { $form = new Form\President([ - ...(new \Althingi\Hydrator\President())->extract($president), + ...$president->toArray(), ...$request->getParsedBody(), // 'president_id' => $request->getAttribute('id'), ]); diff --git a/src/Controller/SessionController.php b/src/Controller/SessionController.php index 6e50e4c5..3edf4b37 100644 --- a/src/Controller/SessionController.php +++ b/src/Controller/SessionController.php @@ -150,7 +150,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('session_id') )) !== null) { $form = new Form\Session([ - ...(new \Althingi\Hydrator\Session())->extract($session), + ...$session->toArray(), ...$request->getParsedBody(), 'session_id' => $request->getAttribute('session_id') ]); diff --git a/src/Controller/SpeechController.php b/src/Controller/SpeechController.php index b3800f97..5bef5af4 100644 --- a/src/Controller/SpeechController.php +++ b/src/Controller/SpeechController.php @@ -20,6 +20,7 @@ ServicePlenaryAwareInterface, ServiceSpeechAwareInterface }; +use Althingi\Model\KindEnum; use Althingi\Utils\{ ErrorFormResponse, ErrorExceptionResponse @@ -57,11 +58,11 @@ public function get(ServerRequest $request): ResponseInterface { $assemblyId = $request->getAttribute('id'); $issueId = $request->getAttribute('issue_id'); - $category = strtoupper($request->getAttribute('category', 'a')); + $kind = KindEnum::fromString($request->getAttribute('kind', 'a')); $speechId = $request->getAttribute('speech_id'); - $count = $this->speechService->countByIssue($assemblyId, $issueId, $category); - $speeches = $this->speechService->fetch($speechId, $assemblyId, $issueId, 25, $category); + $count = $this->speechService->countByIssue($assemblyId, $issueId, $kind); + $speeches = $this->speechService->fetch($speechId, $assemblyId, $issueId, 25, $kind); $positionBegin = (count($speeches) > 0) ? $speeches[0]->getPosition() : 0 ; @@ -109,12 +110,12 @@ public function getList(ServerRequest $request): ResponseInterface { $assemblyId = $request->getAttribute('id'); $issueId = $request->getAttribute('issue_id'); - $category = strtoupper($request->getAttribute('category', 'a')); + $kind = KindEnum::fromString($request->getAttribute('kind', 'a')); $speechesAndProperties = $this->speechService->fetchAllByIssue( $assemblyId, $issueId, - $category, + $kind, ); return new JsonResponse($speechesAndProperties, 206); @@ -136,14 +137,14 @@ public function put(ServerRequest $request): ResponseInterface { $assemblyId = $request->getAttribute('id'); $issueId = $request->getAttribute('issue_id'); - $category = strtoupper($request->getAttribute('category', 'a')); + $kind = KindEnum::fromString($request->getAttribute('kind', 'a')); $form = new Form\Speech([ ...$request->getParsedBody(), 'speech_id' => $request->getAttribute('speech_id'), 'issue_id' => $issueId, 'assembly_id' => $assemblyId, - 'category' => $category, + 'category' => $kind, ]); if ($form->isValid()) { @@ -201,7 +202,7 @@ public function patch(ServerRequest $request): ResponseInterface if (($speech = $this->speechService->get($request->getAttribute('speech_id'))) != null) { $form = new Form\Speech([ - ...(new \Althingi\Hydrator\Speech())->extract($speech), + ...$speech->toArray(), ...$request->getParsedBody(), 'speech_id' => $request->getAttribute('speech_id'), ]); diff --git a/src/Controller/SuperCategoryController.php b/src/Controller/SuperCategoryController.php index 230bcf97..b0480948 100644 --- a/src/Controller/SuperCategoryController.php +++ b/src/Controller/SuperCategoryController.php @@ -81,7 +81,7 @@ public function patch(ServerRequest $request): ResponseInterface $request->getAttribute('super_category_id') )) != null) { $form = new Form\SuperCategory([ - ...(new \Althingi\Hydrator\SuperCategory())->extract($superCategory), + ...$superCategory->toArray(), ...$request->getParsedBody(), ]); diff --git a/src/Controller/VoteController.php b/src/Controller/VoteController.php index e63e4ed5..e7e4ba92 100644 --- a/src/Controller/VoteController.php +++ b/src/Controller/VoteController.php @@ -11,6 +11,7 @@ use Althingi\Form; use Althingi\Service\Vote; use Althingi\Injector\ServiceVoteAwareInterface; +use Althingi\Model\KindEnum; use Althingi\Utils\ErrorFormResponse; use Althingi\Router\{ RestControllerInterface, @@ -69,7 +70,7 @@ public function put(ServerRequest $request): ResponseInterface 'assembly_id' => $assemblyId, 'issue_id' => $issueId, 'vote_id' => $voteId, - 'category' => 'A' + 'kind' => KindEnum::A->value ]); if ($form->isValid()) { @@ -94,7 +95,7 @@ public function patch(ServerRequest $request): ResponseInterface if (($vote = $this->voteService->get($voteId)) != null) { $form = new Form\Vote([ - ...(new \Althingi\Hydrator\Vote())->extract($vote), + ...$vote->toArray(), ...$request->getParsedBody(), 'assembly_id' => $assemblyId, 'issue_id' => $issueId, diff --git a/src/Controller/VoteItemController.php b/src/Controller/VoteItemController.php index 2eac0459..a79a6df0 100644 --- a/src/Controller/VoteItemController.php +++ b/src/Controller/VoteItemController.php @@ -17,6 +17,7 @@ ServiceVoteAwareInterface, ServiceVoteItemAwareInterface }; +use Althingi\Model\KindEnum; use Althingi\Service\{ Constituency, Congressman, @@ -88,7 +89,7 @@ public function post(ServerRequest $request): ResponseInterface 'issue_id' => $voteObject->getIssueId(), 'vote_id' => $voteObject->getVoteId(), 'vote_item_id' => $voteObject->getVoteItemId(), - 'category' => 'a' + 'kind' => KindEnum::A->value ], ['name' => 'loggjafarthing/thingmal/atkvaedagreidslur/atkvaedagreidsla']) ]); } else { @@ -143,7 +144,7 @@ public function patch(ServerRequest $request): ResponseInterface if (($voteItem = $this->voteItemService->get($voteItemId)) !== null) { $form = new Form\VoteItem([ - ...(new \Althingi\Hydrator\VoteItem())->extract($voteItem), + ...$voteItem->toArray(), ...$request->getParsedBody(), ]); diff --git a/src/Filter/ToNoNullInt.php b/src/Filter/ToNoNullInt.php new file mode 100644 index 00000000..0c96c7f3 --- /dev/null +++ b/src/Filter/ToNoNullInt.php @@ -0,0 +1,21 @@ +attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , - (new Input('category')) + (new Input('kind')) ->attachValidator(new NotEmpty()) + ->attachValidator(new IssueKind()) , (new Input('committee_id')) ->attachValidator(new NotEmpty()) diff --git a/src/Form/CommitteeMeetingAgenda.php b/src/Form/CommitteeMeetingAgenda.php index 6f18f8c7..2cf8370b 100644 --- a/src/Form/CommitteeMeetingAgenda.php +++ b/src/Form/CommitteeMeetingAgenda.php @@ -5,6 +5,7 @@ use Althingi\Hydrator; use Althingi\Model; use Althingi\Filter\ToInt; +use Althingi\Validator\IssueKind; use Laminas\Filter\ToNull; use Althingi\Validator\SignedDigits; use Laminas\Validator\NotEmpty; @@ -40,8 +41,9 @@ public function getValidationConfig(): array ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , - (new Input('category', true)) + (new Input('kind', true)) ->attachFilter(new ToNull(['type' => 'all'])) + ->attachValidator(new IssueKind()) , (new Input('issue_id', true)) ->attachValidator(new SignedDigits()) diff --git a/src/Form/CongressmanDocument.php b/src/Form/CongressmanDocument.php index e4abbbd4..b79b5d78 100644 --- a/src/Form/CongressmanDocument.php +++ b/src/Form/CongressmanDocument.php @@ -5,6 +5,7 @@ use Althingi\Filter\ToInt; use Althingi\Hydrator; use Althingi\Model; +use Althingi\Validator\IssueKind; use Althingi\Validator\SignedDigits; use Laminas\Filter\ToNull; use Laminas\Validator\NotEmpty; @@ -25,16 +26,20 @@ public function getModel(): Model\CongressmanDocument public function getValidationConfig(): array { return [ - (new Input('issue_id')) + (new Input('assembly_id')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , - (new Input('assembly_id')) + (new Input('issue_id')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , + (new Input('kind')) + ->attachValidator(new NotEmpty()) + ->attachValidator(new IssueKind()) + , (new Input('document_id')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) @@ -45,9 +50,6 @@ public function getValidationConfig(): array ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , - (new Input('category')) - ->attachValidator(new NotEmpty()) - , (new Input('order')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) diff --git a/src/Form/Document.php b/src/Form/Document.php index 95a640ee..369281ad 100644 --- a/src/Form/Document.php +++ b/src/Form/Document.php @@ -5,6 +5,7 @@ use Althingi\Filter\ToInt; use Althingi\Hydrator; use Althingi\Model; +use Althingi\Validator\IssueKind; use Althingi\Validator\SignedDigits; use Laminas\Filter\ToNull; use Laminas\Validator\Date; @@ -26,7 +27,7 @@ public function getModel(): Model\Document public function getValidationConfig(): array { return [ - (new Input('issue_id')) + (new Input('document_id')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) @@ -36,11 +37,15 @@ public function getValidationConfig(): array ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , - (new Input('document_id')) + (new Input('issue_id')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , + (new Input('kind')) + ->attachValidator(new NotEmpty()) + ->attachValidator(new IssueKind()) + , (new Input('committee_id', true)) ->attachFilter(new ToInt()) ->attachFilter(new ToNull(['type' => 'all'])) @@ -57,9 +62,6 @@ public function getValidationConfig(): array ->attachValidator(new NotEmpty()) ->attachFilter(new ToNull(['type' => 'all'])) , - (new Input('category')) - ->attachValidator(new NotEmpty()) - , (new Input('note', true)) ->attachFilter(new ToNull(['type' => 'all'])) , diff --git a/src/Form/Issue.php b/src/Form/Issue.php index c612ce15..60f04dfa 100644 --- a/src/Form/Issue.php +++ b/src/Form/Issue.php @@ -6,6 +6,7 @@ use Althingi\Model; use Althingi\Filter\ToInt; use Althingi\Filter\ItemStatusFilter; +use Althingi\Validator\IssueKind; use Laminas\Filter\ToNull; use Althingi\Validator\SignedDigits; use Laminas\Validator\NotEmpty; @@ -26,16 +27,20 @@ public function getModel(): Model\Issue public function getValidationConfig(): array { return [ - (new Input('issue_id')) + (new Input('assembly_id')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , - (new Input('assembly_id')) + (new Input('issue_id')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , + (new Input('kind')) + ->attachValidator(new NotEmpty()) + ->attachValidator(new IssueKind()) + , (new Input('congressman_id', true)) ->attachFilter(new ToInt()) ->attachFilter(new ToNull(['type' => 'all'])) @@ -46,9 +51,6 @@ public function getValidationConfig(): array (new Input('sub_name')) ->attachFilter(new ToNull(['type' => 'all'])) , - (new Input('category')) - ->attachValidator(new NotEmpty()) - , (new Input('type')) ->attachValidator(new NotEmpty()) , diff --git a/src/Form/IssueCategory.php b/src/Form/IssueCategory.php index f0e91172..8e69dc65 100644 --- a/src/Form/IssueCategory.php +++ b/src/Form/IssueCategory.php @@ -5,6 +5,7 @@ use Althingi\Filter\ToInt; use Althingi\Hydrator; use Althingi\Model; +use Althingi\Validator\IssueKind; use Althingi\Validator\SignedDigits; use Laminas\Validator\NotEmpty; use Library\Form\Form; @@ -24,7 +25,7 @@ public function getModel(): Model\IssueCategory public function getValidationConfig(): array { return [ - (new Input('issue_id')) + (new Input('category_id')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) @@ -34,13 +35,14 @@ public function getValidationConfig(): array ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , - (new Input('category_id')) + (new Input('issue_id')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , - (new Input('category')) + (new Input('kind')) ->attachValidator(new NotEmpty()) + ->attachValidator(new IssueKind()) , ]; } diff --git a/src/Form/IssueLink.php b/src/Form/IssueLink.php index cc779f42..5e82f61a 100644 --- a/src/Form/IssueLink.php +++ b/src/Form/IssueLink.php @@ -5,6 +5,7 @@ use Althingi\Filter\ToInt; use Althingi\Hydrator; use Althingi\Model; +use Althingi\Validator\IssueKind; use Althingi\Validator\SignedDigits; use Laminas\Filter\ToNull; use Laminas\Validator\NotEmpty; @@ -48,8 +49,9 @@ public function getValidationConfig(): array ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , - (new Input('category')) + (new Input('kind')) ->attachValidator(new NotEmpty()) + ->attachValidator(new IssueKind()) , (new Input('type', true)) ->attachFilter(new ToNull(['type' => 'all'])) diff --git a/src/Form/PlenaryAgenda.php b/src/Form/PlenaryAgenda.php index 5eb737ce..a1d6cfd3 100644 --- a/src/Form/PlenaryAgenda.php +++ b/src/Form/PlenaryAgenda.php @@ -5,6 +5,7 @@ use Althingi\Filter\ToInt; use Althingi\Hydrator; use Althingi\Model; +use Althingi\Validator\IssueKind; use Althingi\Validator\SignedDigits; use Laminas\Filter\ToNull; use Laminas\Validator\NotEmpty; @@ -35,11 +36,20 @@ public function getValidationConfig(): array ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , + (new Input('assembly_id')) + ->attachValidator(new NotEmpty()) + ->attachValidator(new SignedDigits()) + ->attachFilter(new ToInt()) + , (new Input('issue_id')) ->attachValidator(new NotEmpty()) ->attachValidator(new SignedDigits()) ->attachFilter(new ToInt()) , + (new Input('kind')) + ->attachValidator(new NotEmpty()) + ->attachValidator(new IssueKind()) + , (new Input('issue_name', true)) ->attachFilter(new ToNull(['type' => 'all'])) , @@ -49,14 +59,6 @@ public function getValidationConfig(): array (new Input('issue_typename', true)) ->attachFilter(new ToNull(['type' => 'all'])) , - (new Input('assembly_id')) - ->attachValidator(new NotEmpty()) - ->attachValidator(new SignedDigits()) - ->attachFilter(new ToInt()) - , - (new Input('category')) - ->attachValidator(new NotEmpty()) - , (new Input('iteration_type', true)) ->attachFilter(new ToNull(['type' => 'all'])) , diff --git a/src/Form/Speech.php b/src/Form/Speech.php index e1267755..6144bbe1 100644 --- a/src/Form/Speech.php +++ b/src/Form/Speech.php @@ -5,6 +5,7 @@ use Althingi\Filter\ToInt; use Althingi\Hydrator; use Althingi\Model; +use Althingi\Validator\IssueKind; use Althingi\Validator\SignedDigits; use Laminas\Filter\{Boolean, ToNull}; use Laminas\Validator\{Date, NotEmpty}; @@ -50,8 +51,9 @@ public function getValidationConfig(): array ->attachValidator(new SignedDigits()) ->attachValidator(new NotEmpty()) , - (new Input('category', true)) + (new Input('kind', true)) ->attachFilter(new ToNull(['type' => 'all'])) + ->attachValidator(new IssueKind()) , (new Input('congressman_id')) ->attachFilter(new ToInt()) diff --git a/src/Form/Vote.php b/src/Form/Vote.php index 530dc684..62a5fa53 100644 --- a/src/Form/Vote.php +++ b/src/Form/Vote.php @@ -3,8 +3,10 @@ namespace Althingi\Form; use Althingi\Filter\ToInt; +use Althingi\Filter\ToNoNullInt; use Althingi\Hydrator; use Althingi\Model; +use Althingi\Validator\IssueKind; use Althingi\Validator\SignedDigits; use Laminas\Filter\ToNull; use Laminas\Validator\{Date, NotEmpty}; @@ -25,28 +27,29 @@ public function getModel(): Model\Vote public function getValidationConfig(): array { return [ - (new Input('issue_id')) + (new Input('vote_id')) ->attachFilter(new ToInt()) ->attachValidator(new SignedDigits()) ->attachValidator(new NotEmpty()) , + (new Input('document_id', true)) + ->attachFilter(new ToInt()) + ->attachFilter(new ToNull(['type' => 'all'])) + , (new Input('assembly_id')) ->attachFilter(new ToInt()) ->attachValidator(new SignedDigits()) ->attachValidator(new NotEmpty()) , - (new Input('category')) - ->attachValidator(new NotEmpty()) - , - (new Input('document_id', true)) - ->attachFilter(new ToInt()) - ->attachFilter(new ToNull(['type' => 'all'])) - , - (new Input('vote_id')) + (new Input('issue_id')) ->attachFilter(new ToInt()) ->attachValidator(new SignedDigits()) ->attachValidator(new NotEmpty()) , + (new Input('kind')) + ->attachValidator(new NotEmpty()) + ->attachValidator(new IssueKind()) + , (new Input('date')) ->attachValidator(new NotEmpty()) ->attachValidator(new Date(['step' => 'any', 'format' => 'Y-m-d H:i:s'])) @@ -61,16 +64,13 @@ public function getValidationConfig(): array ->attachFilter(new ToNull(['type' => 'all'])) , (new Input('yes', true)) - ->attachFilter(new ToNull(['type' => 'all'])) - ->attachFilter(new ToInt()) + ->attachFilter(new ToNoNullInt()) , (new Input('no', true)) - ->attachFilter(new ToNull(['type' => 'all'])) - ->attachFilter(new ToInt()) + ->attachFilter(new ToNoNullInt()) , (new Input('inaction', true)) - ->attachFilter(new ToNull(['type' => 'all'])) - ->attachFilter(new ToInt()) + ->attachFilter(new ToNoNullInt()) , (new Input('committee_to', true)) ->attachFilter(new ToNull(['type' => 'all'])) diff --git a/src/Hydrator/CommitteeDocument.php b/src/Hydrator/CommitteeDocument.php index bd268e10..c6f24c8c 100644 --- a/src/Hydrator/CommitteeDocument.php +++ b/src/Hydrator/CommitteeDocument.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class CommitteeDocument implements HydratorInterface @@ -22,7 +23,7 @@ public function hydrate(array $data, $object) ->setDocumentId($data['document_id']) ->setAssemblyId($data['assembly_id']) ->setIssueId($data['issue_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setCommitteeId($data['committee_id']) ->setPart($data['part']) ->setName($data['name']); diff --git a/src/Hydrator/CommitteeMeetingAgenda.php b/src/Hydrator/CommitteeMeetingAgenda.php index df482d5c..982b128c 100644 --- a/src/Hydrator/CommitteeMeetingAgenda.php +++ b/src/Hydrator/CommitteeMeetingAgenda.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class CommitteeMeetingAgenda implements HydratorInterface @@ -18,7 +19,7 @@ public function hydrate(array $data, $object) return $object ->setCommitteeMeetingAgendaId($data['committee_meeting_agenda_id']) ->setCommitteeMeetingId($data['committee_meeting_id']) - ->setCategory(empty($data['category']) ? null : $data['category']) + ->setKind($data['kind'] ? KindEnum::fromString($data['kind']) : null) ->setIssueId(isset($data['issue_id']) ? $data['issue_id'] : null) ->setAssemblyId($data['assembly_id']) ->setTitle(isset($data['title']) ? $data['title'] : null); diff --git a/src/Hydrator/CongressmanDocument.php b/src/Hydrator/CongressmanDocument.php index 683d4035..ec355c8a 100644 --- a/src/Hydrator/CongressmanDocument.php +++ b/src/Hydrator/CongressmanDocument.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class CongressmanDocument implements HydratorInterface @@ -18,7 +19,7 @@ public function hydrate(array $data, $object) return $object ->setDocumentId($data['document_id']) ->setIssueId($data['issue_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setAssemblyId($data['assembly_id']) ->setCongressmanId($data['congressman_id']) ->setMinister(isset($data['minister']) ? $data['minister'] : null) diff --git a/src/Hydrator/Document.php b/src/Hydrator/Document.php index 8252ad21..5f455967 100644 --- a/src/Hydrator/Document.php +++ b/src/Hydrator/Document.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class Document implements HydratorInterface @@ -20,7 +21,7 @@ public function hydrate(array $data, $object) return $object ->setDocumentId($data['document_id']) ->setIssueId($data['issue_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setAssemblyId($data['assembly_id']) ->setDate(array_key_exists('date', $data) ? $this->hydrateDate($data['date']) : null) ->setUrl($data['url']) diff --git a/src/Hydrator/Issue.php b/src/Hydrator/Issue.php index 8176e6be..a16ee0ff 100644 --- a/src/Hydrator/Issue.php +++ b/src/Hydrator/Issue.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class Issue implements HydratorInterface @@ -19,7 +20,7 @@ public function hydrate(array $data, $object) ->setIssueId($data['issue_id']) ->setAssemblyId($data['assembly_id']) ->setCongressmanId($data['congressman_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setName($data['name']) ->setSubName($data['sub_name']) ->setType($data['type']) diff --git a/src/Hydrator/IssueAndDate.php b/src/Hydrator/IssueAndDate.php index 50372851..28956ac5 100644 --- a/src/Hydrator/IssueAndDate.php +++ b/src/Hydrator/IssueAndDate.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; use DateTime; @@ -20,7 +21,7 @@ public function hydrate(array $data, $object) ->setIssueId($data['issue_id']) ->setAssemblyId($data['assembly_id']) ->setCongressmanId($data['congressman_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setName($data['name']) ->setSubName($data['sub_name']) ->setType($data['type']) diff --git a/src/Hydrator/IssueCategory.php b/src/Hydrator/IssueCategory.php index b0f3624a..6cc6d8be 100644 --- a/src/Hydrator/IssueCategory.php +++ b/src/Hydrator/IssueCategory.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class IssueCategory implements HydratorInterface @@ -17,7 +18,7 @@ public function hydrate(array $data, $object) { return $object ->setCategoryId($data['category_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setIssueId($data['issue_id']) ->setAssemblyId($data['assembly_id']); } diff --git a/src/Hydrator/IssueLink.php b/src/Hydrator/IssueLink.php index b40c2e40..6e388e7a 100644 --- a/src/Hydrator/IssueLink.php +++ b/src/Hydrator/IssueLink.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class IssueLink implements HydratorInterface @@ -18,10 +19,10 @@ public function hydrate(array $data, $object) return $object ->setIssueId($data['issue_id']) ->setAssemblyId($data['assembly_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setFromAssemblyId($data['from_assembly_id']) ->setFromIssueId($data['from_issue_id']) - ->setFromCategory($data['from_category']) + ->setFromKind(KindEnum::fromString($data['from_category'])) ->setType($data['type']) ; } diff --git a/src/Hydrator/IssueValue.php b/src/Hydrator/IssueValue.php index d7c6691d..584aa028 100644 --- a/src/Hydrator/IssueValue.php +++ b/src/Hydrator/IssueValue.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class IssueValue implements HydratorInterface @@ -19,7 +20,7 @@ public function hydrate(array $data, $object) ->setIssueId($data['issue_id']) ->setAssemblyId($data['assembly_id']) ->setCongressmanId($data['congressman_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setName($data['name']) ->setSubName($data['sub_name']) ->setType($data['type']) diff --git a/src/Hydrator/Link.php b/src/Hydrator/Link.php index a5aa0372..96a09a52 100644 --- a/src/Hydrator/Link.php +++ b/src/Hydrator/Link.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class Link implements HydratorInterface @@ -18,7 +19,7 @@ public function hydrate(array $data, $object) return $object ->setIssueId($data['issue_id']) ->setAssemblyId($data['assembly_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setType(array_key_exists('type', $data) ? $data['type'] : 'related') ; } diff --git a/src/Hydrator/PlenaryAgenda.php b/src/Hydrator/PlenaryAgenda.php index e36f19bc..04f64f58 100644 --- a/src/Hydrator/PlenaryAgenda.php +++ b/src/Hydrator/PlenaryAgenda.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class PlenaryAgenda implements HydratorInterface @@ -20,7 +21,7 @@ public function hydrate(array $data, $object) ->setPlenaryId($data['plenary_id']) ->setIssueId($data['issue_id']) ->setAssemblyId($data['assembly_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setIterationType($data['iteration_type']) ->setIterationContinue($data['iteration_continue']) ->setIterationComment($data['iteration_comment']) diff --git a/src/Hydrator/Speech.php b/src/Hydrator/Speech.php index 25620803..1bd44ab6 100644 --- a/src/Hydrator/Speech.php +++ b/src/Hydrator/Speech.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class Speech implements HydratorInterface @@ -19,7 +20,7 @@ public function hydrate(array $data, $object) { return $object ->setSpeechId($data['speech_id']) - ->setCategory(empty($data['category']) ? null : $data['category']) + ->setKind($data['kind'] ? KindEnum::fromString($data['kind']) : null) ->setPlenaryId($data['plenary_id']) ->setAssemblyId($data['assembly_id']) ->setIssueId($data['issue_id']) diff --git a/src/Hydrator/Vote.php b/src/Hydrator/Vote.php index 4f2ae239..5d7f0438 100644 --- a/src/Hydrator/Vote.php +++ b/src/Hydrator/Vote.php @@ -2,6 +2,7 @@ namespace Althingi\Hydrator; +use Althingi\Model\KindEnum; use Laminas\Hydrator\HydratorInterface; class Vote implements HydratorInterface @@ -20,7 +21,7 @@ public function hydrate(array $data, $object) return $object ->setVoteId($data['vote_id']) ->setIssueId($data['issue_id']) - ->setCategory($data['category']) + ->setKind(KindEnum::fromString($data['kind'])) ->setAssemblyId($data['assembly_id']) ->setDocumentId(isset($data['document_id']) ? $data['document_id'] : null) ->setDate(array_key_exists('date', $data) ? $this->hydrateDate($data['date']) : null) diff --git a/src/Model/CommitteeDocument.php b/src/Model/CommitteeDocument.php index 0e224f36..fa22dc8b 100644 --- a/src/Model/CommitteeDocument.php +++ b/src/Model/CommitteeDocument.php @@ -8,7 +8,7 @@ class CommitteeDocument implements ModelInterface private int $document_id; private int $assembly_id; private int $issue_id; - private string $category; + private KindEnum $kind; private int $committee_id; private ?string $part = null; private ?string $name = null; @@ -18,7 +18,7 @@ public function getDocumentCommitteeId(): ?int return $this->document_committee_id; } - public function setDocumentCommitteeId(?int $document_committee_id): self + public function setDocumentCommitteeId(?int $document_committee_id): static { $this->document_committee_id = $document_committee_id; return $this; @@ -29,7 +29,7 @@ public function getDocumentId(): int return $this->document_id; } - public function setDocumentId(int $document_id): self + public function setDocumentId(int $document_id): static { $this->document_id = $document_id; return $this; @@ -40,7 +40,7 @@ public function getAssemblyId(): int return $this->assembly_id; } - public function setAssemblyId(int $assembly_id): self + public function setAssemblyId(int $assembly_id): static { $this->assembly_id = $assembly_id; return $this; @@ -51,20 +51,21 @@ public function getIssueId(): int return $this->issue_id; } - public function setIssueId(int $issue_id): self + public function setIssueId(int $issue_id): static { $this->issue_id = $issue_id; return $this; } - public function getCategory(): string + public function getKind(): KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(string $category): self + public function setKind(KindEnum $kind): static { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -73,7 +74,7 @@ public function getCommitteeId(): int return $this->committee_id; } - public function setCommitteeId(int $committee_id): self + public function setCommitteeId(int $committee_id): static { $this->committee_id = $committee_id; return $this; @@ -84,7 +85,7 @@ public function getPart(): ?string return $this->part; } - public function setPart(?string $part): self + public function setPart(?string $part): static { $this->part = $part; return $this; @@ -95,7 +96,7 @@ public function getName(): ?string return $this->name; } - public function setName(?string $name): self + public function setName(?string $name): static { $this->name = $name; return $this; @@ -113,7 +114,7 @@ public function toArray(): array 'document_id' => $this->document_id, 'assembly_id' => $this->assembly_id, 'issue_id' => $this->issue_id, - 'category' => $this->category, + 'kind' => $this->kind->value, 'committee_id' => $this->committee_id, 'part' => $this->part, 'name' => $this->name, diff --git a/src/Model/CommitteeMeetingAgenda.php b/src/Model/CommitteeMeetingAgenda.php index 1f151550..efbb24d5 100644 --- a/src/Model/CommitteeMeetingAgenda.php +++ b/src/Model/CommitteeMeetingAgenda.php @@ -7,9 +7,9 @@ class CommitteeMeetingAgenda implements ModelInterface private $committee_meeting_agenda_id; private $committee_meeting_id; private ?int $issue_id = null; - private $assembly_id; + private int $assembly_id; private ?string $title = null; - private ?string $category; + private ?KindEnum $kind; public function getCommitteeMeetingAgendaId(): int { @@ -66,14 +66,15 @@ public function setTitle(?string $title): self return $this; } - public function getCategory(): ?string + public function getKind(): ?KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(?string $category) + public function setKind(?KindEnum $kind): self { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -83,7 +84,7 @@ public function toArray(): array 'committee_meeting_agenda_id' => $this->committee_meeting_agenda_id, 'committee_meeting_id' => $this->committee_meeting_id, 'issue_id' => $this->issue_id, - 'category' => $this->category, + 'kind' => $this->kind?->value ?? null, 'assembly_id' => $this->assembly_id, 'title' => $this->title, ]; diff --git a/src/Model/CongressmanDocument.php b/src/Model/CongressmanDocument.php index 2887639a..d827f50b 100644 --- a/src/Model/CongressmanDocument.php +++ b/src/Model/CongressmanDocument.php @@ -6,7 +6,7 @@ class CongressmanDocument implements ModelInterface { private int $document_id; private int $issue_id; - private string $category; + private KindEnum $kind; private int $assembly_id; private int $congressman_id; private ?string $minister = null; @@ -17,7 +17,7 @@ public function getDocumentId(): int return $this->document_id; } - public function setDocumentId(int $document_id): self + public function setDocumentId(int $document_id): static { $this->document_id = $document_id; return $this; @@ -28,20 +28,21 @@ public function getIssueId(): int return $this->issue_id; } - public function setIssueId(int $issue_id): self + public function setIssueId(int $issue_id): static { $this->issue_id = $issue_id; return $this; } - public function getCategory(): string + public function getKind(): KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(string $category) + public function setKind(KindEnum $kind): static { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -50,7 +51,7 @@ public function getAssemblyId(): int return $this->assembly_id; } - public function setAssemblyId(int $assembly_id): self + public function setAssemblyId(int $assembly_id): static { $this->assembly_id = $assembly_id; return $this; @@ -61,7 +62,7 @@ public function getCongressmanId(): int return $this->congressman_id; } - public function setCongressmanId(int $congressman_id): self + public function setCongressmanId(int $congressman_id): static { $this->congressman_id = $congressman_id; return $this; @@ -72,7 +73,7 @@ public function getMinister(): ?string return $this->minister; } - public function setMinister(?string $minister): self + public function setMinister(?string $minister): static { $this->minister = $minister; return $this; @@ -83,7 +84,7 @@ public function getOrder(): int return $this->order; } - public function setOrder(int $order): self + public function setOrder(int $order): static { $this->order = $order; return $this; @@ -94,7 +95,7 @@ public function toArray(): array return [ 'document_id' => $this->document_id, 'issue_id' => $this->issue_id, - 'category' => $this->category, + 'kind' => $this->kind->value, 'assembly_id' => $this->assembly_id, 'congressman_id' => $this->congressman_id, 'minister' => $this->minister, diff --git a/src/Model/Document.php b/src/Model/Document.php index 189bed3d..634744f6 100644 --- a/src/Model/Document.php +++ b/src/Model/Document.php @@ -12,14 +12,14 @@ class Document implements ModelInterface private DateTime $date; private ?string $url = null; private string $type; - private string $category; + private KindEnum $kind; public function getDocumentId(): int { return $this->document_id; } - public function setDocumentId(int $document_id): self + public function setDocumentId(int $document_id): static { $this->document_id = $document_id; return $this; @@ -30,7 +30,7 @@ public function getIssueId(): int return $this->issue_id; } - public function setIssueId(int $issue_id): self + public function setIssueId(int $issue_id): static { $this->issue_id = $issue_id; return $this; @@ -41,7 +41,7 @@ public function getAssemblyId(): int return $this->assembly_id; } - public function setAssemblyId(int $assembly_id): self + public function setAssemblyId(int $assembly_id): static { $this->assembly_id = $assembly_id; return $this; @@ -52,7 +52,7 @@ public function getDate(): DateTime return $this->date; } - public function setDate(DateTime $date): self + public function setDate(DateTime $date): static { $this->date = $date; return $this; @@ -63,7 +63,7 @@ public function getUrl(): ?string return $this->url; } - public function setUrl(?string $url): self + public function setUrl(?string $url): static { $this->url = $url; return $this; @@ -74,20 +74,21 @@ public function getType(): string return $this->type; } - public function setType(string $type): self + public function setType(string $type): static { $this->type = $type; return $this; } - public function getCategory(): string + public function getKind(): KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(string $category) + public function setKind(KindEnum $kind): static { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -96,7 +97,7 @@ public function toArray(): array return [ 'document_id' => $this->document_id, 'issue_id' => $this->issue_id, - 'category' => $this->category, + 'kind' => $this->kind->value, 'assembly_id' => $this->assembly_id, 'date' => $this->date?->format('Y-m-d H:i:s'), 'url' => $this->url, diff --git a/src/Model/Issue.php b/src/Model/Issue.php index f5fd208b..473d1f7a 100644 --- a/src/Model/Issue.php +++ b/src/Model/Issue.php @@ -7,7 +7,7 @@ class Issue implements ModelInterface private $issue_id; private $assembly_id; private ?int $congressman_id = null; - private $category; + private KindEnum $kind = KindEnum::A; private ?string $name = null; private ?string $sub_name = null; private ?string $type = null; @@ -27,7 +27,7 @@ public function getIssueId(): int return $this->issue_id; } - public function setIssueId(int $issue_id): self + public function setIssueId(int $issue_id): static { $this->issue_id = $issue_id; return $this; @@ -38,7 +38,7 @@ public function getAssemblyId(): int return $this->assembly_id; } - public function setAssemblyId(int $assembly_id): self + public function setAssemblyId(int $assembly_id): static { $this->assembly_id = $assembly_id; return $this; @@ -49,20 +49,21 @@ public function getCongressmanId(): ?int return $this->congressman_id; } - public function setCongressmanId(?int $congressman_id): self + public function setCongressmanId(?int $congressman_id): static { $this->congressman_id = $congressman_id; return $this; } - public function getCategory(): string + public function getKind(): KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(string $category): self + public function setKind(KindEnum $kind): static { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -71,7 +72,7 @@ public function getName(): ?string return $this->name; } - public function setName(?string $name): self + public function setName(?string $name): static { $this->name = $name; return $this; @@ -82,7 +83,7 @@ public function getSubName(): ?string return $this->sub_name; } - public function setSubName(?string $sub_name): self + public function setSubName(?string $sub_name): static { $this->sub_name = $sub_name; return $this; @@ -93,7 +94,7 @@ public function getType(): ?string return $this->type; } - public function setType(?string $type): self + public function setType(?string $type): static { $this->type = $type; return $this; @@ -104,7 +105,7 @@ public function getTypeName(): ?string return $this->type_name; } - public function setTypeName(?string $type_name): self + public function setTypeName(?string $type_name): static { $this->type_name = $type_name; return $this; @@ -115,7 +116,7 @@ public function getTypeSubname(): ?string return $this->type_subname; } - public function setTypeSubname(?string $type_subname): self + public function setTypeSubname(?string $type_subname): static { $this->type_subname = $type_subname; return $this; @@ -126,7 +127,7 @@ public function getStatus(): ?string return $this->status; } - public function setStatus(?string $status): self + public function setStatus(?string $status): static { $this->status = $status; return $this; @@ -137,7 +138,7 @@ public function getQuestion(): ?string return $this->question; } - public function setQuestion(?string $question): self + public function setQuestion(?string $question): static { $this->question = $question; return $this; @@ -148,7 +149,7 @@ public function getGoal(): ?string return $this->goal; } - public function setGoal(?string $goal): self + public function setGoal(?string $goal): static { $this->goal = $goal; return $this; @@ -159,7 +160,7 @@ public function getMajorChanges(): ?string return $this->major_changes; } - public function setMajorChanges(?string $major_changes): self + public function setMajorChanges(?string $major_changes): static { $this->major_changes = $major_changes; return $this; @@ -170,7 +171,7 @@ public function getChangesInLaw(): ?string return $this->changes_in_law; } - public function setChangesInLaw(?string $changes_in_law): self + public function setChangesInLaw(?string $changes_in_law): static { $this->changes_in_law = $changes_in_law; return $this; @@ -181,7 +182,7 @@ public function getCostsAndRevenues(): ?string return $this->costs_and_revenues; } - public function setCostsAndRevenues(?string $costs_and_revenues): self + public function setCostsAndRevenues(?string $costs_and_revenues): static { $this->costs_and_revenues = $costs_and_revenues; return $this; @@ -192,7 +193,7 @@ public function getDeliveries(): ?string return $this->deliveries; } - public function setDeliveries(?string $deliveries): self + public function setDeliveries(?string $deliveries): static { $this->deliveries = $deliveries; return $this; @@ -203,7 +204,7 @@ public function getAdditionalInformation(): ?string return $this->additional_information; } - public function setAdditionalInformation(?string $additional_information): self + public function setAdditionalInformation(?string $additional_information): static { $this->additional_information = $additional_information; return $this; @@ -211,12 +212,12 @@ public function setAdditionalInformation(?string $additional_information): self public function isA() { - return $this->category === 'A'; + return $this->kind === KindEnum::A; } public function isB() { - return $this->category === 'B'; + return $this->kind === KindEnum::B; } public function toArray(): array @@ -225,7 +226,7 @@ public function toArray(): array 'issue_id' => $this->issue_id, 'assembly_id' => $this->assembly_id, 'congressman_id' => $this->congressman_id, - 'category' => $this->category, + 'kind' => $this->kind, 'name' => $this->name, 'sub_name' => $this->sub_name, 'type' => $this->type, diff --git a/src/Model/IssueCategory.php b/src/Model/IssueCategory.php index 397f0b30..5377c8fa 100644 --- a/src/Model/IssueCategory.php +++ b/src/Model/IssueCategory.php @@ -7,14 +7,14 @@ class IssueCategory implements ModelInterface private int $category_id; private int $issue_id; private int $assembly_id; - private string $category; + private KindEnum $kind; public function getCategoryId(): int { return $this->category_id; } - public function setCategoryId(int $category_id): self + public function setCategoryId(int $category_id): static { $this->category_id = $category_id; return $this; @@ -25,7 +25,7 @@ public function getIssueId(): int return $this->issue_id; } - public function setIssueId(int $issue_id): self + public function setIssueId(int $issue_id): static { $this->issue_id = $issue_id; return $this; @@ -36,20 +36,21 @@ public function getAssemblyId(): int return $this->assembly_id; } - public function setAssemblyId(int $assembly_id): self + public function setAssemblyId(int $assembly_id): static { $this->assembly_id = $assembly_id; return $this; } - public function getCategory(): string + public function getKind(): KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(string $category) + public function setKind(KindEnum $kind): static { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -59,7 +60,7 @@ public function toArray(): array 'category_id' => $this->category_id, 'issue_id' => $this->issue_id, 'assembly_id' => $this->assembly_id, - 'category' => $this->category, + 'kind' => $this->kind->value, ]; } diff --git a/src/Model/IssueLink.php b/src/Model/IssueLink.php index 1c9aa605..3df9b38d 100644 --- a/src/Model/IssueLink.php +++ b/src/Model/IssueLink.php @@ -6,10 +6,10 @@ class IssueLink implements ModelInterface { private $from_assembly_id; private $from_issue_id; - private $from_category; + private KindEnum $from_kind; private $assembly_id; private $issue_id; - private $category; + private KindEnum $kind; private ?string $type = null; public function getFromAssemblyId(): int @@ -17,7 +17,7 @@ public function getFromAssemblyId(): int return $this->from_assembly_id; } - public function setFromAssemblyId(int $from_assembly_id): self + public function setFromAssemblyId(int $from_assembly_id): static { $this->from_assembly_id = $from_assembly_id; return $this; @@ -28,20 +28,21 @@ public function getFromIssueId(): int return $this->from_issue_id; } - public function setFromIssueId(int $from_issue_id): self + public function setFromIssueId(int $from_issue_id): static { $this->from_issue_id = $from_issue_id; return $this; } - public function getFromCategory(): string + public function getFromKind(): KindEnum { - return $this->from_category; + return $this->from_kind; } - public function setFromCategory(string $from_category): self + public function setFromKind(KindEnum $from_kind): static { - $this->from_category = $from_category; + $this->from_kind = $from_kind; + return $this; } @@ -50,7 +51,7 @@ public function getAssemblyId(): int return $this->assembly_id; } - public function setAssemblyId(int $assembly_id): self + public function setAssemblyId(int $assembly_id): static { $this->assembly_id = $assembly_id; return $this; @@ -61,20 +62,21 @@ public function getIssueId(): int return $this->issue_id; } - public function setIssueId(int $issue_id): self + public function setIssueId(int $issue_id): static { $this->issue_id = $issue_id; return $this; } - public function getCategory(): string + public function getKind(): KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(string $category): self + public function setKind(KindEnum $kind): static { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -83,7 +85,7 @@ public function getType(): ?string return $this->type; } - public function setType(?string $type): self + public function setType(?string $type): static { $this->type = $type; return $this; @@ -94,10 +96,10 @@ public function toArray(): array return [ 'to_assembly_id' => $this->assembly_id, 'to_issue_id' => $this->issue_id, - 'to_category' => $this->category, + 'to_kind' => $this->kind->value, 'from_assembly_id' => $this->from_assembly_id, 'from_issue_id' => $this->from_issue_id, - 'from_category' => $this->from_category, + 'from_kind' => $this->from_kind->value, 'type' => $this->type, ]; } diff --git a/src/Model/KindEnum.php b/src/Model/KindEnum.php new file mode 100644 index 00000000..4402e31c --- /dev/null +++ b/src/Model/KindEnum.php @@ -0,0 +1,20 @@ + self::A, + 'b' => self::B, + default => throw new Exception("'$value' is not a valid string"), + }; + } +} diff --git a/src/Model/Link.php b/src/Model/Link.php index 178d3257..5b689fac 100644 --- a/src/Model/Link.php +++ b/src/Model/Link.php @@ -2,13 +2,11 @@ namespace Althingi\Model; -use DateTime; - class Link implements ModelInterface { private int $assembly_id; private int $issue_id; - private string $category; + private KindEnum $kind; private string $type; public function getAssemblyId(): int @@ -16,7 +14,7 @@ public function getAssemblyId(): int return $this->assembly_id; } - public function setAssemblyId(int $assembly_id): self + public function setAssemblyId(int $assembly_id): static { $this->assembly_id = $assembly_id; return $this; @@ -27,20 +25,21 @@ public function getIssueId(): int return $this->issue_id; } - public function setIssueId(int $issue_id): self + public function setIssueId(int $issue_id): static { $this->issue_id = $issue_id; return $this; } - public function getCategory(): string + public function getKind(): KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(string $category): self + public function setKind(KindEnum $kind): static { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -49,7 +48,7 @@ public function getType(): string return $this->type; } - public function setType(string $type): self + public function setType(string $type): static { $this->type = $type; return $this; @@ -60,7 +59,7 @@ public function toArray(): array return [ 'assembly_id' => $this->assembly_id, 'issue_id' => $this->issue_id, - 'category' => $this->category, + 'kind' => $this->kind->value, 'type' => $this->type, ]; } diff --git a/src/Model/PlenaryAgenda.php b/src/Model/PlenaryAgenda.php index b88866d4..867afd6f 100644 --- a/src/Model/PlenaryAgenda.php +++ b/src/Model/PlenaryAgenda.php @@ -7,7 +7,7 @@ class PlenaryAgenda implements ModelInterface private int $plenaryId; private int $issueId; private int $assemblyId; - private string $category; + private KindEnum $kind; private ?string $iterationType = null; private ?string $iterationContinue = null; private ?string $iterationComment = null; @@ -27,7 +27,7 @@ public function getItemId(): int return $this->itemId; } - public function setItemId(int $itemId): self + public function setItemId(int $itemId): static { $this->itemId = $itemId; return $this; @@ -38,7 +38,7 @@ public function getPlenaryId(): int return $this->plenaryId; } - public function setPlenaryId(int $plenaryId): self + public function setPlenaryId(int $plenaryId): static { $this->plenaryId = $plenaryId; return $this; @@ -49,7 +49,7 @@ public function getIssueId(): int return $this->issueId; } - public function setIssueId(int $issueId): self + public function setIssueId(int $issueId): static { $this->issueId = $issueId; return $this; @@ -60,20 +60,21 @@ public function getAssemblyId(): int return $this->assemblyId; } - public function setAssemblyId(int $assemblyId): self + public function setAssemblyId(int $assemblyId): static { $this->assemblyId = $assemblyId; return $this; } - public function getCategory(): string + public function getKind(): KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(string $category): self + public function setKind(KindEnum $kind): static { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -82,7 +83,7 @@ public function getIterationType(): ?string return $this->iterationType; } - public function setIterationType(?string $iterationType): self + public function setIterationType(?string $iterationType): static { $this->iterationType = $iterationType; return $this; @@ -93,7 +94,7 @@ public function getIterationContinue(): ?string return $this->iterationContinue; } - public function setIterationContinue(?string $iterationContinue): self + public function setIterationContinue(?string $iterationContinue): static { $this->iterationContinue = $iterationContinue; return $this; @@ -104,7 +105,7 @@ public function getIterationComment(): ?string return $this->iterationComment; } - public function setIterationComment(?string $iterationComment): self + public function setIterationComment(?string $iterationComment): static { $this->iterationComment = $iterationComment; return $this; @@ -115,7 +116,7 @@ public function getComment(): ?string return $this->comment; } - public function setComment(?string $comment): self + public function setComment(?string $comment): static { $this->comment = $comment; return $this; @@ -126,7 +127,7 @@ public function getCommentType(): ?string return $this->commentType; } - public function setCommentType(?string $commentType): self + public function setCommentType(?string $commentType): static { $this->commentType = $commentType; return $this; @@ -137,7 +138,7 @@ public function getPosedId(): ?int return $this->posedId; } - public function setPosedId(?int $posedId): self + public function setPosedId(?int $posedId): static { $this->posedId = $posedId; return $this; @@ -148,7 +149,7 @@ public function getPosed(): ?string return $this->posed; } - public function setPosed(?string $posed): self + public function setPosed(?string $posed): static { $this->posed = $posed; return $this; @@ -159,7 +160,7 @@ public function getAnswererId(): ?int return $this->answererId; } - public function setAnswererId(?int $answererId): self + public function setAnswererId(?int $answererId): static { $this->answererId = $answererId; return $this; @@ -170,7 +171,7 @@ public function getAnswerer(): ?string return $this->answerer; } - public function setAnswerer(?string $answerer): self + public function setAnswerer(?string $answerer): static { $this->answerer = $answerer; return $this; @@ -181,7 +182,7 @@ public function getCounterAnswererId(): ?int return $this->counterAnswererId; } - public function setCounterAnswererId(?int $counterAnswererId): self + public function setCounterAnswererId(?int $counterAnswererId): static { $this->counterAnswererId = $counterAnswererId; return $this; @@ -192,7 +193,7 @@ public function getCounterAnswerer(): ?string return $this->counterAnswerer; } - public function setCounterAnswerer(?string $counterAnswerer): self + public function setCounterAnswerer(?string $counterAnswerer): static { $this->counterAnswerer = $counterAnswerer; return $this; @@ -203,7 +204,7 @@ public function getInstigatorId(): ?int return $this->instigatorId; } - public function setInstigatorId(?int $instigatorId): self + public function setInstigatorId(?int $instigatorId): static { $this->instigatorId = $instigatorId; return $this; @@ -214,7 +215,7 @@ public function getInstigator(): ?string return $this->instigator; } - public function setInstigator(?string $instigator): self + public function setInstigator(?string $instigator): static { $this->instigator = $instigator; return $this; @@ -227,7 +228,7 @@ public function toArray(): array 'plenary_id' => $this->plenaryId, 'issue_id' => $this->issueId, 'assembly_id' => $this->assemblyId, - 'category' => $this->category, + 'kind' => $this->kind, 'iteration_type' => $this->iterationType, 'iteration_continue' => $this->iterationContinue, 'iteration_comment' => $this->iterationComment, diff --git a/src/Model/Speech.php b/src/Model/Speech.php index c081e854..301aaee6 100644 --- a/src/Model/Speech.php +++ b/src/Model/Speech.php @@ -10,7 +10,7 @@ class Speech implements ModelInterface private $plenary_id; private $assembly_id; private $issue_id; - private $category; + private ?KindEnum $kind; private $congressman_id; private ?string $congressman_type = null; private ?DateTime $from = null; @@ -65,14 +65,15 @@ public function setIssueId(int $issue_id): self return $this; } - public function getCategory(): ?string + public function getKind(): ?KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(?string $category): self + public function setKind(?KindEnum $kind): self { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -182,7 +183,7 @@ public function toArray(): array 'plenary_id' => $this->plenary_id, 'assembly_id' => $this->assembly_id, 'issue_id' => $this->issue_id, - 'category' => $this->category, + 'kind' => $this->kind->value, 'congressman_id' => $this->congressman_id, 'congressman_type' => $this->congressman_type, 'from' => $this->from?->format('Y-m-d H:i:s'), diff --git a/src/Model/Vote.php b/src/Model/Vote.php index cee49de7..69697424 100644 --- a/src/Model/Vote.php +++ b/src/Model/Vote.php @@ -8,7 +8,7 @@ class Vote implements ModelInterface { private $vote_id; private $issue_id; - private $category; + private KindEnum $kind; private $assembly_id; private ?int $document_id = null; private ?DateTime $date = null; @@ -25,7 +25,7 @@ public function getVoteId(): int return $this->vote_id; } - public function setVoteId(int $vote_id): self + public function setVoteId(int $vote_id): static { $this->vote_id = $vote_id; return $this; @@ -36,7 +36,7 @@ public function getIssueId(): int return $this->issue_id; } - public function setIssueId(int $issue_id): self + public function setIssueId(int $issue_id): static { $this->issue_id = $issue_id; return $this; @@ -47,7 +47,7 @@ public function getAssemblyId(): int return $this->assembly_id; } - public function setAssemblyId(int $assembly_id): self + public function setAssemblyId(int $assembly_id): static { $this->assembly_id = $assembly_id; return $this; @@ -58,7 +58,7 @@ public function getDocumentId(): ?int return $this->document_id; } - public function setDocumentId(?int $document_id): self + public function setDocumentId(?int $document_id): static { $this->document_id = $document_id; return $this; @@ -69,7 +69,7 @@ public function getDate(): ?DateTime return $this->date; } - public function setDate(?DateTime $date): self + public function setDate(?DateTime $date): static { $this->date = $date; return $this; @@ -80,7 +80,7 @@ public function getType(): ?string return $this->type; } - public function setType(?string $type): self + public function setType(?string $type): static { $this->type = $type; return $this; @@ -91,7 +91,7 @@ public function getOutcome(): ?string return $this->outcome; } - public function setOutcome(?string $outcome): self + public function setOutcome(?string $outcome): static { $this->outcome = $outcome; return $this; @@ -102,7 +102,7 @@ public function getMethod(): ?string return $this->method; } - public function setMethod(?string $method): self + public function setMethod(?string $method): static { $this->method = $method; return $this; @@ -113,7 +113,7 @@ public function getYes(): ?int return $this->yes; } - public function setYes(?int $yes): self + public function setYes(?int $yes): static { $this->yes = $yes; return $this; @@ -124,7 +124,7 @@ public function getNo(): ?int return $this->no; } - public function setNo(?int $no): self + public function setNo(?int $no): static { $this->no = $no; return $this; @@ -135,7 +135,7 @@ public function getInaction(): ?int return $this->inaction; } - public function setInaction(?int $inaction): self + public function setInaction(?int $inaction): static { $this->inaction = $inaction; return $this; @@ -146,20 +146,21 @@ public function getCommitteeTo(): ?string return $this->committee_to; } - public function setCommitteeTo(?string $committee_to): self + public function setCommitteeTo(?string $committee_to): static { $this->committee_to = $committee_to; return $this; } - public function getCategory(): string + public function getKind(): KindEnum { - return $this->category; + return $this->kind; } - public function setCategory(string $category): self + public function setKind(KindEnum $kind): static { - $this->category = $category; + $this->kind = $kind; + return $this; } @@ -168,7 +169,7 @@ public function toArray(): array return [ 'vote_id' => $this->vote_id, 'issue_id' => $this->issue_id, - 'category' => $this->category, + 'kind' => $this->kind->value, 'assembly_id' => $this->assembly_id, 'document_id' => $this->document_id, 'date' => $this->date?->format('Y-m-d H:m:s'), diff --git a/src/Service/Category.php b/src/Service/Category.php index ddce861d..ccd247b6 100644 --- a/src/Service/Category.php +++ b/src/Service/Category.php @@ -5,6 +5,7 @@ use Althingi\Model; use Althingi\Hydrator; use Althingi\Injector\DatabaseAwareInterface; +use Althingi\Model\KindEnum; use Generator; use PDO; @@ -58,7 +59,7 @@ public function fetchByAssembly(int $assemblyId): array { $statement = $this->getDriver()->prepare(' select count(*) as `count` , C.* from `Issue` I - join `Category_has_Issue` CI on (CI.`issue_id` = I.`issue_id` and CI.`category` = I.`category`) + join `Category_has_Issue` CI on (CI.`issue_id` = I.`issue_id` and CI.`kind` = I.`kind`) join `Category` C on (C.`category_id` = CI.`category_id` and CI.assembly_id = :assembly_id) where I.`assembly_id` = :assembly_id group by CI.`category_id` @@ -81,11 +82,12 @@ public function fetchByAssemblyAndIssue(int $assemblyId, int $issueId): array join `Category` C on (C.`category_id` = CI.`category_id`) where CI.`assembly_id` = :assembly_id and CI.`issue_id` = :issue_id - and CI.category = \'A\'; + and CI.kind = :kind; '); $statement->execute([ 'assembly_id' => $assemblyId, 'issue_id' => $issueId, + 'kind' => KindEnum::A->value ]); return array_map(function ($object) { return (new Hydrator\Category())->hydrate($object, new Model\Category()); @@ -100,12 +102,13 @@ public function fetchByAssemblyIssueAndCategory(int $assemblyId, int $issueId, i where CI.`assembly_id` = :assembly_id and CI.`issue_id` = :issue_id and CI.`category_id` = :category_id - and CI.category = \'A\'; + and CI.kind = :kind; '); $statement->execute([ 'assembly_id' => $assemblyId, 'issue_id' => $issueId, 'category_id' => $categoryId, + 'kind' => KindEnum::A->value ]); $object = $statement->fetch(PDO::FETCH_ASSOC); diff --git a/src/Service/CommitteeDocument.php b/src/Service/CommitteeDocument.php index d6dd7191..0fd40a5a 100644 --- a/src/Service/CommitteeDocument.php +++ b/src/Service/CommitteeDocument.php @@ -7,6 +7,7 @@ use Althingi\Model; use Althingi\Hydrator; use Althingi\Injector\{DatabaseAwareInterface, EventsAwareInterface}; +use Althingi\Model\KindEnum; use Althingi\Presenters\IndexableCommitteeDocumentPresenter; use Exception; use Generator; @@ -95,13 +96,13 @@ public function fetchByDocument(int $assemblyId, $issueId, $documentId): array select * from `Document_has_Committee` where assembly_id = :assembly_id and issue_id = :issue_id and - category = 'A' and + kind = :kind and document_id = :document_id "); $statement->execute([ 'assembly_id' => $assemblyId, 'issue_id' => $issueId, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'document_id' => $documentId, ]); @@ -149,7 +150,7 @@ public function getIdentifier( int $documentId, int $assemblyId, int $issueId, - string $category, + KindEnum $kind, int $committeeId, string $part ): int { @@ -158,7 +159,7 @@ public function getIdentifier( where `assembly_id` = :assembly_id and, `document_id` = :document_id and, `issue_id` = :issue_id and, - `category` = :category and, + `kind` = :kind and, `committee_id` = :committee_id and, `part` = :part ; @@ -167,7 +168,7 @@ public function getIdentifier( 'document_id' => $documentId, 'assembly_id' => $assemblyId, 'issue_id' => $issueId, - 'category' => $category, + 'kind' => $kind->value, 'committee_id' => $committeeId, 'part' => $part, ]); diff --git a/src/Service/Congressman.php b/src/Service/Congressman.php index c4e28248..abb158dd 100644 --- a/src/Service/Congressman.php +++ b/src/Service/Congressman.php @@ -7,6 +7,7 @@ use Althingi\Presenters\IndexableCongressmanPresenter; use Althingi\Injector\{EventsAwareInterface, DatabaseAwareInterface}; use Althingi\Events\{UpdateEvent, AddEvent}; +use Althingi\Model\KindEnum; use PDO; use DateTime; use Generator; @@ -127,16 +128,16 @@ public function fetchTimeByAssembly( int $assemblyId, ?int $size = null, ?string $order = 'desc', - ?array $category = ['A'] + ?array $kind = [KindEnum::A] ): array { $limit = $size ? "limit 0, {$size}" : ''; - $categories = count($category) > 0 - ? 'and S.category in (' . implode(', ', array_map(function ($c) { - return '"' . $c . '"'; - }, $category)) . ')' + $kinds = count($kind) > 0 + ? 'and S.kind in (' . implode(', ', array_map(function (KindEnum $item) { + return '"' . $item->value . '"'; + }, $kind)) . ')' : ''; $statement = $this->getDriver()->prepare( @@ -144,7 +145,7 @@ public function fetchTimeByAssembly( ( select (sum(time_to_sec(timediff(`to`, `from`)))) as `count` from `Speech` S - where S.`assembly_id` = :assembly_id and S.`congressman_id` = C.congressman_id {$categories} + where S.`assembly_id` = :assembly_id and S.`congressman_id` = C.congressman_id {$kinds} group by `congressman_id` ) as `value` from `Session` S @@ -189,7 +190,7 @@ public function fetchIssueTypeCountByAssembly( D.document_id = DhC.document_id and D.issue_id = DhC.issue_id and D.assembly_id = DhC.assembly_id and - D.category = DhC.category + D.kind = DhC.kind ) where D.assembly_id = :assembly_id group by D.issue_id @@ -198,7 +199,7 @@ public function fetchIssueTypeCountByAssembly( join Issue I on ( A.issue_id = I.issue_id and A.assembly_id = I.assembly_id and - A.category = I.category + A.kind = I.kind ) join Congressman C on (A.congressman_id = C.congressman_id) {$types} @@ -235,13 +236,13 @@ public function fetchByCabinet(int $cabinetId): array * @return \Althingi\Model\CongressmanAndDateRange[] * @deprecated */ - public function fetchAccumulatedTimeByIssue(int $assemblyId, int $issueId, ?string $category = 'A'): array + public function fetchAccumulatedTimeByIssue(int $assemblyId, int $issueId, ?KindEnum $kind = KindEnum::A): array { $statement = $this->getDriver()->prepare(" select C.*, (sum(`diff`)) as `time`, date(`from`) as `begin`, null as `end` from ( select *, timediff(`to`, `from`) as `diff` from `Speech` D - where D.assembly_id = :assembly_id and D.issue_id = :issue_id and D.category = :category + where D.assembly_id = :assembly_id and D.issue_id = :issue_id and D.kind = :kind ) S join `Congressman` C on (C.congressman_id = S.congressman_id) group by S.congressman_id @@ -250,7 +251,7 @@ public function fetchAccumulatedTimeByIssue(int $assemblyId, int $issueId, ?stri $statement->execute([ 'issue_id' => $issueId, 'assembly_id' => $assemblyId, - 'category' => $category + 'kind' => $kind->value ]); return array_map(function ($object) { @@ -295,7 +296,7 @@ public function fetchProponentsByIssue(int $assemblyId, int $issueId): array select D.`document_id` from `Document` D where D.`assembly_id` = :assembly_id and D.`issue_id` = :issue_id - and D.`category` = \'A\' + and D.`kind` = :kind order by `date` asc limit 0, 1 ) order by DC.`order`; @@ -303,7 +304,8 @@ public function fetchProponentsByIssue(int $assemblyId, int $issueId): array $statement->execute([ 'assembly_id' => $assemblyId, - 'issue_id' => $issueId + 'issue_id' => $issueId, + 'kind' => KindEnum::A->value ]); return array_map(function ($object) { diff --git a/src/Service/Constituency.php b/src/Service/Constituency.php index 0c49c185..afbeb4e5 100644 --- a/src/Service/Constituency.php +++ b/src/Service/Constituency.php @@ -141,7 +141,7 @@ public function fetchFrequencyByAssembly(int $assemblyId): array join Issue I on ( D.issue_id = I.issue_id and D.assembly_id = I.assembly_id and - D.category = I.category + D.kind = I.kind ) where D.assembly_id = :assembly_id and I.type = "l" group by D.issue_id diff --git a/src/Service/DatabaseService.php b/src/Service/DatabaseService.php index 72f4c029..a5e13f39 100644 --- a/src/Service/DatabaseService.php +++ b/src/Service/DatabaseService.php @@ -126,6 +126,9 @@ protected function toSqlValues(ModelInterface $data): array if ($i instanceof DateTime) { return $i->format('Y-m-d H:i:s'); } + if (is_object($i) && enum_exists($i::class)) { + return $i->value; + } if (is_bool($i)) { return (int) $i; } diff --git a/src/Service/Document.php b/src/Service/Document.php index 52a09906..eb1eba34 100644 --- a/src/Service/Document.php +++ b/src/Service/Document.php @@ -7,6 +7,7 @@ use Althingi\Events\{UpdateEvent, AddEvent}; use Althingi\Presenters\IndexableDocumentPresenter; use Althingi\Injector\{DatabaseAwareInterface, EventsAwareInterface}; +use Althingi\Model\KindEnum; use Exception; use Generator; use PDO; @@ -40,13 +41,14 @@ public function getPrimaryDocument(int $assemblyId, int $issueId) select * from `Document` where `assembly_id` = :assembly_id and `issue_id` = :issue_id and - `category` = 'A' + `kind` = :kind order by `date` limit 0, 1 "); $statement->execute([ 'assembly_id' => $assemblyId, 'issue_id' => $issueId, + 'kind' => KindEnum::A ]); $object = $statement->fetch(PDO::FETCH_ASSOC); diff --git a/src/Service/Issue.php b/src/Service/Issue.php index 9af63791..be7ca174 100644 --- a/src/Service/Issue.php +++ b/src/Service/Issue.php @@ -7,6 +7,7 @@ use Althingi\Events\{UpdateEvent, AddEvent}; use Althingi\Presenters\IndexableIssuePresenter; use Althingi\Injector\{EventsAwareInterface, DatabaseAwareInterface}; +use Althingi\Model\KindEnum; use Generator; use InvalidArgumentException; use PDO; @@ -27,18 +28,18 @@ class Issue implements DatabaseAwareInterface, EventsAwareInterface ]; const ALLOWED_ORDER = ['asc', 'desc']; - public function get(int $issue_id, int $assembly_id, $category = 'A'): ? Model\Issue + public function get(int $issue_id, int $assembly_id, $kind = KindEnum::A): ? Model\Issue { $issueStatement = $this->getDriver()->prepare(' select * from `Issue` I where I.`assembly_id` = :assembly_id and I.`issue_id` = :issue_id - and I.`category` = :category + and I.`kind` = :kind '); $issueStatement->execute([ 'assembly_id' => $assembly_id, 'issue_id' => $issue_id, - 'category' => $category + 'kind' => $kind->value ]); $object = $issueStatement->fetch(PDO::FETCH_ASSOC); @@ -53,12 +54,12 @@ public function get(int $issue_id, int $assembly_id, $category = 'A'): ? Model\I * * @return \Althingi\Model\Issue[] | void */ - public function fetchAll(array $category = ['A']) + public function fetchAll(array $kind = [KindEnum::A]) { $statement = $this->getDriver()->prepare( - 'select * from `Issue` I where I.category in (' . implode(', ', array_map(function ($c) { - return '"' . $c . '"'; - }, $category)) . ');' + 'select * from `Issue` I where I.kind in (' . implode(', ', array_map(function (KindEnum $item) { + return '"' . $item->value . '"'; + }, $kind)) . ');' ); $statement->execute(); @@ -90,20 +91,24 @@ public function fetchAllGenerator(?int $assemblyId = null): Generator /** * Get one Issue along with some metadata. */ - public function getWithDate(int $issue_id, int $assembly_id, $category = 'A'): ? Model\IssueAndDate + public function getWithDate(int $issue_id, int $assembly_id, $kind = KindEnum::A): ? Model\IssueAndDate { $issueStatement = $this->getDriver()->prepare( 'select *, (select D.`date` from `Document` D - where assembly_id = I.assembly_id and issue_id = I.issue_id and I.category = "A" + where assembly_id = I.assembly_id and issue_id = I.issue_id and I.kind = "A" order by date asc limit 0, 1) as `date` from `Issue` I where I.assembly_id = :assembly_id and I.issue_id = :issue_id - and I.category = :category' + and I.kind = :kind' ); - $issueStatement->execute(['issue_id' => $issue_id, 'assembly_id' => $assembly_id, 'category' => $category]); + $issueStatement->execute([ + 'issue_id' => $issue_id, + 'assembly_id' => $assembly_id, + 'kind' => $kind->value + ]); $object = $issueStatement->fetch(PDO::FETCH_ASSOC); @@ -134,12 +139,12 @@ public function fetchByAssembly( ?string $order = 'asc', array $type = [], array $categoryType = [], - array $category = ['A'] + array $kind = [KindEnum::A] ): array { $order = in_array($order, self::ALLOWED_ORDER) ? $order : 'asc'; $typeFilterString = $this->typeFilterString($type); $categoryFilterString = $this->categoryTypeFilterString($categoryType); - $categoryString = $this->categoryString($category); + $kindString = $this->categoryString($kind); $size = $size ? : 25; if (empty($categoryFilterString)) { @@ -149,13 +154,13 @@ public function fetchByAssembly( select D.`date` from `Document` D where `assembly_id` = I.`assembly_id` and `issue_id` = I.issue_id - and D.`category` = I.`category` + and D.`kind` = I.`kind` order by `date` asc limit 0, 1 ) as `date` from `Issue` I where I.`assembly_id` = :id {$typeFilterString} - {$categoryString} + {$kindString} order by I.`issue_id` {$order} limit {$offset}, {$size}; "); @@ -166,7 +171,7 @@ public function fetchByAssembly( select D.`date` from `Document` D where `assembly_id` = I.`assembly_id` and `issue_id` = I.issue_id - and D.`category` = I.category + and D.`kind` = I.kind order by `date` asc limit 0, 1 ) as `date` @@ -174,11 +179,11 @@ public function fetchByAssembly( left outer join `Category_has_Issue` CI on ( CI.`issue_id` = I.`issue_id` and CI.`assembly_id` = I.assembly_id - and (CI.`category` = I.category or CI.`category` is null) + and (CI.`kind` = I.kind or CI.`kind` is null) ) where I.assembly_id = :id {$typeFilterString} - {$categoryString} + {$kindString} {$categoryFilterString} order by I.issue_id {$order} limit {$offset}, {$size}; @@ -191,24 +196,24 @@ public function fetchByAssembly( }, $statement->fetchAll(PDO::FETCH_ASSOC)); } - public function countByAssembly(int $id, array $type = [], array $categoryTypes = [], ?array $category = ['A']): int + public function countByAssembly(int $id, array $type = [], array $categoryTypes = [], ?array $kind = [KindEnum::A]): int { $typeFilterString = $this->typeFilterString($type); $categoryFilterString = $this->categoryTypeFilterString($categoryTypes); - $categoryString = $this->categoryString($category); + $kindString = $this->categoryString($kind); if (empty($categoryFilterString)) { $statement = $this->getDriver()->prepare(" select count(*) from `Issue` I - where `assembly_id` = :id {$typeFilterString} {$categoryString} + where `assembly_id` = :id {$typeFilterString} {$kindString} "); } else { $statement = $this->getDriver()->prepare(" select count(*) from `Issue` I join `Category_has_Issue` CI on ( - CI.issue_id = I.issue_id and CI.assembly_id = :id {$categoryString} + CI.issue_id = I.issue_id and CI.assembly_id = :id {$kindString} ) - where I.assembly_id = :id {$typeFilterString} {$categoryFilterString} {$categoryString} + where I.assembly_id = :id {$typeFilterString} {$categoryFilterString} {$kindString} "); } @@ -224,11 +229,14 @@ public function fetchByCongressman(int $id): array $statement = $this->getDriver()->prepare(" select * from `Issue` I where I.`congressman_id` = :id - and I.category = 'A' + and I.kind = :kind order by I.`assembly_id` desc, I.`issue_id` asc; "); - $statement->execute(['id' => $id]); + $statement->execute([ + 'id' => $id, + 'kind' => KindEnum::A->value + ]); return array_map(function ($object) { return (new Hydrator\Issue())->hydrate($object, new Model\Issue()); }, $statement->fetchAll(PDO::FETCH_ASSOC)); @@ -243,7 +251,7 @@ public function fetchByAssemblyAndCongressman(int $assemblyId, int $congressmanI { $statement = $this->getDriver()->prepare(" select I.* from `Document_has_Congressman` D - join `Issue` I on (I.`issue_id` = D.`issue_id` and I.assembly_id = D.assembly_id and I.category = 'A') + join `Issue` I on (I.`issue_id` = D.`issue_id` and I.assembly_id = D.assembly_id and I.kind = :kind) where D.assembly_id = :assembly_id and D.congressman_id = :congressman_id and D.`order` = 1 @@ -253,6 +261,7 @@ public function fetchByAssemblyAndCongressman(int $assemblyId, int $congressmanI $statement->execute([ 'assembly_id' => $assemblyId, 'congressman_id' => $congressmanId, + 'kind' => KindEnum::A->value ]); return array_map(function ($object) { return (new Hydrator\Issue())->hydrate($object, new Model\Issue()); @@ -271,12 +280,12 @@ public function fetchByAssemblyAndCongressmanSummary(int $assemblyId, int $congr join `Issue` I on ( D.issue_id = I.issue_id and D.assembly_id = I.assembly_id - and I.category = 'A' + and I.kind = :kind ) join `Document_has_Congressman` DC on ( D.document_id = DC.document_id and D.assembly_id = DC.assembly_id - and I.category = 'A' + and I.kind = :kind ) where D.assembly_id = :assembly_id and DC.congressman_id = :congressman_id @@ -287,6 +296,7 @@ public function fetchByAssemblyAndCongressmanSummary(int $assemblyId, int $congr $statement->execute([ 'assembly_id' => $assemblyId, 'congressman_id' => $congressmanId, + 'kind' => KindEnum::A->value ]); return array_map(function ($object) { return (new Hydrator\CongressmanIssue())->hydrate($object, new Model\CongressmanIssue()); @@ -300,18 +310,18 @@ public function fetchByAssemblyAndCongressmanSummary(int $assemblyId, int $congr * * @return \Althingi\Model\AssemblyStatus[] */ - public function fetchCountByCategoryAndStatus(int $assemblyId, string $category = 'A'): array + public function fetchCountByCategoryAndStatus(int $assemblyId, string $kind = KindEnum::A): array { $statement = $this->getDriver()->prepare(' select count(*) as `count`, I.`status`, I.`type`, I.`type_name`, I.`type_subname` from `Issue` I where I.assembly_id = :assembly_id - and I.category = :category + and I.kind = :kind group by I.`type`, I.`status` order by I.`type_name` '); $statement->execute([ 'assembly_id' => $assemblyId, - 'category' => $category, + 'kind' => $kind->value, ]); return array_map(function ($object) { @@ -322,11 +332,11 @@ public function fetchCountByCategoryAndStatus(int $assemblyId, string $category public function fetchCountByCategory(int $assemblyId) { $statement = $this->getDriver()->prepare(' - select count(*) as `count`, category, type, type_name, type_subname + select count(*) as `count`, kind, type, type_name, type_subname from Issue where assembly_id = :assembly_id group by type - order by category, type_name; + order by kind, type_name; '); $statement->execute([ @@ -347,13 +357,14 @@ public function fetchCountByGovernment(int $assemblyId): array { $statement = $this->getDriver()->prepare(' select I.`status` as `value`, count(*) as `count` from Document D - join Issue I on (D.assembly_id = I.assembly_id and D.issue_id = I.issue_id and I.category = \'A\') + join Issue I on (D.assembly_id = I.assembly_id and D.issue_id = I.issue_id and I.kind = :kind) where D.assembly_id = :assembly_id and D.`type` = \'stjórnarfrumvarp\' group by I.`status`; '); $statement->execute([ 'assembly_id' => $assemblyId, + 'kind' => KindEnum::A->value ]); return array_map(function ($object) { @@ -371,11 +382,14 @@ public function fetchBillStatisticsByAssembly(int $id): array $statement = $this->getDriver()->prepare( 'select count(*) as `count`, I.`status` from `Issue` I where I.`type` = \'l\' and I.assembly_id = :assembly_id - and I.category = \'A\' + and I.kind = :kind group by `status`;' ); - $statement->execute(['assembly_id' => $id]); + $statement->execute([ + 'assembly_id' => $id, + 'kind' => KindEnum::A->value + ]); return array_map(function ($object) { return (new Hydrator\IssueTypeStatus())->hydrate($object, new Model\IssueTypeStatus()); @@ -392,11 +406,14 @@ public function fetchNonGovernmentBillStatisticsByAssembly(int $id): array where `type` = \'l\' and assembly_id = :assembly_id and `type_subname` != \'stjórnarfrumvarp\' - and I.category = \'A\' + and I.kind = :kind group by `status`;' ); - $statement->execute(['assembly_id' => $id]); + $statement->execute([ + 'assembly_id' => $id, + 'kind' => KindEnum::A->value + ]); return array_map(function ($object) { return (new Hydrator\IssueTypeStatus())->hydrate($object, new Model\IssueTypeStatus()); @@ -413,7 +430,7 @@ public function fetchGovernmentBillStatisticsByAssembly(int $id): array { $statement = $this->getDriver()->prepare(' select count(*) as `count`, I.status from Document D - join Issue I on (I.assembly_id = D.assembly_id and I.issue_id = D.issue_id and I.category = D.category) + join Issue I on (I.assembly_id = D.assembly_id and I.issue_id = D.issue_id and I.kind = D.kind) where D.assembly_id = :assembly_id and D.type = \'stjórnarfrumvarp\' group by I.status; '); @@ -428,7 +445,7 @@ public function fetchGovernmentBillStatisticsByAssembly(int $id): array /** * @return \Althingi\Model\Status[] */ - public function fetchProgress(int $assemblyId, int $issueId, string $category = 'A'): array + public function fetchProgress(int $assemblyId, int $issueId, string $kind = KindEnum::A): array { $statement = $this->getDriver()->prepare(' select count(*) as value, @@ -444,7 +461,7 @@ public function fetchProgress(int $assemblyId, int $issueId, string $category = true as `completed`, 256 as `importance` from `Document` D - where D.`assembly_id` = :assembly_id and D.`issue_id` = :issue_id and `category` = :category + where D.`assembly_id` = :assembly_id and D.`issue_id` = :issue_id and `kind` = :kind group by date_format(D.date, "%Y-%m-%d") having min(D.date) @@ -463,7 +480,7 @@ public function fetchProgress(int $assemblyId, int $issueId, string $category = true as `completed`, 128 as `importance` from Speech S - where S.assembly_id = :assembly_id and S.issue_id = :issue_id and S.`category` = :category + where S.assembly_id = :assembly_id and S.issue_id = :issue_id and S.`kind` = :kind group by date_format(S.`from`, "%Y-%m-%d") having min(`from`) @@ -512,7 +529,11 @@ public function fetchProgress(int $assemblyId, int $issueId, string $category = ; '); - $statement->execute(['assembly_id' => $assemblyId, 'issue_id' => $issueId, 'category' => $category]); + $statement->execute([ + 'assembly_id' => $assemblyId, + 'issue_id' => $issueId, + 'kind' => $kind->value + ]); return array_map(function ($object) { return (new Hydrator\Status())->hydrate($object, new Model\Status()); @@ -528,7 +549,7 @@ public function fetchByAssemblyAndSpeechTime( int $assemblyId, ?int $size = null, ?string $order = 'desc', - $categories = ['A'] + $kind = [KindEnum::A] ): array { $limit = $size ? "limit 0, {$size}" @@ -541,12 +562,12 @@ public function fetchByAssemblyAndSpeechTime( join `Issue` I on ( I.`issue_id` = S.`issue_id` and I.`assembly_id` = S.`assembly_id` - and I.`category` = S.`category` + and I.`kind` = S.`kind` ) - where S.`assembly_id` = :assembly and S.`category` in (" . - implode(', ', array_map(function ($c) { - return '"' . $c . '"'; - }, $categories)) + where S.`assembly_id` = :assembly and S.`kind` in (" . + implode(', ', array_map(function (KindEnum $item) { + return '"' . $item->value . '"'; + }, $kind)) . ") group by S.`issue_id` order by `value` {$order} @@ -604,7 +625,7 @@ public function update(Model\Issue $data): int $data, "issue_id = {$data->getIssueId()} and ". "assembly_id = {$data->getAssemblyId()} and ". - "category = '{$data->getCategory()}'" + "kind = '{$data->getKind()->value}'" ) ); $statement->execute($this->toSqlValues($data)); @@ -649,24 +670,16 @@ private function categoryTypeFilterString(array $category = []): string return ' and CI.`category_id` in (' . implode(',', $category) . ')'; } - private function categoryString(?array $categories = [], $prefix = 'and') + private function categoryString(?array $kind = [], $prefix = 'and') { - $formattedCategories = array_map(function ($c) { - return strtoupper($c); - }, $categories ? : []); - - $filteredCategories = array_filter($formattedCategories, function ($c) { - return $c === 'A' || $c === 'B'; - }); - - if (empty($filteredCategories)) { + if (empty($kind)) { return ''; } - $quotedCategories = array_map(function ($c) { - return "'" . $c . "'"; - }, $filteredCategories); + $quotedCategories = array_map(function (KindEnum $item) { + return "'" . $item->value . "'"; + }, $kind); - return " {$prefix} I.`category` in (" . implode(',', $quotedCategories) . ')'; + return " {$prefix} I.`kind` in (" . implode(',', $quotedCategories) . ')'; } } diff --git a/src/Service/IssueCategory.php b/src/Service/IssueCategory.php index 042c040f..66c5ab44 100644 --- a/src/Service/IssueCategory.php +++ b/src/Service/IssueCategory.php @@ -6,6 +6,7 @@ use Althingi\Events\{UpdateEvent, AddEvent}; use Althingi\Presenters\IndexableIssueCategoryPresenter; use Althingi\Injector\{EventsAwareInterface, DatabaseAwareInterface}; +use Althingi\Model\KindEnum; use Generator; use PDO; @@ -21,12 +22,13 @@ public function get(int $assemblyId, int $issueId, int $categoryId): ? Model\Iss where C.`assembly_id` = :assembly_id and C.`issue_id` = :issue_id and C.`category_id` = :category_id - and C.category = \'A\' + and C.kind = :kind '); $statement->execute([ 'assembly_id' => $assemblyId, 'issue_id' => $issueId, - 'category_id' => $categoryId + 'category_id' => $categoryId, + 'kind' => KindEnum::A->value ]); $object = $statement->fetch(PDO::FETCH_ASSOC); @@ -137,12 +139,12 @@ public function update(Model\IssueCategory $data): int public function fetchFrequencyByAssemblyAndCongressman( int $assemblyId, int $congressmanId, - ?array $category = ['A'] + ?array $kind = [KindEnum::A] ): array { - $categories = count($category) > 0 - ? 'and SP.category in (' . implode(',', array_map(function ($c) { - return '"' . $c . '"'; - }, $category)) . ')' + $categories = count($kind) > 0 + ? 'and SP.kind in (' . implode(',', array_map(function (KindEnum $item) { + return '"' . $item->value . '"'; + }, $kind)) . ')' : ''; $statement = $this->getDriver()->prepare(" diff --git a/src/Service/IssueLink.php b/src/Service/IssueLink.php index 56b1496b..81bd8d70 100644 --- a/src/Service/IssueLink.php +++ b/src/Service/IssueLink.php @@ -7,6 +7,7 @@ use Althingi\Events\{UpdateEvent, AddEvent}; use Althingi\Presenters\IndexableIssueLinkPresenter; use Althingi\Injector\{EventsAwareInterface, DatabaseAwareInterface}; +use Althingi\Model\KindEnum; use PDO; class IssueLink implements DatabaseAwareInterface, EventsAwareInterface @@ -17,7 +18,7 @@ class IssueLink implements DatabaseAwareInterface, EventsAwareInterface /** * @return \Althingi\Model\Issue */ - public function fetchAll(int $assemblyId, int $issueId, string $category = 'A'): array + public function fetchAll(int $assemblyId, int $issueId, KindEnum $kind = KindEnum::A): array { $statement = $this->getDriver() ->prepare(" @@ -25,13 +26,13 @@ public function fetchAll(int $assemblyId, int $issueId, string $category = 'A'): join Issue I on ( IL.to_assembly_id = I.assembly_id and IL.to_issue_id = I.issue_id - and IL.to_category = I.category + and IL.to_kind = I.kind ) where IL.from_assembly_id = :assembly_id and IL.from_issue_id = :issue_id - and IL.from_category = :category; + and IL.from_kind = :kind; "); - $statement->execute(['assembly_id' => $assemblyId, 'issue_id' => $issueId, 'category' => $category]); + $statement->execute(['assembly_id' => $assemblyId, 'issue_id' => $issueId, 'kind' => $kind]); return array_map(function ($issue) { return (new Hydrator\Issue())->hydrate($issue, new Model\Issue()); @@ -83,10 +84,10 @@ public function update(Model\IssueLink $data): int $data, "to_assembly_id={$data->getAssemblyId()} and" . "to_issue_id={$data->getIssueId()} and" . - "to_category={$data->getCategory()} and" . + "to_kind={$data->getKind()->value} and" . "from_assembly_id={$data->getFromAssemblyId()} and" . "from_issue_id={$data->getFromIssueId()} and" . - "from_category={$data->getFromCategory()}" + "from_kind={$data->getFromKind()->value}" ) ); $statement->execute($this->toSqlValues($data)); diff --git a/src/Service/Party.php b/src/Service/Party.php index e26bc743..0d779cad 100644 --- a/src/Service/Party.php +++ b/src/Service/Party.php @@ -7,6 +7,7 @@ use Althingi\Events\{UpdateEvent, AddEvent}; use Althingi\Presenters\IndexablePartyPresenter; use Althingi\Injector\{DatabaseAwareInterface, EventsAwareInterface}; +use Althingi\Model\KindEnum; use PDO; use DateTime; use Generator; @@ -108,12 +109,12 @@ public function getByCongressmanAndAssembly(int $congressmanId, int $assemblyId) * @return \Althingi\Model\PartyAndTime[] * @deprecated */ - public function fetchTimeByAssembly(int $assemblyId, array $category = ['A']): array + public function fetchTimeByAssembly(int $assemblyId, array $kind = [KindEnum::A]): array { - $categories = count($category) > 0 - ? 'and SP.category in (' . implode(',', array_map(function ($c) { - return '"' . $c . '"'; - }, $category)) . ')' + $categories = count($kind) > 0 + ? 'and SP.kind in (' . implode(',', array_map(function (KindEnum $item) { + return '"' . $item->value . '"'; + }, $kind)) . ')' : ''; $statement = $this->getDriver()->prepare(" diff --git a/src/Service/Speech.php b/src/Service/Speech.php index a2713adf..c01e4ad0 100644 --- a/src/Service/Speech.php +++ b/src/Service/Speech.php @@ -7,6 +7,7 @@ use Althingi\Events\{UpdateEvent, AddEvent}; use Althingi\Presenters\IndexableSpeechPresenter; use Althingi\Injector\{EventsAwareInterface, DatabaseAwareInterface}; +use Althingi\Model\KindEnum; use Generator; use PDO; @@ -108,16 +109,20 @@ public function getFrequencyByAssemblyAndCongressman(int $assemblyId, int $congr ]; } - public function fetchAllByIssue(int $assemblyId, int $issueId, string $category = 'A') + public function fetchAllByIssue(int $assemblyId, int $issueId, KindEnum $kind = KindEnum::A) { $statement = $this->getDriver()->prepare(" select *, timestampdiff(SECOND, `from`, `to`) as `time` from `Speech` - where assembly_id = :assembly_id and issue_id = :issue_id and `category` = :category + where assembly_id = :assembly_id and issue_id = :issue_id and `kind` = :kind order by `from` "); - $statement->execute(['assembly_id' => $assemblyId, 'issue_id' => $issueId, 'category' => $category]); + $statement->execute([ + 'assembly_id' => $assemblyId, + 'issue_id' => $issueId, + 'kind' => $kind->value + ]); $speeches = $statement->fetchAll(PDO::FETCH_ASSOC); return array_map(function ($object, $position) { @@ -134,7 +139,7 @@ public function fetchAllByIssue(int $assemblyId, int $issueId, string $category public function fetchByIssue( int $assemblyId, int $issueId, - ?string $category = 'A', + ?KindEnum $kind = KindEnum::A, ?int $offset = 0, ?int $size = null, ?int $words = 1500 @@ -144,11 +149,11 @@ public function fetchByIssue( $statement = $this->getDriver()->prepare(" select *, timestampdiff(SECOND, `from`, `to`) as `time` from `Speech` - where assembly_id = :assembly_id and issue_id = :issue_id and `category` = :category + where assembly_id = :assembly_id and issue_id = :issue_id and `kind` = :kind order by `from` limit {$offset}, {$resultSize}; "); - $statement->execute(['assembly_id' => $assemblyId, 'issue_id' => $issueId, 'category' => $category]); + $statement->execute(['assembly_id' => $assemblyId, 'issue_id' => $issueId, 'kind' => $kind->value]); if ($size) { $speeches = $statement->fetchAll(PDO::FETCH_ASSOC); @@ -187,16 +192,16 @@ public function fetchByIssue( * * @return \Althingi\Model\SpeechAndPosition[] */ - public function fetch(string $id, int $assemblyId, int $issueId, ?int $size = 25, ?string $category = 'A'): array + public function fetch(string $id, int $assemblyId, int $issueId, ?int $size = 25, ?KindEnum $kind = KindEnum::A): array { $pointer = 0; $hasResult = false; $statement = $this->getDriver()->prepare( 'select * from `Speech` s - where s.`assembly_id` = :assembly_id and s.`issue_id` = :issue_id and s.category = :category + where s.`assembly_id` = :assembly_id and s.`issue_id` = :issue_id and s.kind = :kind order by s.`from`' ); - $statement->execute(['assembly_id' => $assemblyId, ':issue_id' => $issueId, 'category' => $category]); + $statement->execute(['assembly_id' => $assemblyId, ':issue_id' => $issueId, 'kind' => $kind->value]); while ($row = $statement->fetch(PDO::FETCH_OBJ)) { if ($row->speech_id == $id) { @@ -274,13 +279,13 @@ public function fetchAllGenerator(?int $assemblyId = null, ?int $issueId = null) return null; } - public function countByIssue(int $assemblyId, int $issueId, ?string $category = 'A'): int + public function countByIssue(int $assemblyId, int $issueId, ?KindEnum $kind = KindEnum::A): int { $statement = $this->getDriver()->prepare(" select count(*) from `Speech` - where assembly_id = :assembly_id and issue_id = :issue_id and category = :category + where assembly_id = :assembly_id and issue_id = :issue_id and kind = :kind "); - $statement->execute(['assembly_id' => $assemblyId, 'issue_id' => $issueId, 'category' => $category]); + $statement->execute(['assembly_id' => $assemblyId, 'issue_id' => $issueId, 'kind' => $kind->value]); return $statement->fetchColumn(0); } @@ -290,13 +295,13 @@ public function countByIssue(int $assemblyId, int $issueId, ?string $category = * * @return \Althingi\Model\DateAndCount[] */ - public function fetchFrequencyByIssue(int $assemblyId, int $issueId, ?string $category = 'A'): array + public function fetchFrequencyByIssue(int $assemblyId, int $issueId, ?KindEnum $kind = KindEnum::A): array { $statement = $this->getDriver()->prepare(' select date_format(`from`, "%Y-%m-%d 00:00:00") as `date`, (sum(time_to_sec(timediff(`to`, `from`)))) as `count` from `Speech` - where assembly_id = :assembly_id and issue_id = :issue_id and category = :category + where assembly_id = :assembly_id and issue_id = :issue_id and kind = :kind group by date_format(`from`, "%Y-%m-%d") having `count` is not null order by `from`; @@ -305,7 +310,7 @@ public function fetchFrequencyByIssue(int $assemblyId, int $issueId, ?string $ca $statement->execute([ 'assembly_id' => $assemblyId, 'issue_id' => $issueId, - 'category' => $category + 'kind' => $kind->value ]); return array_map(function ($speech) { @@ -321,12 +326,12 @@ public function fetchFrequencyByIssue(int $assemblyId, int $issueId, ?string $ca * * @return \Althingi\Model\DateAndCount[] */ - public function fetchFrequencyByAssembly(int $assemblyId, ?array $category = ['A']): array + public function fetchFrequencyByAssembly(int $assemblyId, ?array $kind = [KindEnum::A]): array { - $categories = count($category) > 0 - ? 'and `category` in (' . implode(',', array_map(function ($c) { - return '"' . $c . '"'; - }, $category)) . ')' + $categories = count($kind) > 0 + ? 'and `kind` in (' . implode(',', array_map(function (KindEnum $item) { + return '"' . $item->value . '"'; + }, $kind)) . ')' : ''; $statement = $this->getDriver()->prepare( @@ -346,12 +351,12 @@ public function fetchFrequencyByAssembly(int $assemblyId, ?array $category = ['A public function countTotalTimeByAssemblyAndCongressman( int $assemblyId, int $congressmanId, - ?array $category = ['A'] + ?array $kind = [KindEnum::A] ): int { - $categories = count($category) > 0 - ? 'and S.category in (' . implode(',', array_map(function ($c) { - return '"' . $c . '"'; - }, $category)) . ')' + $categories = count($kind) > 0 + ? 'and S.kind in (' . implode(',', array_map(function (KindEnum $item) { + return '"' . $item->value . '"'; + }, $kind)) . ')' : ''; $statement = $this->getDriver()->prepare(" diff --git a/src/Service/Vote.php b/src/Service/Vote.php index f80010b7..951c7c2b 100644 --- a/src/Service/Vote.php +++ b/src/Service/Vote.php @@ -7,6 +7,7 @@ use Althingi\Events\{UpdateEvent, AddEvent}; use Althingi\Presenters\IndexableVotePresenter; use Althingi\Injector\{EventsAwareInterface, DatabaseAwareInterface}; +use Althingi\Model\KindEnum; use PDO; use DateTime; use Exception; @@ -53,11 +54,12 @@ public function fetchAllGenerator(?int $assemblyId = null, ?int $issueId = null, select * from `Vote` where assembly_id = :assembly_id and issue_id = :issue_id and - category = \'A\' + kind = :kind '); $statement->execute([ 'assembly_id' => $assemblyId, - 'issue_id' => $issueId + 'issue_id' => $issueId, + 'kind' => KindEnum::A->value, ]); } elseif ($assemblyId !== null && $issueId !== null && $documentId !== null) { $statement = $this->getDriver() @@ -65,13 +67,14 @@ public function fetchAllGenerator(?int $assemblyId = null, ?int $issueId = null, select * from `Vote` where assembly_id = :assembly_id and issue_id = :issue_id and - category = \'A\' and + kind = :kind and document_id = :document_id '); $statement->execute([ 'assembly_id' => $assemblyId, 'issue_id' => $issueId, - 'document_id' => $documentId + 'document_id' => $documentId, + 'kind' => KindEnum::A->value, ]); } else { throw new Exception('Paramters missing'); diff --git a/src/Validator/IssueKind.php b/src/Validator/IssueKind.php new file mode 100644 index 00000000..5526fdba --- /dev/null +++ b/src/Validator/IssueKind.php @@ -0,0 +1,31 @@ +error('value is not A or B'); + return false; + } + return true; + } +} diff --git a/tests/Controller/CommitteeDocumentControllerTest.php b/tests/Controller/CommitteeDocumentControllerTest.php index 4337e9d1..68b2e623 100644 --- a/tests/Controller/CommitteeDocumentControllerTest.php +++ b/tests/Controller/CommitteeDocumentControllerTest.php @@ -4,6 +4,7 @@ use Althingi\Controller; use Althingi\Model; +use Althingi\Model\KindEnum; use Althingi\Service; use Althingi\ServiceHelper; use Library\Container\Container; @@ -45,7 +46,7 @@ public function testCreateSuccess() ->setDocumentId(4) ->setAssemblyId(1) ->setIssueId(2) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCommitteeId(3) ->setPart('part') ->setName('name'); @@ -132,7 +133,7 @@ public function testPatchSuccess() ->setDocumentId(4) ->setAssemblyId(1) ->setIssueId(2) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCommitteeId(3) ->setPart(null) ->setName(null); @@ -142,7 +143,7 @@ public function testPatchSuccess() ->setDocumentId(4) ->setAssemblyId(1) ->setIssueId(2) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCommitteeId(3) ->setPart('part') ->setName('name'); @@ -182,7 +183,7 @@ public function testPatchInvalidParams() ->setDocumentId(4) ->setAssemblyId(1) ->setIssueId(2) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCommitteeId(3) ->setPart(null) ->setName(null); @@ -236,7 +237,7 @@ public function testGet() ->setDocumentId(4) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('') + ->setKind(KindEnum::A) ->setCommitteeId(1) ) ->getMock(); @@ -276,7 +277,7 @@ public function testGetList() ->setDocumentId(4) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('') + ->setKind(KindEnum::A) ->setCommitteeId(1) ]) ->getMock(); diff --git a/tests/Controller/CommitteeMeetingAgendaControllerTest.php b/tests/Controller/CommitteeMeetingAgendaControllerTest.php index 073bcc05..90eeeb5e 100644 --- a/tests/Controller/CommitteeMeetingAgendaControllerTest.php +++ b/tests/Controller/CommitteeMeetingAgendaControllerTest.php @@ -3,6 +3,7 @@ namespace Althingi\Controller; use Althingi\Controller\CommitteeMeetingAgendaController; +use Althingi\Model\KindEnum; use Althingi\Service\CommitteeMeetingAgenda; use Althingi\ServiceHelper; use Library\Container\Container; @@ -44,7 +45,7 @@ public function testGet() ->shouldReceive('get') ->andReturn( (new \Althingi\Model\CommitteeMeetingAgenda()) - ->setCategory('category') + ->setKind(KindEnum::A) ->setCommitteeMeetingAgendaId(1) ->setCommitteeMeetingId(1646) ->setAssemblyId(145) @@ -129,7 +130,7 @@ public function testPatch() ->with(1646, 1) ->andReturn( (new \Althingi\Model\CommitteeMeetingAgenda()) - ->setCategory('category') + ->setKind(KindEnum::A) ->setCommitteeMeetingId(1646) ->setCommitteeMeetingAgendaId(1) ->setAssemblyId(145) diff --git a/tests/Controller/CongressmanDocumentControllerTest.php b/tests/Controller/CongressmanDocumentControllerTest.php index 3567cff9..d1e96193 100644 --- a/tests/Controller/CongressmanDocumentControllerTest.php +++ b/tests/Controller/CongressmanDocumentControllerTest.php @@ -4,6 +4,7 @@ use Althingi\Controller\CongressmanDocumentController; use Althingi\Model\CongressmanDocument as CongressmanDocumentModel; +use Althingi\Model\KindEnum; use Althingi\Service\CongressmanDocument; use Althingi\ServiceHelper; use Library\Container\Container; @@ -70,7 +71,7 @@ public function testPatchSuccess() (new CongressmanDocumentModel()) ->setAssemblyId(145) ->setIssueId(2) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(637) ->setDocumentId(1018) ->setOrder(1) diff --git a/tests/Controller/CongressmanIssueControllerTest.php b/tests/Controller/CongressmanIssueControllerTest.php index e0f01e45..8124392e 100644 --- a/tests/Controller/CongressmanIssueControllerTest.php +++ b/tests/Controller/CongressmanIssueControllerTest.php @@ -4,6 +4,7 @@ use Althingi\Controller\CongressmanIssueController; use Althingi\Model; +use Althingi\Model\KindEnum; use Althingi\Service\Issue; use Althingi\ServiceHelper; use Library\Container\Container; @@ -46,7 +47,7 @@ public function testGetCongressmanIssueList() ->shouldReceive('fetchByCongressman') ->with(123) ->once() - ->andReturn([new Model\Issue()]) + ->andReturn([(new Model\Issue())->setKind(KindEnum::A)]) ->getMock(); $this->dispatch('/thingmenn/123/thingmal', 'GET'); diff --git a/tests/Controller/DocumentControllerTest.php b/tests/Controller/DocumentControllerTest.php index df5e654f..515612d9 100644 --- a/tests/Controller/DocumentControllerTest.php +++ b/tests/Controller/DocumentControllerTest.php @@ -4,6 +4,7 @@ use Althingi\Controller\DocumentController; use Althingi\Model; +use Althingi\Model\KindEnum; use Althingi\Service; use Althingi\ServiceHelper; use Library\Container\Container; @@ -49,7 +50,7 @@ public function testGet() ->setDate(new \DateTime()) ->setDocumentId(2) ->setIssueId(2) - ->setCategory('category') + ->setKind(KindEnum::A) ->setAssemblyId(145) ->setType('type') ) @@ -95,7 +96,7 @@ public function testGetList() ->setDate(new \DateTime()) ->setDocumentId(2) ->setIssueId(2) - ->setCategory('category') + ->setKind(KindEnum::A) ->setAssemblyId(145) ->setType('type') ), @@ -104,7 +105,7 @@ public function testGetList() ->setDate(new \DateTime()) ->setDocumentId(2) ->setIssueId(2) - ->setCategory('category') + ->setKind(KindEnum::A) ->setAssemblyId(145) ->setType('type') @@ -174,7 +175,7 @@ public function testPatch() ->setAssemblyId(145) ->setIssueId(2) ->setDocumentId(2) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime()) ->setType('some-type') ) @@ -210,7 +211,7 @@ public function testPatchInvalidArguments() ->setDocumentId(2) ->setDate(new \DateTime()) ->setType('some-type') - ->setCategory('category') + ->setKind(KindEnum::A) ) ->getMock() diff --git a/tests/Controller/IssueCategoryControllerTest.php b/tests/Controller/IssueCategoryControllerTest.php index 2031a380..bd916adb 100644 --- a/tests/Controller/IssueCategoryControllerTest.php +++ b/tests/Controller/IssueCategoryControllerTest.php @@ -5,6 +5,7 @@ use Althingi\Controller\IssueCategoryController; use Althingi\Model\Category as CategoryModel; use Althingi\Model\IssueCategory as IssueCategoryModel; +use Althingi\Model\KindEnum; use Althingi\Service\Category; use Althingi\Service\IssueCategory; use Althingi\ServiceHelper; @@ -126,7 +127,7 @@ public function testPatch() ->setAssemblyId(141) ->setIssueId(131) ->setCategoryId(21) - ->setCategory('A') + ->setKind(KindEnum::A) ) ->getMock() ->shouldReceive('update') diff --git a/tests/Controller/IssueControllerTest.php b/tests/Controller/IssueControllerTest.php index be142702..ef6db720 100644 --- a/tests/Controller/IssueControllerTest.php +++ b/tests/Controller/IssueControllerTest.php @@ -4,6 +4,7 @@ use Althingi\Controller; use Althingi\Model; +use Althingi\Model\KindEnum; use Althingi\Service; use Althingi\ServiceHelper; use Library\Container\Container; @@ -46,7 +47,7 @@ public function testGetSuccessA() { $this->getMockService(Service\Issue::class) ->shouldReceive('get') - ->with(200, 100, 'A') + ->with(200, 100, KindEnum::A) ->andReturn(new Model\Issue()) ->getMock(); @@ -64,7 +65,7 @@ public function testGetSuccessB() { $this->getMockService(Service\Issue::class) ->shouldReceive('get') - ->with(200, 100, 'B') + ->with(200, 100, KindEnum::B) ->andReturn(new Model\Issue()) ->getMock(); @@ -82,7 +83,7 @@ public function testGetNotFound() { $this->getMockService(Service\Issue::class) ->shouldReceive('get') - ->with(200, 100, 'A') + ->with(200, 100, KindEnum::A) ->andReturn(null) ->getMock(); @@ -121,7 +122,7 @@ public function testPutSuccess() $expectedObject = (new Model\Issue()) ->setIssueId(200) ->setAssemblyId(100) - ->setCategory('A') + ->setKind(KindEnum::A) ->setName('n1') ->setType('1') ->setTypeName('tn') @@ -140,7 +141,7 @@ public function testPutSuccess() $this->dispatch('/loggjafarthing/100/thingmal/a/200', 'PUT', [ 'name' => 'n1', - 'category' => 'c1', + 'kind' => KindEnum::A->value, 'type' => '1', 'type_name' => 'tn', 'type_subname' => 'tsn', @@ -181,7 +182,7 @@ public function testPatch() ->setIssueId(200) ->setAssemblyId(100) ->setName('n1') - ->setCategory('c1') + ->setKind(KindEnum::A) ->setType('1') ->setTypeName('tn') ->setTypeSubname('tsn') @@ -190,8 +191,8 @@ public function testPatch() $this->getMockService(Service\Issue::class) ->shouldReceive('get') ->once() - ->with(200, 100, 'A') - ->andReturn((new Model\Issue())->setIssueId(200)->setAssemblyId(100)->setCategory('A')) + ->with(200, 100, KindEnum::A) + ->andReturn((new Model\Issue())->setIssueId(200)->setAssemblyId(100)->setKind(KindEnum::A)) ->getMock() ->shouldReceive('update') @@ -205,7 +206,7 @@ public function testPatch() $this->dispatch('/loggjafarthing/100/thingmal/a/200', 'PATCH', [ 'name' => 'n1', - 'category' => 'c1', + 'kind' => 'A', 'type' => '1', 'type_name' => 'tn', 'type_subname' => 'tsn', diff --git a/tests/Controller/PlenaryAgendaControllerTest.php b/tests/Controller/PlenaryAgendaControllerTest.php index b3ff5ac4..fbf123c1 100644 --- a/tests/Controller/PlenaryAgendaControllerTest.php +++ b/tests/Controller/PlenaryAgendaControllerTest.php @@ -4,6 +4,7 @@ use Althingi\Controller\PlenaryAgendaController; use Althingi\Model; +use Althingi\Model\KindEnum; use Althingi\Service\Congressman; use Althingi\Service\Issue; use Althingi\Service\Party; @@ -57,7 +58,7 @@ public function testGetList() (new Model\PlenaryAgenda()) ->setIssueId(10) ->setAssemblyId(1) - ->setCategory('a') + ->setKind(KindEnum::A) ->setPlenaryId(2) ]) ->once() @@ -77,7 +78,7 @@ public function testPutSuccess() $expectedData = (new \Althingi\Model\PlenaryAgenda()) ->setAssemblyId(1) ->setPlenaryId(2) - ->setCategory('B') + ->setKind(KindEnum::B) ->setIssueId(1) ->setItemId(1) ; @@ -92,7 +93,7 @@ public function testPutSuccess() $this->dispatch('/loggjafarthing/1/thingfundir/2/lidir/1', 'PUT', [ 'issue_id' => 1, - 'category' => 'B', + 'kind' => 'B', ]); $this->assertControllerName(PlenaryAgendaController::class); @@ -108,7 +109,7 @@ public function testPutIssueNotFound() $expectedData = (new \Althingi\Model\PlenaryAgenda()) ->setAssemblyId(1) ->setPlenaryId(2) - ->setCategory('B') + ->setKind(KindEnum::B) ->setIssueId(1) ->setItemId(1) ; @@ -128,7 +129,7 @@ public function testPutIssueNotFound() $this->dispatch('/loggjafarthing/1/thingfundir/2/lidir/1', 'PUT', [ 'issue_id' => 1, - 'category' => 'B', + 'kind' => 'B', 'issue_name' => '', 'issue_type' => '', 'issue_typename' => '', diff --git a/tests/Controller/SpeechControllerTest.php b/tests/Controller/SpeechControllerTest.php index 031e8410..db40c4fa 100644 --- a/tests/Controller/SpeechControllerTest.php +++ b/tests/Controller/SpeechControllerTest.php @@ -5,6 +5,7 @@ use Althingi\Controller; use Althingi\Model; use Althingi\Model\Assembly; +use Althingi\Model\KindEnum; use Althingi\Service; use Althingi\ServiceHelper; use DateTime; @@ -59,9 +60,10 @@ public function testGetSuccess() ->getMock() ->shouldReceive('fetch') - ->with(4, 1, 3, 25, 'A') + ->with(4, 1, 3, 25, KindEnum::A) ->andReturn([ (new Model\SpeechAndPosition()) + ->setKind(KindEnum::A) ->setPosition(1) ->setCongressmanId(1) ->setFrom(new \DateTime()) @@ -115,6 +117,7 @@ public function testGetRangeHeaders() ->shouldReceive('fetch') ->andReturn(array_map(function ($i) { return (new Model\SpeechAndPosition()) + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setText('') ->setFrom(new \DateTime('2000-01-01')) @@ -170,7 +173,7 @@ public function testPutSuccess() ->setTo(new \DateTime('2001-01-01 00:00:00')) ->setType('t1') ->setText('t2') - ->setCategory('A') + ->setKind(KindEnum::A) ->setValidated(false); $this->getMockService(Service\Speech::class) @@ -194,7 +197,7 @@ public function testPutSuccess() 'iteration' => '*', 'type' => 't1', 'text' => 't2', - 'category' =>' A', + 'kind' => 'a', 'validated' => 'false', ]); @@ -306,11 +309,11 @@ public function testGetList() { $this->getMockService(Service\Speech::class) ->shouldReceive('fetchAllByIssue') - ->with(144, 3, 'B') + ->with(144, 3, KindEnum::B) ->once() ->andReturn([ (new Model\SpeechCongressmanProperties()) - ->setSpeech(new Model\Speech()) + ->setSpeech((new Model\Speech())->setKind(KindEnum::A)) ->setCongressman(( (new Model\CongressmanPartyProperties()) ->setAssembly((new Assembly())->setAssemblyId(1)->setFrom(new DateTime())) @@ -341,7 +344,9 @@ public function testPatchSuccess() ->setPlenaryId(1) ->setAssemblyId(145) ->setIssueId(1) - ->setCongressmanId(1); + ->setCongressmanId(1) + ->setKind(KindEnum::A) + ; $this->getMockService(Service\Speech::class) ->shouldReceive('get') @@ -355,6 +360,7 @@ public function testPatchSuccess() ->setAssemblyId(145) ->setIssueId(1) ->setCongressmanId(1) + ->setKind(KindEnum::A) ) ->getMock() @@ -379,7 +385,7 @@ public function testPatchInvalid() { $this->getMockService(Service\Speech::class) ->shouldReceive('get') - ->andReturn(new Model\Speech()) + ->andReturn((new Model\Speech())->setKind(KindEnum::A)) ->getMock(); $this->dispatch('/loggjafarthing/144/thingmal/a/3/raedur/4', 'PATCH', [ diff --git a/tests/Controller/VoteControllerTest.php b/tests/Controller/VoteControllerTest.php index d9fbdbfd..63b778a2 100644 --- a/tests/Controller/VoteControllerTest.php +++ b/tests/Controller/VoteControllerTest.php @@ -3,6 +3,7 @@ namespace Althingi\Controller; use Althingi\Controller\VoteController; +use Althingi\Model\KindEnum; use Althingi\Service\Vote; use Althingi\ServiceHelper; use Library\Container\Container; @@ -45,7 +46,7 @@ public function testGet() $this->getMockService(Vote::class) ->shouldReceive('get') ->with(3) - ->andReturn((new \Althingi\Model\Vote())) + ->andReturn((new \Althingi\Model\Vote())->setKind(KindEnum::A)) ->once() ->getMock(); @@ -83,7 +84,7 @@ public function testGetList() $this->getMockService(Vote::class) ->shouldReceive('fetchByIssue') ->with(1, 2) - ->andReturn([(new \Althingi\Model\Vote())]) + ->andReturn([(new \Althingi\Model\Vote())->setKind(KindEnum::A)]) ->once() ->getMock() ; @@ -149,14 +150,14 @@ public function testPatchSuccess() ->setAssemblyId(1) ->setDate(new \DateTime('2000-01-01 00:00:00')) ->setType('type') - ->setCategory('A') + ->setKind(KindEnum::A) ->setMethod('method'); $expectedData = (new \Althingi\Model\Vote()) ->setVoteId(3) ->setIssueId(2) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2001-01-01 01:02:03')) ->setType('type') ->setMethod('method'); diff --git a/tests/Form/PlenaryAgendaTest.php b/tests/Form/PlenaryAgendaTest.php index 4a8e0541..419e4bc7 100644 --- a/tests/Form/PlenaryAgendaTest.php +++ b/tests/Form/PlenaryAgendaTest.php @@ -11,7 +11,7 @@ public function testWithIDsAreNumbers() { $form = new PlenaryAgenda([ 'assembly_id' => 141, - 'category' => 'B', + 'kind' => 'B', 'counter_answerer' => 'velferu00f0arru00e1u00f0herra', 'counter_answerer_id' => 683, 'instigator' => 'Ju00f3n Gunnarsson', @@ -34,7 +34,7 @@ public function testWithEverythingIsAString() { $form = new PlenaryAgenda([ 'assembly_id' => '141', - 'category' => 'B', + 'kind' => 'B', 'counter_answerer' => 'velferu00f0arru00e1u00f0herra', 'counter_answerer_id' => '683', 'instigator' => 'Ju00f3n Gunnarsson', @@ -65,7 +65,7 @@ public function testWithEmptyStringsAsIDs() { $form = new PlenaryAgenda([ 'assembly_id' => '141', - 'category' => 'B', + 'kind' => 'B', 'counter_answerer' => 'velferu00f0arru00e1u00f0herra', 'counter_answerer_id' => '', 'instigator' => 'Ju00f3n Gunnarsson', diff --git a/tests/Form/VoteTest.php b/tests/Form/VoteTest.php index f62cb85c..5de8b95d 100644 --- a/tests/Form/VoteTest.php +++ b/tests/Form/VoteTest.php @@ -2,6 +2,7 @@ namespace Althingi\Form; +use Althingi\Model\KindEnum; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -11,6 +12,10 @@ public static function providerFunction() { return [ [["yes" => 48, "no" => 0, "inaction" => "0",], 48, 0 , 0], + [["yes" => '48', "no" => '0', "inaction" => "0",], 48, 0 , 0], + [["yes" => 'notAnumber', "no" => '0', "inaction" => "0",], 0, 0 , 0], + [["yes" => 'true', "no" => '0', "inaction" => "0",], 0, 0 , 0], + [["yes" => 'false', "no" => 'false', "inaction" => "false",], 0, 0 , 0], [["yes" => '0', "no" => 0, "inaction" => "0",], 0, 0 , 0], [["yes" => '', "no" => 0, "inaction" => "0",], 0, 0 , 0], [["yes" => 'e', "no" => 0, "inaction" => "0",], 0, 0 , 0], @@ -21,34 +26,27 @@ public static function providerFunction() #[DataProvider('providerFunction')] public function testTrue($input, $yes, $no, $inaction) { - $this->assertTrue(true); -// $inputData = array_merge([ -// "assembly_id" => 146, -// "committee_to" => null, -// "date" => "2016-12-07 13:32:07", -// "document_id" => 1, -// "inaction" => "0", -// "issue_id" => 1, -// "method" => "atkvæðagreiðslukerfi", -// "no" => 0, -// "outcome" => "samþykkt", -// "type" => "Of skammt var liðið frá útbýtingu --- Afbrigði", -// "vote_id" => 53954, -// "yes" => 48, -// ], $input); -// -// $form = (new \Althingi\Form\Vote()) -// ->setData($inputData); -// $form->isValid(); -// -// $outputData = $form->getObject(); -// -// $this->assertNotNull($outputData->getYes()); -// $this->assertNotNull($outputData->getNo()); -// $this->assertNotNull($outputData->getInaction()); -// -// $this->assertTrue($yes === $outputData->getYes()); -// $this->assertTrue($no === $outputData->getNo()); -// $this->assertTrue($inaction === $outputData->getInaction()); + $form = new Vote([ + "assembly_id" => 146, + "committee_to" => null, + "date" => "2016-12-07 13:32:07", + "document_id" => 1, + "inaction" => $input['inaction'], + "issue_id" => 1, + "method" => "atkvæðagreiðslukerfi", + "no" => $input['no'], + "outcome" => "samþykkt", + "type" => "Of skammt var liðið frá útbýtingu --- Afbrigði", + "vote_id" => 53954, + "yes" => $input['yes'], + 'kind' => KindEnum::A->value + ]); + + $form->isValid(); + $model = $form->getModel(); + + $this->assertEquals($yes, $model->getYes()); + $this->assertEquals($no, $model->getNo()); + $this->assertEquals($inaction, $model->getInaction()); } } diff --git a/tests/Service/CategoryTest.php b/tests/Service/CategoryTest.php index 240742fd..7e17d80f 100644 --- a/tests/Service/CategoryTest.php +++ b/tests/Service/CategoryTest.php @@ -6,6 +6,7 @@ use Althingi\DatabaseConnection; use Althingi\Model\Category as CategoryModel; use Althingi\Model\CategoryAndCount as CategoryAndCountModel; +use Althingi\Model\KindEnum; use PDO; class CategoryTest extends TestCase @@ -160,12 +161,12 @@ protected function getDataSet() ['assembly_id' => 2, 'from' => '2000-01-01', 'to' => null], ], 'Issue' => [ - ['issue_id' => 1, 'assembly_id' => 1, 'category' => 'A'], - ['issue_id' => 2, 'assembly_id' => 1, 'category' => 'A'], - ['issue_id' => 3, 'assembly_id' => 1, 'category' => 'A'], - ['issue_id' => 4, 'assembly_id' => 1, 'category' => 'A'], - ['issue_id' => 5, 'assembly_id' => 2, 'category' => 'A'], - ['issue_id' => 6, 'assembly_id' => 2, 'category' => 'A'], + ['issue_id' => 1, 'assembly_id' => 1, 'kind' => KindEnum::A->value], + ['issue_id' => 2, 'assembly_id' => 1, 'kind' => KindEnum::A->value], + ['issue_id' => 3, 'assembly_id' => 1, 'kind' => KindEnum::A->value], + ['issue_id' => 4, 'assembly_id' => 1, 'kind' => KindEnum::A->value], + ['issue_id' => 5, 'assembly_id' => 2, 'kind' => KindEnum::A->value], + ['issue_id' => 6, 'assembly_id' => 2, 'kind' => KindEnum::A->value], ], 'SuperCategory' => [ ['super_category_id' => 1, 'title' => 'title'], @@ -176,11 +177,11 @@ protected function getDataSet() ['category_id' => 3, 'super_category_id' => 1, 'title' => 't2', 'description' => 'd2'], ], 'Category_has_Issue' => [ - ['category_id' => 1, 'issue_id' => 1, 'assembly_id' => 1, 'category' => 'A'], - ['category_id' => 2, 'issue_id' => 2, 'assembly_id' => 1, 'category' => 'A'], - ['category_id' => 2, 'issue_id' => 3, 'assembly_id' => 1, 'category' => 'A'], - ['category_id' => 2, 'issue_id' => 4, 'assembly_id' => 1, 'category' => 'A'], - ['category_id' => 2, 'issue_id' => 5, 'assembly_id' => 2, 'category' => 'A'], + ['category_id' => 1, 'issue_id' => 1, 'assembly_id' => 1, 'kind' => KindEnum::A->value], + ['category_id' => 2, 'issue_id' => 2, 'assembly_id' => 1, 'kind' => KindEnum::A->value], + ['category_id' => 2, 'issue_id' => 3, 'assembly_id' => 1, 'kind' => KindEnum::A->value], + ['category_id' => 2, 'issue_id' => 4, 'assembly_id' => 1, 'kind' => KindEnum::A->value], + ['category_id' => 2, 'issue_id' => 5, 'assembly_id' => 2, 'kind' => KindEnum::A->value], ], ]); } diff --git a/tests/Service/CommitteeMeetingAgendaTest.php b/tests/Service/CommitteeMeetingAgendaTest.php index 433321cb..11a01bb3 100644 --- a/tests/Service/CommitteeMeetingAgendaTest.php +++ b/tests/Service/CommitteeMeetingAgendaTest.php @@ -6,6 +6,7 @@ use Althingi\Service\CommitteeMeetingAgenda; use Althingi\DatabaseConnection; use Althingi\Model\CommitteeMeetingAgenda as CommitteeMeetingAgendaModel; +use Althingi\Model\KindEnum; use PDO; class CommitteeMeetingAgendaTest extends TestCase @@ -21,7 +22,7 @@ public function testGet() ->setAssemblyId(1) ->setCommitteeMeetingAgendaId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setTitle('title'); $service = new CommitteeMeetingAgenda(); $service->setDriver($this->pdo); @@ -37,16 +38,16 @@ public function testCreate() 'CommitteeMeetingAgenda' => [ [ 'committee_meeting_agenda_id' => 1, 'committee_meeting_id' => 1, 'issue_id' => 1, - 'category' => 'A', 'assembly_id' => 1, 'title' => 'title', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => 'title', ], [ 'committee_meeting_agenda_id' => 2, 'committee_meeting_id' => 1, 'issue_id' => null, - 'category' => 'A', 'assembly_id' => 1, 'title' => 'title', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => 'title', ], [ 'committee_meeting_agenda_id' => 3, 'committee_meeting_id' => 1, 'issue_id' => null, - 'category' => 'A', 'assembly_id' => 1, 'title' => null, + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => null, ], [ 'committee_meeting_agenda_id' => 4, 'committee_meeting_id' => 1, 'issue_id' => 1, - 'category' => 'A', 'assembly_id' => 1, 'title' => 'thetitle', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => 'thetitle', ], ], ])->getTable('CommitteeMeetingAgenda'); @@ -56,7 +57,7 @@ public function testCreate() $committeeMeetingAgenda = (new CommitteeMeetingAgendaModel()) ->setCommitteeMeetingId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setTitle('thetitle'); @@ -74,16 +75,16 @@ public function testSave() 'CommitteeMeetingAgenda' => [ [ 'committee_meeting_agenda_id' => 1, 'committee_meeting_id' => 1, 'issue_id' => 1, - 'category' => 'A', 'assembly_id' => 1, 'title' => 'title' + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => 'title' ], [ 'committee_meeting_agenda_id' => 2, 'committee_meeting_id' => 1, 'issue_id' => null, - 'category' => 'A', 'assembly_id' => 1, 'title' => 'title' + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => 'title' ], [ 'committee_meeting_agenda_id' => 3, 'committee_meeting_id' => 1, 'issue_id' => null, - 'category' => 'A', 'assembly_id' => 1, 'title' => null + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => null ], [ 'committee_meeting_agenda_id' => 4, 'committee_meeting_id' => 1, 'issue_id' => 1, - 'category' => 'A', 'assembly_id' => 1, 'title' => 'thetitle' + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => 'thetitle' ], ], ])->getTable('CommitteeMeetingAgenda'); @@ -93,7 +94,7 @@ public function testSave() $committeeMeetingAgenda = (new CommitteeMeetingAgendaModel()) ->setCommitteeMeetingId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setTitle('thetitle'); @@ -111,13 +112,13 @@ public function testUpdate() 'CommitteeMeetingAgenda' => [ [ 'committee_meeting_agenda_id' => 1, 'committee_meeting_id' => 1, 'issue_id' => 1, - 'category' => 'A', 'assembly_id' => 1, 'title' => 'thisismynewtitle' + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => 'thisismynewtitle' ], [ 'committee_meeting_agenda_id' => 2, 'committee_meeting_id' => 1, 'issue_id' => null, - 'category' => 'A', 'assembly_id' => 1, 'title' => 'title' + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => 'title' ], [ 'committee_meeting_agenda_id' => 3, 'committee_meeting_id' => 1, 'issue_id' => null, - 'category' => 'A', 'assembly_id' => 1, 'title' => null + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'title' => null ], ], ])->getTable('CommitteeMeetingAgenda'); @@ -128,7 +129,7 @@ public function testUpdate() ->setCommitteeMeetingAgendaId(1) ->setCommitteeMeetingId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setTitle('thisismynewtitle'); @@ -148,7 +149,7 @@ protected function getDataSet() ['assembly_id' => 2, 'from' => '2000-01-01'], ], 'Issue' => [ - ['issue_id' => 1, 'assembly_id' => 1, 'category' => 'A'], + ['issue_id' => 1, 'assembly_id' => 1, 'kind' => KindEnum::A->value], ], 'Committee' => [ ['committee_id' => 1, 'name' => 'committee1', 'first_assembly_id' => 1], @@ -166,13 +167,13 @@ protected function getDataSet() 'CommitteeMeetingAgenda' => [ [ 'committee_meeting_agenda_id' => 1, 'committee_meeting_id' => 1, - 'issue_id' => 1, 'assembly_id' => 1, 'title' => 'title', 'category' => 'A' + 'issue_id' => 1, 'assembly_id' => 1, 'title' => 'title', 'kind' => KindEnum::A->value ], [ 'committee_meeting_agenda_id' => 2, 'committee_meeting_id' => 1, - 'issue_id' => null, 'assembly_id' => 1, 'title' => 'title', 'category' => 'A' + 'issue_id' => null, 'assembly_id' => 1, 'title' => 'title', 'kind' => KindEnum::A->value ], [ 'committee_meeting_agenda_id' => 3, 'committee_meeting_id' => 1, - 'issue_id' => null, 'assembly_id' => 1, 'title' => null, 'category' => 'A' + 'issue_id' => null, 'assembly_id' => 1, 'title' => null, 'kind' => KindEnum::A->value ], ], ]); diff --git a/tests/Service/CongressmanDocumentTest.php b/tests/Service/CongressmanDocumentTest.php index 6687262c..b0c3eeb8 100644 --- a/tests/Service/CongressmanDocumentTest.php +++ b/tests/Service/CongressmanDocumentTest.php @@ -8,6 +8,7 @@ use Althingi\DatabaseConnection; use Althingi\Events\AddEvent; use Althingi\Events\UpdateEvent; +use Althingi\Model\KindEnum; use Psr\EventDispatcher\EventDispatcherInterface; use Mockery; use PDO; @@ -25,7 +26,7 @@ public function testGet() $expectedData = (new CongressmanDocumentModel()) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setCongressmanId(1) ->setOrder(1); @@ -39,7 +40,7 @@ public function testCreate() $congressman = (new CongressmanDocumentModel()) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setCongressmanId(2) ->setOrder(2); @@ -47,10 +48,10 @@ public function testCreate() $expectedTable = $this->createArrayDataSet([ 'Document_has_Congressman' => [ [ - 'document_id' => 1, 'issue_id' => 1, 'category' => 'A', + 'document_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'congressman_id' => 1, 'minister' => null, 'order' => 1 ], [ - 'document_id' => 1, 'issue_id' => 1, 'category' => 'A', + 'document_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'congressman_id' => 2, 'minister' => null, 'order' => 2 ], ], @@ -70,7 +71,7 @@ public function testSave() $congressman = (new CongressmanDocumentModel()) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setCongressmanId(2) ->setOrder(2); @@ -78,10 +79,10 @@ public function testSave() $expectedTable = $this->createArrayDataSet([ 'Document_has_Congressman' => [ [ - 'document_id' => 1, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'congressman_id' => 1, 'minister' => null, 'order' => 1 ], [ - 'document_id' => 1, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'congressman_id' => 2, 'minister' => null, 'order' => 2 ], ], @@ -101,7 +102,7 @@ public function testUpdate() $congressman = (new CongressmanDocumentModel()) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setCongressmanId(1) ->setMinister('hello') @@ -110,7 +111,7 @@ public function testUpdate() $expectedTable = $this->createArrayDataSet([ 'Document_has_Congressman' => [ [ - 'document_id' => 1, 'issue_id' => 1, 'category' => 'A' ,'assembly_id' => 1, + 'document_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value ,'assembly_id' => 1, 'congressman_id' => 1, 'minister' => 'hello', 'order' => 2 ] ], @@ -139,7 +140,7 @@ public function testCreateFireEventOne() $congressman = (new CongressmanDocumentModel()) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setCongressmanId(2) ->setOrder(2); @@ -165,7 +166,7 @@ public function testUpdateFireEventOne() $congressman = (new CongressmanDocumentModel()) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setCongressmanId(1) ->setOrder(2); @@ -190,7 +191,7 @@ public function testUpdateFireEventZero() $congressman = (new CongressmanDocumentModel()) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setCongressmanId(1) ->setOrder(1); @@ -216,7 +217,7 @@ public function testSaveFireEventZero() $congressman = (new CongressmanDocumentModel()) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setCongressmanId(1) ->setOrder(1); @@ -241,7 +242,7 @@ public function testSaveFireEventOne() $congressman = (new CongressmanDocumentModel()) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setCongressmanId(1) ->setOrder(2); @@ -266,7 +267,7 @@ public function testSaveFireEventTwo() $congressman = (new CongressmanDocumentModel()) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setCongressmanId(2) ->setOrder(1); @@ -292,13 +293,13 @@ protected function getDataSet() ['congressman_id' => 4, 'name' => 'name4', 'birth' => '2000-01-01', 'death' => null], ], 'Issue' => [ - ['issue_id' => 1, 'assembly_id' => 1, 'category' => 'A'] + ['issue_id' => 1, 'assembly_id' => 1, 'kind' => KindEnum::A->value] ], 'Document' => [ [ 'document_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01', 'url' => '', @@ -309,7 +310,7 @@ protected function getDataSet() [ 'document_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'congressman_id' => 1, 'order' => 1 diff --git a/tests/Service/CongressmanTest.php b/tests/Service/CongressmanTest.php index 67957669..8aceb457 100644 --- a/tests/Service/CongressmanTest.php +++ b/tests/Service/CongressmanTest.php @@ -16,6 +16,7 @@ use Mockery; use Psr\EventDispatcher\EventDispatcherInterface; use Althingi\Events\{UpdateEvent, AddEvent}; +use Althingi\Model\KindEnum; class CongressmanTest extends TestCase { @@ -535,14 +536,14 @@ protected function getDataSet() ], ], 'Issue' => [ - ['issue_id' => 1, 'assembly_id' => 1, 'category' => 'A'] + ['issue_id' => 1, 'assembly_id' => 1, 'kind' => KindEnum::A->value] ], 'Document' => [ [ 'document_id' => 1, 'issue_id' => 1, 'assembly_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'date' => '2000-01-01', 'url' => '', 'type' => '' @@ -553,7 +554,7 @@ protected function getDataSet() 'document_id' => 1, 'issue_id' => 1, 'assembly_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'order' => 1 ] @@ -567,7 +568,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => '2001-01-01 00:00:00', 'to' => '2001-01-01 00:01:00', diff --git a/tests/Service/DocumentTest.php b/tests/Service/DocumentTest.php index 2a36f188..2df4cd71 100644 --- a/tests/Service/DocumentTest.php +++ b/tests/Service/DocumentTest.php @@ -8,6 +8,7 @@ use Althingi\Events\UpdateEvent; use PHPUnit\Framework\TestCase; use Althingi\Model\Document as DocumentModel; +use Althingi\Model\KindEnum; use Mockery; use PDO; use Psr\EventDispatcher\EventDispatcherInterface; @@ -26,7 +27,7 @@ public function testGet() $expectedData = (new DocumentModel()) ->setDocumentId(1) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setIssueId(1) ->setDate(new \DateTime('2000-01-01')) ->setType('type') @@ -53,7 +54,7 @@ public function testCreate() ->setAssemblyId(1) ->setDocumentId(5) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2000-01-01')) ->setType('type') ->setUrl('http://url.com'); @@ -65,19 +66,19 @@ public function testCreate() $expectedTable = $this->createArrayDataSet([ 'Document' => [ [ - 'document_id' => 1, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 2, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 2, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 3, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 3, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 4, 'issue_id' => 2, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 4, 'issue_id' => 2, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 5, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 5, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], ] @@ -94,7 +95,7 @@ public function testSave() ->setAssemblyId(1) ->setDocumentId(5) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2000-01-01')) ->setType('type') ->setUrl('http://url.com'); @@ -106,19 +107,19 @@ public function testSave() $expectedTable = $this->createArrayDataSet([ 'Document' => [ [ - 'document_id' => 1, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 2, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 2, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 3, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 3, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 4, 'issue_id' => 2, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 4, 'issue_id' => 2, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 5, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 5, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], ] @@ -134,7 +135,7 @@ public function testUpdate() ->setDocumentId(1) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2000-01-01')) ->setType('thisismytype') ->setUrl('http://url.com'); @@ -146,16 +147,16 @@ public function testUpdate() $expectedTable = $this->createArrayDataSet([ 'Document' => [ [ - 'document_id' => 1, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'thisismytype' ], [ - 'document_id' => 2, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 2, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 3, 'issue_id' => 1, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 3, 'issue_id' => 1, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 4, 'issue_id' => 2, 'category' => 'A', 'assembly_id' => 1, + 'document_id' => 4, 'issue_id' => 2, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], ] @@ -180,7 +181,7 @@ public function testCreateFireEventResourceCreated() ->setAssemblyId(1) ->setDocumentId(5) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2000-01-01')) ->setType('type') ->setUrl('http://url.com'); @@ -206,7 +207,7 @@ public function testUpdateFireEventZeroResourceFoundButNoUpdateRequired() ->setAssemblyId(1) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2000-01-01')) ->setType('type') ->setUrl('http://url.com'); @@ -232,7 +233,7 @@ public function testUpdateFireEventOneResourceFoundAndAnUpdateRequired() ->setAssemblyId(1) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2000-01-01')) ->setType('type') ->setUrl('http://url.com/add-to-url'); @@ -258,7 +259,7 @@ public function testSaveFireEventZeroResourceFoundButNoUpdateRequired() ->setAssemblyId(1) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2000-01-01')) ->setType('type') ->setUrl('http://url.com'); @@ -284,7 +285,7 @@ public function testSaveFireEventOneNeedsToBeCreated() ->setAssemblyId(1) ->setDocumentId(5) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2000-01-01')) ->setType('type') ->setUrl('http://url.com'); @@ -310,7 +311,7 @@ public function testSaveFireEventTwoCresourceFoundAndNeedsToBeUpdated() ->setAssemblyId(1) ->setDocumentId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2000-01-01')) ->setType('type') ->setUrl('http://url.com/update'); @@ -328,21 +329,21 @@ protected function getDataSet() ['assembly_id' => 1, 'from' => '2000-01-01', 'to' => null] ], 'Issue' => [ - ['issue_id' => 1, 'assembly_id' => 1, 'category' => 'A' ,], - ['issue_id' => 2, 'assembly_id' => 1, 'category' => 'A' ,], + ['issue_id' => 1, 'assembly_id' => 1, 'kind' => KindEnum::A->value ,], + ['issue_id' => 2, 'assembly_id' => 1, 'kind' => KindEnum::A->value ,], ], 'Document' => [ [ - 'document_id' => 1, 'issue_id' => 1, 'category' => 'A' ,'assembly_id' => 1, + 'document_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value ,'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 2, 'issue_id' => 1, 'category' => 'A' ,'assembly_id' => 1, + 'document_id' => 2, 'issue_id' => 1, 'kind' => KindEnum::A->value ,'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 3, 'issue_id' => 1, 'category' => 'A' ,'assembly_id' => 1, + 'document_id' => 3, 'issue_id' => 1, 'kind' => KindEnum::A->value ,'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], [ - 'document_id' => 4, 'issue_id' => 2, 'category' => 'A' ,'assembly_id' => 1, + 'document_id' => 4, 'issue_id' => 2, 'kind' => KindEnum::A->value ,'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type' ], ] diff --git a/tests/Service/IssueCategoryTest.php b/tests/Service/IssueCategoryTest.php index c1b0a24f..8c4783b6 100644 --- a/tests/Service/IssueCategoryTest.php +++ b/tests/Service/IssueCategoryTest.php @@ -8,6 +8,7 @@ use Althingi\DatabaseConnection; use Althingi\Events\AddEvent; use Althingi\Events\UpdateEvent; +use Althingi\Model\KindEnum; use Mockery; use PHPUnit\Framework\TestCase; use PDO; @@ -40,7 +41,7 @@ public function testCreate() $issueCategory = (new IssueCategoryModel()) ->setAssemblyId(145) ->setIssueId(2) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCategoryId(34); $service->create($issueCategory); @@ -57,7 +58,7 @@ public function testSave() $issueCategory = (new IssueCategoryModel()) ->setAssemblyId(145) ->setIssueId(2) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCategoryId(34); $service->save($issueCategory); @@ -74,7 +75,7 @@ public function testUpdate() $issueCategory = (new IssueCategoryModel()) ->setAssemblyId(145) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCategoryId(1); $service->update($issueCategory); @@ -112,7 +113,7 @@ public function testCreateFireEventResourceCreated() $issueCategory = (new IssueCategoryModel()) ->setAssemblyId(145) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCategoryId(2); (new IssueCategory()) @@ -136,7 +137,7 @@ public function testUpdateFireEventResourceFoundButNoUpdateRequired() $issueCategory = (new IssueCategoryModel()) ->setAssemblyId(145) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCategoryId(1); (new IssueCategory()) @@ -160,7 +161,7 @@ public function testSaveFireEventResourceAdded() $issueCategory = (new IssueCategoryModel()) ->setAssemblyId(145) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCategoryId(2); (new IssueCategory()) @@ -184,7 +185,7 @@ public function testSaveFireEventResourceFoundButNoNeedForAnUpdate() $issueCategory = (new IssueCategoryModel()) ->setAssemblyId(145) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCategoryId(1); (new IssueCategory()) @@ -265,7 +266,7 @@ protected function getDataSet() 'issue_id' => 1, 'assembly_id' => 145, 'congressman_id' => null, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'name' => '', 'sub_name' => '', 'type' => '', @@ -277,7 +278,7 @@ protected function getDataSet() 'issue_id' => 2, 'assembly_id' => 145, 'congressman_id' => null, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'name' => '', 'sub_name' => '', 'type' => '', @@ -288,7 +289,7 @@ protected function getDataSet() ], ], 'Category_has_Issue' => [ - ['category_id' => 1, 'issue_id' => 1, 'assembly_id' => 145, 'category' => 'A'], + ['category_id' => 1, 'issue_id' => 1, 'assembly_id' => 145, 'kind' => KindEnum::A->value], ], 'Speech' => [ [ @@ -296,7 +297,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 145, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => '2000-01-01 00:00:00', 'to' => null, @@ -305,7 +306,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 145, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => null, 'to' => '2000-01-01 00:0:10', @@ -314,7 +315,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 145, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => '2000-01-01 00:00:00', 'to' => '2000-01-01 00:0:10', @@ -323,7 +324,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 145, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => '2000-01-01 00:00:00', 'to' => '2000-01-01 00:0:10', diff --git a/tests/Service/IssueTest.php b/tests/Service/IssueTest.php index 593d1010..c72767d9 100644 --- a/tests/Service/IssueTest.php +++ b/tests/Service/IssueTest.php @@ -10,6 +10,7 @@ use PHPUnit\Framework\TestCase; use Althingi\Model\Issue as IssueModel; use Althingi\Model\IssueAndDate as IssueAndDateModel; +use Althingi\Model\KindEnum; use Mockery; use PDO; use Psr\EventDispatcher\EventDispatcherInterface; @@ -33,7 +34,7 @@ public function testGet() ->setType('l') ->setTypeSubname('something') ->setStatus('some') - ->setCategory('A') + ->setKind(KindEnum::A) ->setDate(new \DateTime('2000-01-01')); $this->assertEquals($expectedDataWithDate, $actualDataWithDate); } @@ -43,7 +44,7 @@ public function testGetB() $service = new Issue(); $service->setDriver($this->pdo); - $expectedDataWithDate = $service->getWithDate(1, 1, 'B'); + $expectedDataWithDate = $service->getWithDate(1, 1, KindEnum::B); $actualDataWithDate = (new IssueAndDateModel()) ->setIssueId(1) ->setAssemblyId(1) @@ -51,7 +52,7 @@ public function testGetB() ->setType(null) ->setTypeSubname(null) ->setStatus(null) - ->setCategory('B') + ->setKind(KindEnum::B) ->setDate(null); $this->assertEquals($expectedDataWithDate, $actualDataWithDate); } @@ -83,7 +84,7 @@ public function testGetByAssemblyB() $service = new Issue(); $service->setDriver($this->pdo); - $issues = $service->fetchByAssembly(1, 0, 25, null, [], [], ['B']); + $issues = $service->fetchByAssembly(1, 0, 25, null, [], [], [KindEnum::B]); $this->assertCount(1, $issues); $this->assertInstanceOf(IssueAndDateModel::class, $issues[0]); @@ -94,7 +95,7 @@ public function testGetByAssemblyBandA() $service = new Issue(); $service->setDriver($this->pdo); - $issues = $service->fetchByAssembly(1, 0, 25, null, [], [], ['A', 'B']); + $issues = $service->fetchByAssembly(1, 0, 25, null, [], [], [KindEnum::A, KindEnum::B]); $this->assertCount(4, $issues); $this->assertInstanceOf(IssueAndDateModel::class, $issues[0]); @@ -183,7 +184,8 @@ public function testCreate() $issue = (new IssueModel()) ->setAssemblyId(1) ->setIssueId(4) - ->setCategory('A'); + ->setKind(KindEnum::A) + ; $issueService = new Issue(); $issueService->setDriver($this->pdo); @@ -217,7 +219,8 @@ public function testSave() ->setAssemblyId(1) ->setIssueId(4) ->setType('ab') - ->setCategory('A'); + ->setKind(KindEnum::A) + ; $issueService = new Issue(); $issueService->setDriver($this->pdo); @@ -250,7 +253,7 @@ public function testUpdate() $issue = (new IssueModel()) ->setAssemblyId(1) ->setIssueId(3) - ->setCategory('A') + ->setKind(KindEnum::A) ->setStatus('awesome'); $issueService = new Issue(); @@ -266,13 +269,13 @@ public function testUpdate() 'type' => null, 'status' => 'awesome', 'type_subname' => null, - 'category' => 'A' + 'kind' => KindEnum::A->value ], ], ])->getTable('Issue'); $queryTable = $this->getConnection()->createQueryTable( 'Issue', - 'SELECT `issue_id`, `assembly_id`, `congressman_id`, `type`, `status`, `type_subname`, `category` + 'SELECT `issue_id`, `assembly_id`, `congressman_id`, `type`, `status`, `type_subname`, `kind` FROM Issue WHERE issue_id = 3 AND assembly_id = 1' ); @@ -294,7 +297,8 @@ public function testCreateFireEventResourceCreated() $issue = (new IssueModel()) ->setAssemblyId(1) ->setIssueId(4) - ->setCategory('A'); + ->setKind(KindEnum::A) + ; (new Issue()) ->setDriver($this->pdo) @@ -316,7 +320,7 @@ public function testUpdateFireEventResourceFoundButNoUpdateRequired() $issue = (new IssueModel()) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setType('l') ->setStatus('some') @@ -343,7 +347,7 @@ public function testUpdateFireEventResourceFoundAndUpdateIsNeeded() $issue = (new IssueModel()) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setType('l') ->setStatus('some') @@ -370,7 +374,7 @@ public function testSaveFireEventResourceCreated() $issue = (new IssueModel()) ->setAssemblyId(1) ->setIssueId(4) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setType('l') ->setStatus('some') @@ -397,7 +401,7 @@ public function testSaveFireEventResourceFoundNoUpdateRequired() $issue = (new IssueModel()) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setType('l') ->setStatus('some') @@ -424,7 +428,7 @@ public function testSaveFireEventResourceFoundUpdateNeeded() $issue = (new IssueModel()) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setType('l') ->setStatus('some') @@ -452,7 +456,7 @@ protected function getDataSet() [ 'issue_id' => 1, 'assembly_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'type' => 'l', 'status' => 'some', @@ -460,23 +464,23 @@ protected function getDataSet() ], [ 'issue_id' => 2, 'assembly_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'type' => 'l', 'status' => 'some', 'type_subname' => 'stjórnarfrumvarp' ], - ['issue_id' => 3, 'assembly_id' => 1, 'category' => 'A'], - ['issue_id' => 1, 'assembly_id' => 2, 'category' => 'A'], + ['issue_id' => 3, 'assembly_id' => 1, 'kind' => KindEnum::A->value], + ['issue_id' => 1, 'assembly_id' => 2, 'kind' => KindEnum::A->value], - ['issue_id' => 1, 'assembly_id' => 1, 'category' => 'B'], - ['issue_id' => 1, 'assembly_id' => 2, 'category' => 'B'], + ['issue_id' => 1, 'assembly_id' => 1, 'kind' => KindEnum::B->value], + ['issue_id' => 1, 'assembly_id' => 2, 'kind' => KindEnum::B->value], ], 'Document' => [ [ 'document_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01', 'url' => '', @@ -484,7 +488,7 @@ protected function getDataSet() ], [ 'document_id' => 2, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-02', 'url' => '', @@ -492,7 +496,7 @@ protected function getDataSet() ], [ 'document_id' => 3, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-03', 'url' => '', diff --git a/tests/Service/PartyTest.php b/tests/Service/PartyTest.php index 91d7f8e9..c4b6aa6f 100644 --- a/tests/Service/PartyTest.php +++ b/tests/Service/PartyTest.php @@ -6,6 +6,7 @@ use Althingi\DatabaseConnection; use Althingi\Events\AddEvent; use Althingi\Events\UpdateEvent; +use Althingi\Model\KindEnum; use PHPUnit\Framework\TestCase; use Althingi\Model\Party as PartyModel; use Althingi\Model\PartyAndTime as PartyAndTimeModel; @@ -416,7 +417,7 @@ protected function getDataSet() ['cabinet_id' => 1, 'congressman_id' => 1, 'title' => 'dude', 'from' => '2000-01-01'] ], 'Issue' => [ - ['issue_id' => 1, 'assembly_id' => 1, 'category' => 'A'], + ['issue_id' => 1, 'assembly_id' => 1, 'kind' => KindEnum::A->value], ], 'Plenary' => [ ['plenary_id' => 1, 'assembly_id' => 1], @@ -427,7 +428,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => '2001-01-01 01:00:00', 'to' => '2001-01-01 01:10:00' diff --git a/tests/Service/SessionTest.php b/tests/Service/SessionTest.php index bf701521..8eff61bd 100644 --- a/tests/Service/SessionTest.php +++ b/tests/Service/SessionTest.php @@ -6,6 +6,7 @@ use Althingi\DatabaseConnection; use Althingi\Events\AddEvent; use Althingi\Events\UpdateEvent; +use Althingi\Model\KindEnum; use PHPUnit\Framework\TestCase; use Althingi\Model\Session as SessionModel; use Mockery; @@ -536,7 +537,7 @@ protected function getDataSet() ], ], 'Issue' => [ - ['issue_id' => 1, 'assembly_id' => 1, 'category' => 'A'], + ['issue_id' => 1, 'assembly_id' => 1, 'kind' => KindEnum::A->value], ], 'Plenary' => [ ['plenary_id' => 1, 'assembly_id' => 1], diff --git a/tests/Service/SpeechTest.php b/tests/Service/SpeechTest.php index 02721163..93ba6132 100644 --- a/tests/Service/SpeechTest.php +++ b/tests/Service/SpeechTest.php @@ -10,6 +10,7 @@ use Althingi\Model\Speech as SpeechModel; use Althingi\Model\SpeechAndPosition as SpeechAndPositionModel; use Althingi\Model\DateAndCount as DateAndCountModel; +use Althingi\Model\KindEnum; use Mockery; use PDO; use Psr\EventDispatcher\EventDispatcherInterface; @@ -29,7 +30,7 @@ public function testGetSpeech() ->setSpeechId('id--00001') ->setAssemblyId(1) ->setPlenaryId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setIssueId(1) ->setCongressmanId(1); @@ -60,7 +61,7 @@ public function testFetch() ->setSpeechId('id--00003') ->setAssemblyId(1) ->setPlenaryId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setIssueId(1) ->setCongressmanId(1) ->setPosition(2), @@ -69,7 +70,7 @@ public function testFetch() ->setSpeechId('id--00004') ->setAssemblyId(1) ->setPlenaryId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setIssueId(1) ->setCongressmanId(1) ->setPosition(3), @@ -102,7 +103,7 @@ public function testFetchByIssue() ->setSpeechId('id--00001') ->setAssemblyId(1) ->setPlenaryId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setIssueId(1) ->setCongressmanId(1) ->setPosition(0), @@ -111,13 +112,13 @@ public function testFetchByIssue() ->setSpeechId('id--00002') ->setAssemblyId(1) ->setPlenaryId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setIssueId(1) ->setCongressmanId(1) ->setPosition(1), ]; - $actualData = $service->fetchByIssue(1, 1, 'A', 0, 2); + $actualData = $service->fetchByIssue(1, 1, KindEnum::A, 0, 2); $this->assertEquals($expectedData, $actualData); } @@ -181,7 +182,7 @@ public function testCreate() ->setPlenaryId(1) ->setAssemblyId(3) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1); $expectedTable = $this->createArrayDataSet([ @@ -191,7 +192,7 @@ public function testCreate() 'plenary_id' => 1, 'assembly_id' => 3, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'congressman_type' => null, 'from' => null, @@ -219,7 +220,7 @@ public function testSave() $speech = (new SpeechModel()) ->setSpeechId('id--20001') ->setPlenaryId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(3) ->setIssueId(1) ->setCongressmanId(1); @@ -231,7 +232,7 @@ public function testSave() 'plenary_id' => 1, 'assembly_id' => 3, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'congressman_type' => null, 'from' => null, @@ -259,7 +260,7 @@ public function testSavePlenaryDoesntExist() $speech = (new SpeechModel()) ->setSpeechId('id--20001') ->setPlenaryId(10000) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(3) ->setIssueId(1) ->setCongressmanId(1); @@ -279,7 +280,7 @@ public function testUpdate() ->setSpeechId('id--00001') ->setPlenaryId(1) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setIssueId(1) ->setCongressmanId(2); @@ -290,7 +291,7 @@ public function testUpdate() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 2, 'congressman_type' => null, 'from' => null, @@ -329,7 +330,7 @@ public function testCreateFireEventResourceCreated() ->setPlenaryId(1) ->setAssemblyId(3) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1); (new Speech()) @@ -355,7 +356,7 @@ public function testUpdateFireEventResourceFoundNoUpdate() ->setPlenaryId(1) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setValidated(true); @@ -382,7 +383,7 @@ public function testUpdateFireEventResourceFoundUpdateNeeded() ->setPlenaryId(1) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setValidated(false); @@ -409,7 +410,7 @@ public function testSaveFireEventResourceCreated() ->setPlenaryId(1) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setValidated(false); @@ -436,7 +437,7 @@ public function testSaveFireEventResourceFoundNoUpdateNeeded() ->setPlenaryId(1) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setValidated(true); @@ -463,7 +464,7 @@ public function testSaveFireEventResourceFoundUpdateRequired() ->setPlenaryId(1) ->setAssemblyId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setCongressmanId(1) ->setValidated(false); @@ -483,14 +484,14 @@ protected function getDataSet() ['assembly_id' => 3, 'from' => '2000-01-01'], ], 'Issue' => [ - ['assembly_id' => 1, 'issue_id' => 1, 'category' => 'A',], - ['assembly_id' => 1, 'issue_id' => 2, 'category' => 'A',], - ['assembly_id' => 1, 'issue_id' => 3, 'category' => 'A',], - ['assembly_id' => 2, 'issue_id' => 1, 'category' => 'A',], - ['assembly_id' => 2, 'issue_id' => 2, 'category' => 'A',], - ['assembly_id' => 2, 'issue_id' => 3, 'category' => 'A',], - - ['assembly_id' => 3, 'issue_id' => 1, 'category' => 'A',], + ['assembly_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value,], + ['assembly_id' => 1, 'issue_id' => 2, 'kind' => KindEnum::A->value,], + ['assembly_id' => 1, 'issue_id' => 3, 'kind' => KindEnum::A->value,], + ['assembly_id' => 2, 'issue_id' => 1, 'kind' => KindEnum::A->value,], + ['assembly_id' => 2, 'issue_id' => 2, 'kind' => KindEnum::A->value,], + ['assembly_id' => 2, 'issue_id' => 3, 'kind' => KindEnum::A->value,], + + ['assembly_id' => 3, 'issue_id' => 1, 'kind' => KindEnum::A->value,], ], 'Congressman' => [ ['congressman_id' => 1, 'name' => 'congressman 1', 'birth' => '2000-01-01'], @@ -509,7 +510,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => null, 'to' => null, @@ -520,7 +521,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => null, 'to' => null, @@ -531,7 +532,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => null, 'to' => null, @@ -542,7 +543,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => null, 'to' => null, @@ -553,7 +554,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 2, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => null, 'to' => null, @@ -564,7 +565,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 2, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => '2000-01-01 00:00:00', 'to' => '2000-01-01 00:01:00', @@ -575,7 +576,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 2, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 1, 'from' => '2000-02-01 00:00:00', 'to' => '2000-02-01 00:01:00', @@ -586,7 +587,7 @@ protected function getDataSet() 'plenary_id' => 1, 'assembly_id' => 1, 'issue_id' => 2, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'congressman_id' => 2, 'from' => '2000-03-01 00:00:00', 'to' => '2000-03-01 00:01:00', diff --git a/tests/Service/VoteItemTest.php b/tests/Service/VoteItemTest.php index 42fe06b7..0c1a8eb3 100644 --- a/tests/Service/VoteItemTest.php +++ b/tests/Service/VoteItemTest.php @@ -8,6 +8,7 @@ use Althingi\DatabaseConnection; use Althingi\Events\AddEvent; use Althingi\Events\UpdateEvent; +use Althingi\Model\KindEnum; use Mockery; use PHPUnit\Framework\TestCase; use PDO; @@ -309,12 +310,12 @@ protected function getDataSet() ['assembly_id' => 2, 'from' => '2000-01-01', 'to' => null], ], 'Issue' => [ - ['assembly_id' => 1, 'issue_id' => 1, 'category' => 'A'], - ['assembly_id' => 1, 'issue_id' => 2, 'category' => 'A'], - ['assembly_id' => 1, 'issue_id' => 3, 'category' => 'A'], - ['assembly_id' => 2, 'issue_id' => 1, 'category' => 'A'], - ['assembly_id' => 2, 'issue_id' => 2, 'category' => 'A'], - ['assembly_id' => 2, 'issue_id' => 3, 'category' => 'A'], + ['assembly_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value], + ['assembly_id' => 1, 'issue_id' => 2, 'kind' => KindEnum::A->value], + ['assembly_id' => 1, 'issue_id' => 3, 'kind' => KindEnum::A->value], + ['assembly_id' => 2, 'issue_id' => 1, 'kind' => KindEnum::A->value], + ['assembly_id' => 2, 'issue_id' => 2, 'kind' => KindEnum::A->value], + ['assembly_id' => 2, 'issue_id' => 3, 'kind' => KindEnum::A->value], ], 'Congressman' => [ ['congressman_id' => 1, 'name' => '', 'birth' => '2001-01-01'], @@ -328,7 +329,7 @@ protected function getDataSet() 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type', - 'category' => 'A' + 'kind' => KindEnum::A->value ], [ 'document_id' => 2, 'issue_id' => 1, @@ -336,7 +337,7 @@ protected function getDataSet() 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type', - 'category' => 'A' + 'kind' => KindEnum::A->value ], [ 'document_id' => 3, 'issue_id' => 1, @@ -344,7 +345,7 @@ protected function getDataSet() 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type', - 'category' => 'A' + 'kind' => KindEnum::A->value ], [ 'document_id' => 4, 'issue_id' => 2, @@ -352,7 +353,7 @@ protected function getDataSet() 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', 'type' => 'type', - 'category' => 'A' + 'kind' => KindEnum::A->value ], ], 'Vote' => [ @@ -362,14 +363,14 @@ protected function getDataSet() 'assembly_id' => 1, 'document_id' => 1, 'date' => '2000-01-01', - 'category' => 'A' + 'kind' => KindEnum::A->value ], [ 'vote_id' => 2, 'issue_id' => 1, 'assembly_id' => 1, 'document_id' => 2, 'date' => '2000-02-01', - 'category' => 'A' + 'kind' => KindEnum::A->value ], ], 'VoteItem' => [ diff --git a/tests/Service/VoteTest.php b/tests/Service/VoteTest.php index e5ebe8e2..256ff707 100644 --- a/tests/Service/VoteTest.php +++ b/tests/Service/VoteTest.php @@ -10,6 +10,7 @@ use Althingi\Events\UpdateEvent; use PHPUnit\Framework\TestCase; use Althingi\Model\DateAndCount as DateAndCountModel; +use Althingi\Model\KindEnum; use DateTime; use Mockery; use PDO; @@ -29,7 +30,7 @@ public function testVote() $expectedData = (new VoteModel()) ->setVoteId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setDocumentId(1) ->setDate(new \DateTime('2000-01-01T00:01:00')); @@ -58,14 +59,14 @@ public function testFetchByIssue() (new VoteModel()) ->setVoteId(1) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setDocumentId(1) ->setDate(new \DateTime('2000-01-01T00:01:00')), (new VoteModel()) ->setVoteId(2) ->setIssueId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setDocumentId(2) ->setDate(new \DateTime('2000-02-01')), @@ -112,7 +113,7 @@ public function testFetchByDocument() $expectedData = [(new VoteModel()) ->setVoteId(7) ->setIssueId(2) - ->setCategory('A') + ->setKind(KindEnum::A) ->setAssemblyId(1) ->setDocumentId(2)]; $actualData = $service->fetchByDocument(1, 2, 2); @@ -126,7 +127,7 @@ public function testCreate() ->setVoteId(9) ->setIssueId(2) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setYes(0) ->setNo(0) ->setInaction(0) @@ -155,7 +156,7 @@ public function testSave() ->setVoteId(9) ->setIssueId(2) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setYes(0) ->setNo(0) ->setInaction(0) @@ -184,7 +185,7 @@ public function testUpdate() ->setVoteId(1) ->setIssueId(1) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setYes(0) ->setNo(0) ->setInaction(0) @@ -268,7 +269,7 @@ public function testCreateFireEventResourceCreated() ->setVoteId(9) ->setIssueId(2) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setYes(0) ->setNo(0) ->setInaction(0) @@ -295,7 +296,7 @@ public function testUpdateFireEventResourceFoundNoUpdateNeeded() ->setVoteId(1) ->setIssueId(1) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setYes(0) ->setNo(0) ->setInaction(0) @@ -326,7 +327,7 @@ public function testUpdateFireEventResourceFoundUpdatedRequired() ->setVoteId(1) ->setIssueId(1) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setYes(0) ->setNo(0) ->setInaction(0) @@ -354,7 +355,7 @@ public function testSaveFireEventResourceCreated() ->setVoteId(100) ->setIssueId(1) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setYes(0) ->setNo(0) ->setInaction(0) @@ -382,7 +383,7 @@ public function testSaveFireEventResourceFoundNoUpdatedNeeded() ->setVoteId(1) ->setIssueId(1) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setYes(0) ->setNo(0) ->setInaction(0) @@ -410,7 +411,7 @@ public function testSaveFireEventResourceFoundUpdateRequired() ->setVoteId(1) ->setIssueId(1) ->setAssemblyId(1) - ->setCategory('A') + ->setKind(KindEnum::A) ->setYes(0) ->setNo(0) ->setInaction(0) @@ -437,17 +438,17 @@ protected function getDataSet() ['congressman_id' => 4, 'name' => 'name4', 'birth' => '2000-01-01', 'death' => null], ], 'Issue' => [ - ['assembly_id' => 1, 'issue_id' => 1, 'category' => 'A'], - ['assembly_id' => 1, 'issue_id' => 2, 'category' => 'A'], - ['assembly_id' => 1, 'issue_id' => 3, 'category' => 'A'], - ['assembly_id' => 2, 'issue_id' => 1, 'category' => 'A'], - ['assembly_id' => 2, 'issue_id' => 2, 'category' => 'A'], - ['assembly_id' => 2, 'issue_id' => 3, 'category' => 'A'], + ['assembly_id' => 1, 'issue_id' => 1, 'kind' => KindEnum::A->value], + ['assembly_id' => 1, 'issue_id' => 2, 'kind' => KindEnum::A->value], + ['assembly_id' => 1, 'issue_id' => 3, 'kind' => KindEnum::A->value], + ['assembly_id' => 2, 'issue_id' => 1, 'kind' => KindEnum::A->value], + ['assembly_id' => 2, 'issue_id' => 2, 'kind' => KindEnum::A->value], + ['assembly_id' => 2, 'issue_id' => 3, 'kind' => KindEnum::A->value], ], 'Document' => [ ['document_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', @@ -455,7 +456,7 @@ protected function getDataSet() ], [ 'document_id' => 2, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', @@ -463,7 +464,7 @@ protected function getDataSet() ], [ 'document_id' => 3, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', @@ -471,7 +472,7 @@ protected function getDataSet() ], [ 'document_id' => 4, 'issue_id' => 2, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'date' => '2000-01-01 00:00:00', 'url' => 'http://url.com', @@ -482,24 +483,24 @@ protected function getDataSet() [ 'vote_id' => 1, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'document_id' => 1, 'date' => '2000-01-01T00:01:00' ], [ 'vote_id' => 2, 'issue_id' => 1, - 'category' => 'A', + 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'document_id' => 2, 'date' => '2000-02-01' ], - ['vote_id' => 3, 'issue_id' => 2, 'category' => 'A', 'assembly_id' => 1, 'document_id' => 1], - ['vote_id' => 4, 'issue_id' => 2, 'category' => 'A', 'assembly_id' => 1, 'document_id' => 1], - ['vote_id' => 5, 'issue_id' => 2, 'category' => 'A', 'assembly_id' => 1, 'document_id' => 1], - ['vote_id' => 6, 'issue_id' => 2, 'category' => 'A', 'assembly_id' => 1, 'document_id' => 1], - ['vote_id' => 7, 'issue_id' => 2, 'category' => 'A', 'assembly_id' => 1, 'document_id' => 2], - ['vote_id' => 8, 'issue_id' => 2, 'category' => 'A', 'assembly_id' => 2, 'document_id' => 2], + ['vote_id' => 3, 'issue_id' => 2, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'document_id' => 1], + ['vote_id' => 4, 'issue_id' => 2, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'document_id' => 1], + ['vote_id' => 5, 'issue_id' => 2, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'document_id' => 1], + ['vote_id' => 6, 'issue_id' => 2, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'document_id' => 1], + ['vote_id' => 7, 'issue_id' => 2, 'kind' => KindEnum::A->value, 'assembly_id' => 1, 'document_id' => 2], + ['vote_id' => 8, 'issue_id' => 2, 'kind' => KindEnum::A->value, 'assembly_id' => 2, 'document_id' => 2], ], 'VoteItem' => [ ['vote_id' => 1, 'congressman_id' => 1, 'vote' => 'ja', 'vote_item_id' => 1],