Skip to content

Commit

Permalink
VSVGVQ-54 Merge branch 'master' into feature/VSVGVQ-54
Browse files Browse the repository at this point in the history
* master: (24 commits)
  VSVGVQ-59 Fix PHPStan warning.
  VSVGVQ-59 Make sure to keep the existing password when updating a user.
  VSVGVQ-59 Add header docs to password value object.
  VSVGVQ-59 Exclude UserFormType from code coverage.
  VSVGVQ-59 Add basic unit test for user form.
  VSVGVQ-59 Add a trait to create the extensions for testing a form.
  VSVGVQ-56 Add extra index parameter on answer.
  VSVGVQ-56 Add EntityNotFoundException header comment on it_can_update_a_category.
  VSVGVQ-56 Add createUpdatedAccidentQuestion and use in unit tests.
  VSVGVQ-56 Clean up comments about update/merge.
  VSVGVQ-59 Add route to update an existing user.
  VSVGVQ-59 Add simple Roles class to manage roles.
  VSVGVQ-59 Add a basic export to CSV for users.
  VSVGVQ-56: add comment why we first do a find in update function of user, question and category repositories
  VSVGVQ-59 Add a few basic unit tests with specials characters for user serialization to json and csv.
  VSVGVQ-56: add tests for updating non-existing user, question and category
  VSVGVQ-56: add test for updating question with non-existing category
  VSVGVQ-59 Make it possible to normalize user and users to CSV.
  VSVGVQ-59 Add locale files for datatable and load based on the locale (taken from path).
  VSVGVQ-59 Add base template for index view of admins.
  ...

# Conflicts:
#	phpunit.xml
#	src/Company/Repositories/CompanyDoctrineRepository.php
#	src/User/ValueObjects/Password.php
  • Loading branch information
Luc Wollants committed Jun 13, 2018
2 parents 7952b13 + a15e0c2 commit f7c546e
Show file tree
Hide file tree
Showing 41 changed files with 1,257 additions and 237 deletions.
12 changes: 12 additions & 0 deletions config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,15 @@ users_view_index:
methods: [GET]
requirements:
_locale: nl|fr
users_view_edit:
path: /{_locale}/view/users/edit/{id}
controller: VSV\GVQ_API\User\Controllers\UserViewController::edit
methods: [GET, POST]
requirements:
_locale: nl|fr
users_export:
path: /{_locale}/csv/users
controller: VSV\GVQ_API\User\Controllers\UserViewController::export
methods: [GET]
requirements:
_locale: nl|fr
5 changes: 5 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ services:
$uuidFactory: '@uuid_factory'
tags: ['controller.service_arguments']

VSV\GVQ_API\User\Controllers\UserViewController:
arguments:
$uuidFactory: '@uuid_factory'
tags: ['controller.service_arguments']

VSV\GVQ_API\Image\Controllers\ImageController:
arguments:
$fileSystem: '@local_fly_system'
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<file>./src/Question/Controllers/QuestionViewController.php</file>
<file>./src/Question/Forms/QuestionFormType.php</file>
<file>./src/User/Controllers/UserViewController.php</file>
<file>./src/User/Forms/UserFormType.php</file>
<file>./src/Account/Controllers/AccountViewController.php</file>
<file>./src/Account/Forms/RegistrationFormType.php</file>
</exclude>
Expand Down
28 changes: 28 additions & 0 deletions public/js/bootstrap-table-fr-BE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Bootstrap Table French (Belgium) translation
* Author: Julien Bisconti (julien.bisconti@gmail.com)
*/
(function ($) {
'use strict';

$.fn.bootstrapTable.locales['fr-BE'] = {
formatLoadingMessage: function () {
return 'Chargement en cours...';
},
formatRecordsPerPage: function (pageNumber) {
return pageNumber + ' entrées par page';
},
formatShowingRows: function (pageFrom, pageTo, totalRows) {
return 'Affiche de ' + pageFrom + ' à ' + pageTo + ' sur ' + totalRows + ' lignes';
},
formatSearch: function () {
return 'Recherche';
},
formatNoMatches: function () {
return 'Pas de fichiers trouvés';
}
};

$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['fr-BE']);

})(jQuery);
52 changes: 52 additions & 0 deletions public/js/bootstrap-table-nl-NL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Bootstrap Table Dutch translation
* Author: Your Name <info@a2hankes.nl>
*/
(function($) {
'use strict';

$.fn.bootstrapTable.locales['nl-NL'] = {
formatLoadingMessage: function() {
return 'Laden, even geduld...';
},
formatRecordsPerPage: function(pageNumber) {
return pageNumber + ' records per pagina';
},
formatShowingRows: function(pageFrom, pageTo, totalRows) {
return 'Toon ' + pageFrom + ' tot ' + pageTo + ' van ' + totalRows + ' record' + ((totalRows > 1) ? 's' : '');
},
formatDetailPagination: function(totalRows) {
return 'Toon ' + totalRows + ' record' + ((totalRows > 1) ? 's' : '');
},
formatSearch: function() {
return 'Zoeken';
},
formatNoMatches: function() {
return 'Geen resultaten gevonden';
},
formatRefresh: function() {
return 'Vernieuwen';
},
formatToggle: function() {
return 'Omschakelen';
},
formatColumns: function() {
return 'Kolommen';
},
formatAllRows: function() {
return 'Alle';
},
formatPaginationSwitch: function() {
return 'Verberg/Toon paginatie';
},
formatExport: function() {
return 'Exporteer data';
},
formatClearFilters: function() {
return 'Verwijder filters';
}
};

$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['nl-NL']);

})(jQuery);
23 changes: 4 additions & 19 deletions src/Company/Repositories/CompanyDoctrineRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace VSV\GVQ_API\Company\Repositories;

