Skip to content

Commit

Permalink
Merge branch 'release/2.4.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu committed Apr 4, 2022
2 parents 3dfa34d + c9366eb commit e984da0
Show file tree
Hide file tree
Showing 18 changed files with 314 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Admin/EventAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EventAdmin extends Admin
const EVENT_ADD_FORM_VIEW = 'event.event_add_form';
const EVENT_ADD_DETAILS_FORM = 'event.event_add_form_details';
const EVENT_EDIT_FORM_VIEW = 'event.event_edit_form';
const EVENT_EDIT_DETAILS_FORM_VIEW = 'event.event_edit_form_detail';
const EVENT_EDIT_DETAILS_FORM_VIEW = 'event.event_edit_form_details';
const EVENT_EDIT_SEO_FORM_VIEW = 'event.event_edit_form_seo';

/**
Expand Down
79 changes: 79 additions & 0 deletions Admin/SettingAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

namespace Pixel\EventBundle\Admin;

use Pixel\EventBundle\Entity\Setting;
use Sulu\Bundle\AdminBundle\Admin\Admin;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItem;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;
use Sulu\Bundle\AdminBundle\Admin\View\ToolbarAction;
use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactoryInterface;
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection;
use Sulu\Component\Security\Authorization\PermissionTypes;
use Sulu\Component\Security\Authorization\SecurityCheckerInterface;

class SettingAdmin extends Admin
{
const TAB_VIEW = "event.settings";
const FORM_VIEW = "event.settings.form";

private ViewBuilderFactoryInterface $viewBuilderFactory;
private SecurityCheckerInterface $securityChecker;

public function __construct(
ViewBuilderFactoryInterface $viewBuilderFactory,
SecurityCheckerInterface $securityChecker
)
{
$this->viewBuilderFactory = $viewBuilderFactory;
$this->securityChecker = $securityChecker;
}

public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
{
if($this->securityChecker->hasPermission(Setting::SECURITY_CONTEXT, PermissionTypes::EDIT)){
$navigationItem = new NavigationItem('event.settings');
$navigationItem->setPosition(2);
$navigationItem->setView(static::TAB_VIEW);
$navigationItemCollection->get(Admin::SETTINGS_NAVIGATION_ITEM)->addChild($navigationItem);
}
}

public function configureViews(ViewCollection $viewCollection): void
{
if($this->securityChecker->hasPermission(Setting::SECURITY_CONTEXT, PermissionTypes::EDIT)){
$viewCollection->add(
$this->viewBuilderFactory->createResourceTabViewBuilder(static::TAB_VIEW, '/event-settings/:id')
->setResourceKey(Setting::RESOURCE_KEY)
->setAttributeDefault('id', '-')
);
$viewCollection->add(
$this->viewBuilderFactory->createFormViewBuilder(static::FORM_VIEW, '/details')
->setResourceKey(Setting::RESOURCE_KEY)
->setFormKey(Setting::FORM_KEY)
->setTabTitle('sulu_admin.details')
->addToolbarActions([new ToolbarAction('sulu_admin.save')])
->setParent(static::TAB_VIEW)
);
}
}

/**
* @return mixed[]
*/
public function getSecurityContexts()
{
return [
self::SULU_ADMIN_SECURITY_SYSTEM => [
'Setting' => [
Setting::SECURITY_CONTEXT => [
PermissionTypes::VIEW,
PermissionTypes::EDIT
]
]
]
];
}
}
19 changes: 6 additions & 13 deletions Controller/Admin/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use Sulu\Component\Rest\Exception\EntityNotFoundException;
use Sulu\Component\Rest\Exception\RestException;
use Sulu\Component\Rest\RequestParametersTrait;
use Sulu\Component\Rest\RestHelperInterface;
use Sulu\Component\Security\SecuredControllerInterface;
use Sulu\Component\Webspace\Manager\WebspaceManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -39,7 +39,7 @@
/**
* @RouteResource("event")
*/
class EventController extends AbstractRestController implements ClassResourceInterface
class EventController extends AbstractRestController implements ClassResourceInterface, SecuredControllerInterface
{

use RequestParametersTrait;
Expand All @@ -54,10 +54,7 @@ class EventController extends AbstractRestController implements ClassResourceInt
*/
private DoctrineListRepresentationFactory $doctrineListRepresentationFactory;

/**
* @var RestHelperInterface
*/
private $restHelper;


/**
* @var EntityManagerInterface
Expand All @@ -75,7 +72,6 @@ class EventController extends AbstractRestController implements ClassResourceInt
public function __construct(
ViewHandlerInterface $viewHandler,
DoctrineListRepresentationFactory $doctrineListRepresentationFactory,
RestHelperInterface $restHelper,
EntityManagerInterface $entityManager,
WebspaceManagerInterface $webspaceManager,
RouteManagerInterface $routeManager,
Expand All @@ -90,7 +86,6 @@ public function __construct(
{
$this->viewHandler = $viewHandler;
$this->doctrineListRepresentationFactory = $doctrineListRepresentationFactory;
$this->restHelper = $restHelper;
$this->entityManager = $entityManager;
$this->webspaceManager = $webspaceManager;
$this->routeManager = $routeManager;
Expand All @@ -112,7 +107,7 @@ public function cgetAction(Request $request): Response
['locale' => $locale]
);

return $this->viewHandler->handle(View::create($listRepresentation));
return $this->handleView($this->view($listRepresentation));
}

public function getAction(int $id, Request $request): Response
Expand All @@ -121,7 +116,7 @@ public function getAction(int $id, Request $request): Response
if (!$event) {
throw new NotFoundHttpException();
}
return $this->viewHandler->handle(View::create($event));
return $this->handleView($this->view($event));
}

protected function load(int $id, Request $request): ?Event
Expand Down Expand Up @@ -152,7 +147,6 @@ protected function mapDataToEntity(array $data, Event $entity, Request $request)
$imageId = $data['image']['id'] ?? null;
$enabled = $data['enabled'] ?? null;
$seo = (isset($data['ext']['seo'])) ? $data['ext']['seo'] : null;
$cards = (isset($data['cards'])) ? $data['cards'] : null;
$url = $data['url'] ?? null;
$email = $data['email'] ?? null;
$phoneNumber = $data['phoneNumber'] ?? null;
Expand All @@ -171,7 +165,6 @@ protected function mapDataToEntity(array $data, Event $entity, Request $request)
$entity->setUrl($url);
$entity->setEmail($email);
$entity->setPhoneNumber($phoneNumber);
$entity->setCards($cards);
}

protected function updateRoutesForEntity(Event $entity): void
Expand Down Expand Up @@ -203,7 +196,7 @@ public function postAction(Request $request): Response
new EventCreatedEvent($event, $data)
);
$this->entityManager->flush();
return $this->viewHandler->handle(View::create($event));
return $this->handleView($this->view($event, 201));
}

protected function create(Request $request): Event
Expand Down
68 changes: 68 additions & 0 deletions Controller/Admin/SettingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace Pixel\EventBundle\Controller\Admin;

use Doctrine\ORM\EntityManagerInterface;
use FOS\RestBundle\View\ViewHandlerInterface;
use HandcraftedInTheAlps\RestRoutingBundle\Controller\Annotations\RouteResource;
use HandcraftedInTheAlps\RestRoutingBundle\Routing\ClassResourceInterface;
use Pixel\EventBundle\Entity\Setting;
use Sulu\Bundle\MediaBundle\Media\Manager\MediaManagerInterface;
use Sulu\Component\Rest\AbstractRestController;
use Sulu\Component\Security\SecuredControllerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

/**
* @RouteResource("event-settings")
*/
class SettingController extends AbstractRestController implements ClassResourceInterface, SecuredControllerInterface
{
private EntityManagerInterface $entityManager;
private MediaManagerInterface $mediaManager;

public function __construct(
EntityManagerInterface $entityManager,
MediaManagerInterface $mediaManager,
ViewHandlerInterface $viewHandler,
?TokenStorageInterface $tokenStorage = null
)
{
$this->entityManager = $entityManager;
$this->mediaManager = $mediaManager;
parent::__construct($viewHandler, $tokenStorage);
}

public function getAction(): Response
{
$applicationSetting = $this->entityManager->getRepository(Setting::class)->findOneBy([]);
return $this->handleView($this->view($applicationSetting ?: new Setting()));
}

public function putAction(Request $request): Response
{
$applicationSetting = $this->entityManager->getRepository(Setting::class)->findOneBy([]);
if(!$applicationSetting){
$applicationSetting = new Setting();
$this->entityManager->persist($applicationSetting);
}
$this->mapDataToEntity($request->request->all(), $applicationSetting);
$this->entityManager->flush();
return $this->handleView($this->view($applicationSetting));
}

public function mapDataToEntity(array $data, Setting $entity): void
{
$defaultImageId = $data['defaultImage']['id'] ?? null;

$entity->setDefaultImage($defaultImageId ? $this->mediaManager->getEntityById($defaultImageId) : null);
}

public function getSecurityContext()
{
return Setting::SECURITY_CONTEXT;
}
}
2 changes: 1 addition & 1 deletion Controller/Website/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function getSubscribedServices()
public function indexAction(Event $event, $attributes = [], $preview = false, $partial = false): Response
{

if (!$event->getSeo()) {
if (!$event->getSeo() || (isset($event->getSeo()['title']) && !$event->getSeo()['title'])) {
$seo = [
"title" => $event->getName(),
];
Expand Down
5 changes: 5 additions & 0 deletions DependencyInjection/EventExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public function prepend(ContainerBuilder $container): void
'list' => 'event.get_events',
],
],
'event_settings' => [
'routes' => [
'detail' => 'event.get_event-settings'
]
]
],
'field_type_options' => [
'selection' => [
Expand Down
26 changes: 2 additions & 24 deletions Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ class Event
*/
private ?string $phoneNumber;

/**
* @ORM\Column(type="json", nullable=true)
* @Serializer\Expose()
*/
private $cards;

/**
* @var Collection<string, EventTranslation>
* @ORM\OneToMany(targetEntity="Pixel\EventBundle\Entity\EventTranslation", mappedBy="event", cascade={"ALL"}, indexBy="locale")
Expand All @@ -109,9 +103,9 @@ public function __construct()
}

/**
* @return mixed
* @return int|null
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}
Expand Down Expand Up @@ -424,22 +418,6 @@ public function setEnabled(?bool $enabled): void
$this->enabled = $enabled;
}

/**
* @return mixed
*/
public function getCards()
{
return $this->cards;
}

/**
* @param mixed $cards
*/
public function setCards($cards): void
{
$this->cards = $cards;
}

public function getTranslations(): array
{
return $this->translations->toArray();
Expand Down
13 changes: 4 additions & 9 deletions Entity/EventTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ class EventTranslation implements AuditableInterface

/**
* @ORM\Column(type="string")
* @Serializer\Expose()
*/
private $name;

/**
* @ORM\Column(type="text", nullable=true)
* @Serializer\Expose()
*/
private ?string $description;

/**
* @ORM\Column(type="string", length=255)
* @Serializer\Expose()
*
* @Serializer\Expose()
*/
Expand All @@ -75,14 +78,6 @@ public function getId(): ?int
return $this->id;
}

/**
* @param int|null $id
*/
public function setId(?int $id): void
{
$this->id = $id;
}

/**
* @return Event
*/
Expand Down Expand Up @@ -120,7 +115,7 @@ public function getName()
*/
public function setName($name): void
{
$this->name = $name;
$this->name = trim($name);
}

/**
Expand Down

0 comments on commit e984da0

Please sign in to comment.