Skip to content

Commit

Permalink
CS Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ludwig031 committed Jan 25, 2024
1 parent 11c12af commit 39638ea
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 73 deletions.
62 changes: 29 additions & 33 deletions bundle/Controller/Admin/AdminController.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php

declare(strict_types=1);

namespace Netgen\Bundle\InformationCollectionBundle\Controller\Admin;

use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute;
use Ibexa\Bundle\Core\Controller;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute;
use Netgen\Bundle\InformationCollectionBundle\Form\Builder\FormBuilder;
use Netgen\InformationCollection\API\Persistence\Anonymizer\Anonymizer;
use Netgen\InformationCollection\API\Service\InformationCollection;
use Netgen\InformationCollection\API\Value\Collection;
use Netgen\InformationCollection\API\Value\Filter\CollectionFields;
use Netgen\InformationCollection\API\Value\Filter\Collections;
use Netgen\InformationCollection\API\Value\Filter\CollectionId;
use Netgen\InformationCollection\API\Value\Filter\Collections;
use Netgen\InformationCollection\API\Value\Filter\ContentId;
use Netgen\InformationCollection\API\Value\Filter\Contents;
use Netgen\InformationCollection\API\Value\Filter\Query;
Expand All @@ -31,6 +33,10 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;

use function array_merge;
use function count;
use function time;