use InvalidArgumentException;
use Ramsey\Uuid\UuidInterface;
use VSV\GVQ_API\Common\Repositories\AbstractDoctrineRepository;
use VSV\GVQ_API\Common\ValueObjects\NotEmptyString;
use VSV\GVQ_API\Company\Models\Company;
use VSV\GVQ_API\Company\Repositories\Entities\CompanyEntity;
use VSV\GVQ_API\Company\ValueObjects\Alias;
use VSV\GVQ_API\User\Repositories\Entities\UserEntity;

class CompanyDoctrineRepository extends AbstractDoctrineRepository implements CompanyRepository
{
Expand All @@ -28,23 +26,10 @@ public function save(Company $company): void
{
$companyEntity = CompanyEntity::fromCompany($company);

/** @var UserEntity $userEntity */
$userEntity = $this->entityManager->find(
UserEntity::class,
$companyEntity->getUserEntity()->getId()
);

if ($userEntity == null) {
throw new InvalidArgumentException(
'User with id: '.
$companyEntity->getUserEntity()->getId().
' not found.'
);
}

$companyEntity->setUserEntity($userEntity);

$this->entityManager->persist($companyEntity);
// The user object inside company is not managed,
// therefore we need to use merge instead of persist.
// When user wouldn't exist yet, the user is not created.
$this->entityManager->merge($companyEntity);
$this->entityManager->flush();
}

Expand Down
8 changes: 0 additions & 8 deletions src/Company/Repositories/Entities/CompanyEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,4 @@ public function getUserEntity(): UserEntity
{
return $this->userEntity;
}

/**
* @param UserEntity $userEntity
*/
public function setUserEntity(UserEntity $userEntity): void
{
$this->userEntity = $userEntity;
}
}
12 changes: 12 additions & 0 deletions src/Question/Repositories/CategoryDoctrineRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace VSV\GVQ_API\Question\Repositories;

use Doctrine\ORM\EntityNotFoundException;
use Ramsey\Uuid\UuidInterface;
use VSV\GVQ_API\Common\Repositories\AbstractDoctrineRepository;
use VSV\GVQ_API\Question\Models\Categories;
Expand Down Expand Up @@ -31,9 +32,20 @@ public function save(Category $category): void

/**
* @param Category $category
* @throws EntityNotFoundException
*/
public function update(Category $category): void
{
// Make sure the category exists,
// otherwise merge will create the category.
$categoryEntity = $this->entityManager->find(
CategoryEntity::class,
$category->getId()
);
if ($categoryEntity == null) {
throw new EntityNotFoundException("Invalid category supplied");
}

$this->entityManager->merge(
CategoryEntity::fromCategory($category)
);
Expand Down
8 changes: 0 additions & 8 deletions src/Question/Repositories/Entities/QuestionEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,6 @@ public function getCategoryEntity(): CategoryEntity
return $this->categoryEntity;
}

/**
* @param CategoryEntity $categoryEntity
*/
public function setCategoryEntity(CategoryEntity $categoryEntity): void
{
$this->categoryEntity = $categoryEntity;
}

/**
* @return string
*/
Expand Down
38 changes: 17 additions & 21 deletions src/Question/Repositories/QuestionDoctrineRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace VSV\GVQ_API\Question\Repositories;

use InvalidArgumentException;
use Doctrine\ORM\EntityNotFoundException;
use Ramsey\Uuid\UuidInterface;
use VSV\GVQ_API\Common\Repositories\AbstractDoctrineRepository;
use VSV\GVQ_API\Question\Models\Question;
use VSV\GVQ_API\Question\Models\Questions;
use VSV\GVQ_API\Question\Repositories\Entities\CategoryEntity;
use VSV\GVQ_API\Question\Repositories\Entities\QuestionEntity;

class QuestionDoctrineRepository extends AbstractDoctrineRepository implements QuestionRepository
Expand All @@ -27,33 +26,29 @@ public function save(Question $question): void
{
$questionEntity = QuestionEntity::fromQuestion($question);

/** @var CategoryEntity $categoryEntity */
$categoryEntity = $this->entityManager->find(
CategoryEntity::class,
$questionEntity->getCategoryEntity()->getId()
);

if ($categoryEntity == null) {
throw new InvalidArgumentException(
'Category with id: '.
$questionEntity->getCategoryEntity()->getId().
' and name: '.
$questionEntity->getCategoryEntity()->getName().
' not found.'
);
}

$questionEntity->setCategoryEntity($categoryEntity);

$this->entityManager->persist($questionEntity);
// The category object inside question is not managed,
// therefore we need to use merge instead of persist.
// When category wouldn't exist yet, the category is not created.
$this->entityManager->merge($questionEntity);
$this->entityManager->flush();
}

/**
* @inheritdoc
* @throws EntityNotFoundException
*/
public function update(Question $question): void
{
// Make sure the question exists,
// otherwise merge will create a new question.
$questionEntity = $this->entityManager->find(
QuestionEntity::class,
$question->getId()
);
if ($questionEntity == null) {
throw new EntityNotFoundException("Invalid question supplied");
}

$this->entityManager->merge(
QuestionEntity::fromQuestion($question)
);
Expand All @@ -80,6 +75,7 @@ public function delete(UuidInterface $id): void
public function getById(UuidInterface $id): ?Question
{
$questionEntity = $this->getEntityById($id);

return $questionEntity ? $questionEntity->toQuestion() : null;
}

Expand Down
Loading

0 comments on commit f7c546e

Please sign in to comment.