class AdminController extends Controller
{
protected InformationCollection $service;
Expand Down Expand Up @@ -60,8 +66,7 @@ public function __construct(
EzInfoCollectionRepository $infoCollectionRepository,
EzInfoCollectionAttributeRepository $infoCollectionAttributeRepository,
FormBuilder $builder
)
{
) {
$this->service = $service;
$this->contentService = $contentService;
$this->configResolver = $configResolver;
Expand All @@ -74,7 +79,7 @@ public function __construct(
}

/**
* Displays overview page
* Displays overview page.
*/
public function overviewAction(Request $request): Response
{
Expand All @@ -83,27 +88,27 @@ public function overviewAction(Request $request): Response
$adapter = new InformationCollectionContentsAdapter($this->service, Query::countQuery());
$pager = $this->getPager($adapter, (int) $request->query->get('page'));

return $this->render("@NetgenInformationCollection/admin/overview.html.twig", ['objects' => $pager]);
return $this->render('@NetgenInformationCollection/admin/overview.html.twig', ['objects' => $pager]);
}

/**
* Displays list of collection for selected Content
* Displays list of collection for selected Content.
*/
public function collectionListAction(Request $request, Content $content): Response
{
$this->checkReadPermissions();

$adapter = new InformationCollectionCollectionListAdapter($this->service, ContentId::withContentId($content->id));
$pager = $this->getPager($adapter, (int)$request->query->get('page'));
$pager = $this->getPager($adapter, (int) $request->query->get('page'));

return $this->render("@NetgenInformationCollection/admin/collection_list.html.twig", [
return $this->render('@NetgenInformationCollection/admin/collection_list.html.twig', [
'objects' => $pager,
'content' => $content,
]);
}

/**
* Handles collection search
* Handles collection search.
*/
public function searchAction(Request $request, Content $content): Response
{
Expand All @@ -112,9 +117,10 @@ public function searchAction(Request $request, Content $content): Response
$query = SearchQuery::withContentAndSearchText($content->id, $request->query->get('searchText'));

$adapter = new InformationCollectionCollectionListSearchAdapter($this->service, $query);
$pager = $this->getPager($adapter, (int)$request->query->get('page'));
$pager = $this->getPager($adapter, (int) $request->query->get('page'));

return $this->render("@NetgenInformationCollection/admin/collection_list.html.twig",
return $this->render(
'@NetgenInformationCollection/admin/collection_list.html.twig',
[
'objects' => $pager,
'content' => $content,
Expand All @@ -123,20 +129,20 @@ public function searchAction(Request $request, Content $content): Response
}

/**
* Displays individual collection details
* Displays individual collection details.
*/
public function viewAction(Collection $collection): Response
{
$this->checkReadPermissions();

return $this->render("@NetgenInformationCollection/admin/view.html.twig", [
return $this->render('@NetgenInformationCollection/admin/view.html.twig', [
'collection' => $collection,
'content' => $collection->getContent(),
]);
}

/**
* Handles actions performed on overview page
* Handles actions performed on overview page.
*/
public function handleContentsAction(Request $request): RedirectResponse
{
Expand All @@ -152,7 +158,6 @@ public function handleContentsAction(Request $request): RedirectResponse
}

if ($request->request->has('DeleteCollectionByContentAction')) {

$this->checkDeletePermissions();

$query = new Contents($contents);
Expand All @@ -170,7 +175,7 @@ public function handleContentsAction(Request $request): RedirectResponse
}

/**
* Handles actions performed on collection list page
* Handles actions performed on collection list page.
*/
public function handleCollectionListAction(Request $request): RedirectResponse
{
Expand All @@ -187,7 +192,6 @@ public function handleCollectionListAction(Request $request): RedirectResponse
}

if ($request->request->has('DeleteCollectionAction')) {

$this->checkDeletePermissions();

$query = new Collections($contentId, $collections);
Expand All @@ -200,7 +204,6 @@ public function handleCollectionListAction(Request $request): RedirectResponse
}

if ($request->request->has('AnonymizeCollectionAction')) {

$this->checkAnonymizePermissions();

foreach ($collections as $collection) {
Expand All @@ -218,7 +221,7 @@ public function handleCollectionListAction(Request $request): RedirectResponse
}

/**
* Handles action on collection details page
* Handles action on collection details page.
*/
public function handleCollectionAction(Request $request): RedirectResponse
{
Expand All @@ -239,7 +242,6 @@ public function handleCollectionAction(Request $request): RedirectResponse
}

if ($request->request->has('DeleteFieldAction')) {

$this->checkDeletePermissions();

$query = new CollectionFields($contentId, $collectionId, $fields);
Expand All @@ -252,7 +254,6 @@ public function handleCollectionAction(Request $request): RedirectResponse
}

if ($request->request->has('AnonymizeFieldAction')) {

$this->checkAnonymizePermissions();

$this->anonymizer->anonymizeCollection($collectionId, $fields);
Expand All @@ -263,25 +264,22 @@ public function handleCollectionAction(Request $request): RedirectResponse
}

if ($request->request->has('DeleteCollectionAction')) {

$this->checkDeletePermissions();

$query = new Collections($contentId, [$collectionId]);
$this->service->deleteCollections($query);

$this->addFlashMessage("success", "collection_removed");
$this->addFlashMessage('success', 'collection_removed');

return $this->redirectToRoute('netgen_information_collection.route.admin.collection_list', ['contentId' => $contentId]);

}

if ($request->request->has('AnonymizeCollectionAction')) {

$this->checkAnonymizePermissions();

$this->anonymizer->anonymizeCollection($collectionId);

$this->addFlashMessage("success", "collection_anonymized");
$this->addFlashMessage('success', 'collection_anonymized');

return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]);
}
Expand Down Expand Up @@ -355,19 +353,17 @@ public function editAction(Request $request, int $collectionId)
);
}

return $this->render("@NetgenInformationCollection/admin/edit.html.twig", [
return $this->render('@NetgenInformationCollection/admin/edit.html.twig', [
'collection' => $collection,
'content' => $location->getContent(),
'form' => $form->createView(),
]);
}



/**
* Adds a flash message with specified parameters.
*/
protected function addFlashMessage(string $messageType, string $message, int $count = 1, array $parameters = array()): void
protected function addFlashMessage(string $messageType, string $message, int $count = 1, array $parameters = []): void
{
$parameters = array_merge($parameters, ['count' => $count]);

Expand All @@ -382,7 +378,7 @@ protected function addFlashMessage(string $messageType, string $message, int $co
}

/**
* Returns configured instance of Pagerfanta
* Returns configured instance of Pagerfanta.
*/
protected function getPager(AdapterInterface $adapter, int $currentPage): Pagerfanta
{
Expand Down
14 changes: 7 additions & 7 deletions bundle/Form/Builder/FormBuilder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Netgen\Bundle\InformationCollectionBundle\Form\Builder;

use Ibexa\Contracts\Core\Repository\Values\Content\Location;
Expand All @@ -21,12 +23,12 @@
class FormBuilder
{
public function __construct(
protected readonly FormFactoryInterface $formFactory,
protected readonly ContentTypeService $contentTypeService,
protected readonly RouterInterface $router,
protected readonly FormFactoryInterface $formFactory,
protected readonly ContentTypeService $contentTypeService,
protected readonly RouterInterface $router,
protected readonly ConfigResolverInterface $configResolver,
protected readonly FieldDataFactory $legacyFactory,
protected readonly FieldHandlerRegistry $registry
protected readonly FieldDataFactory $legacyFactory,
protected readonly FieldHandlerRegistry $registry
) {
}

Expand All @@ -37,14 +39,12 @@ public function createUpdateFormForLocation(Location $location, Collection $coll
$struct = new InformationCollectionStruct();

foreach ($collection->getAttributes() as $attribute) {

$fieldValue = $this->fromLegacyValue(
new FieldValue(
$attribute->getField()->id,
$attribute->getValue()->getDataText(),
$attribute->getValue()->getDataInt(),
$attribute->getValue()->getDataFloat()

),
$attribute->getFieldDefinition()
);
Expand Down
12 changes: 7 additions & 5 deletions bundle/Form/InformationCollectionUpdateType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Netgen\Bundle\InformationCollectionBundle\Form;

use eZ\Publish\API\Repository\Values\ContentType\ContentType;
Expand All @@ -14,6 +16,9 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

use function array_keys;
use function in_array;

class InformationCollectionUpdateType extends AbstractContentType
{
protected FieldTypeHandlerRegistry $fieldTypeHandlerRegistry;
Expand All @@ -24,8 +29,8 @@ class InformationCollectionUpdateType extends AbstractContentType

public function __construct(
FieldTypeHandlerRegistry $fieldTypeHandlerRegistry,
DataMapperInterface $dataMapper,
ConfigResolverInterface $configResolver
DataMapperInterface $dataMapper,
ConfigResolverInterface $configResolver
) {
parent::__construct($fieldTypeHandlerRegistry, $dataMapper);
$this->configResolver = $configResolver;
Expand All @@ -38,7 +43,6 @@ public function getName(): string

/**
* Returns the prefix of the template block name for this type.
*
*/
public function getBlockPrefix(): string
{
Expand Down Expand Up @@ -122,5 +126,3 @@ protected function getLanguageCode(ContentType $contentType): string
return $contentType->mainLanguageCode;
}
}


Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
<?php

declare(strict_types=1);

namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom;

use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface;
use Netgen\InformationCollection\API\Value\Legacy\FieldValue;
use Ibexa\Core\FieldType\Value;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Core\FieldType\Value;
use Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday\Value as BirthdayValue;
use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface;
use Netgen\InformationCollection\API\Value\Legacy\FieldValue;

class BirthdayFieldHandler implements CustomLegacyFieldHandlerInterface
{
/**
* @inheritDoc
* {@inheritDoc}
*/
public function supports(Value $value): bool
{
return $value instanceof BirthdayValue;
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function toString(Value $value, FieldDefinition $fieldDefinition): string
{
return (string) $value;
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue
{
return new FieldValue($fieldDefinition->id, (string) $value, 0, 0);
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function fromLegacyValue(FieldValue $legacyData)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom;

use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Core\FieldType\Checkbox\Value as CheckboxValue;
use Ibexa\Core\FieldType\Country\Value as CountryValue;
use Ibexa\Core\FieldType\Value;
use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface;
use Netgen\InformationCollection\API\Value\Legacy\FieldValue;

use function array_column;
use function implode;

Expand Down
Loading

0 comments on commit 39638ea

Please sign in to comment.