diff --git a/Admin/EventAdmin.php b/Admin/EventAdmin.php index f4dfb44..31a3c83 100644 --- a/Admin/EventAdmin.php +++ b/Admin/EventAdmin.php @@ -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'; /** diff --git a/Admin/SettingAdmin.php b/Admin/SettingAdmin.php new file mode 100644 index 0000000..a14b67c --- /dev/null +++ b/Admin/SettingAdmin.php @@ -0,0 +1,79 @@ +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 + ] + ] + ] + ]; + } +} diff --git a/Controller/Admin/EventController.php b/Controller/Admin/EventController.php index 0e19e20..d49b2e9 100644 --- a/Controller/Admin/EventController.php +++ b/Controller/Admin/EventController.php @@ -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; @@ -39,7 +39,7 @@ /** * @RouteResource("event") */ -class EventController extends AbstractRestController implements ClassResourceInterface +class EventController extends AbstractRestController implements ClassResourceInterface, SecuredControllerInterface { use RequestParametersTrait; @@ -54,10 +54,7 @@ class EventController extends AbstractRestController implements ClassResourceInt */ private DoctrineListRepresentationFactory $doctrineListRepresentationFactory; - /** - * @var RestHelperInterface - */ - private $restHelper; + /** * @var EntityManagerInterface @@ -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, @@ -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; @@ -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 @@ -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 @@ -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; @@ -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 @@ -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 diff --git a/Controller/Admin/SettingController.php b/Controller/Admin/SettingController.php new file mode 100644 index 0000000..42e96f4 --- /dev/null +++ b/Controller/Admin/SettingController.php @@ -0,0 +1,68 @@ +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; + } +} diff --git a/Controller/Website/EventController.php b/Controller/Website/EventController.php index 81723d1..cc35732 100644 --- a/Controller/Website/EventController.php +++ b/Controller/Website/EventController.php @@ -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(), ]; diff --git a/DependencyInjection/EventExtension.php b/DependencyInjection/EventExtension.php index 265fef9..441777a 100644 --- a/DependencyInjection/EventExtension.php +++ b/DependencyInjection/EventExtension.php @@ -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' => [ diff --git a/Entity/Event.php b/Entity/Event.php index f63a909..f9560ab 100644 --- a/Entity/Event.php +++ b/Entity/Event.php @@ -84,12 +84,6 @@ class Event */ private ?string $phoneNumber; - /** - * @ORM\Column(type="json", nullable=true) - * @Serializer\Expose() - */ - private $cards; - /** * @var Collection * @ORM\OneToMany(targetEntity="Pixel\EventBundle\Entity\EventTranslation", mappedBy="event", cascade={"ALL"}, indexBy="locale") @@ -109,9 +103,9 @@ public function __construct() } /** - * @return mixed + * @return int|null */ - public function getId() + public function getId(): ?int { return $this->id; } @@ -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(); diff --git a/Entity/EventTranslation.php b/Entity/EventTranslation.php index c0439c0..31e27dc 100644 --- a/Entity/EventTranslation.php +++ b/Entity/EventTranslation.php @@ -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() */ @@ -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 */ @@ -120,7 +115,7 @@ public function getName() */ public function setName($name): void { - $this->name = $name; + $this->name = trim($name); } /** diff --git a/Entity/Setting.php b/Entity/Setting.php new file mode 100644 index 0000000..9dd897a --- /dev/null +++ b/Entity/Setting.php @@ -0,0 +1,62 @@ +id; + } + + /** + * @return array|null + */ + public function getDefaultImage(): ?MediaInterface + { + return $this->defaultImage; + } + + /** + * @param MediaInterface|null $defaultImage + */ + public function setDefaultImage(?MediaInterface $defaultImage): void + { + $this->defaultImage = $defaultImage; + } +} diff --git a/Preview/EventObjectProvider.php b/Preview/EventObjectProvider.php index f21834c..ebb2654 100644 --- a/Preview/EventObjectProvider.php +++ b/Preview/EventObjectProvider.php @@ -48,9 +48,7 @@ public function setValues($object, $locale, array $data) $email = $data['email'] ?? null; $phoneNumber = $data['phoneNumber'] ?? null; $location = $data['location'] ?? null; - $cards = $data['cards'] ?? null; - dump($cards); $object->setName($data['name']); $object->setDescription($data['description']); diff --git a/Repository/EventRepository.php b/Repository/EventRepository.php index 807a943..3430c94 100644 --- a/Repository/EventRepository.php +++ b/Repository/EventRepository.php @@ -2,7 +2,9 @@ namespace Pixel\EventBundle\Repository; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Pixel\EventBundle\Entity\Event; @@ -13,6 +15,11 @@ class EventRepository extends EntityRepository implements DataProviderRepository { use DataProviderRepositoryTrait; + public function __construct(EntityManagerInterface $em) + { + parent::__construct($em, new ClassMetadata(Event::class)); + } + public function create(string $locale): Event { $event = new Event(); diff --git a/Resources/config/forms/event_settings.xml b/Resources/config/forms/event_settings.xml new file mode 100644 index 0000000..a4ce4cf --- /dev/null +++ b/Resources/config/forms/event_settings.xml @@ -0,0 +1,14 @@ + +
+ event_settings + + + + event_settings.defaultImage + + + +
diff --git a/Resources/config/forms/events_details.xml b/Resources/config/forms/events_details.xml index 77c3125..b2dcb7f 100644 --- a/Resources/config/forms/events_details.xml +++ b/Resources/config/forms/events_details.xml @@ -39,6 +39,7 @@ + @@ -69,11 +70,6 @@ - - - event.directory - - diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 0652654..a751fdb 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -8,7 +8,6 @@ public="true"> - @@ -22,6 +21,17 @@ + + + + + + + + + @@ -31,6 +41,13 @@ + + + + + + + diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml index 3b60495..55dcffc 100644 --- a/Resources/config/services.yaml +++ b/Resources/config/services.yaml @@ -3,4 +3,10 @@ services: autowire: true autoconfigure: true Pixel\EventBundle\Controller\Website\: - resource: '../../Controller/Website' \ No newline at end of file + resource: '../../Controller/Website' + + Pixel\EventBundle\Twig\SettingsExtension: + public: false + autowire: true + tags: + - {name: twig.extension} \ No newline at end of file diff --git a/Resources/translations/admin.fr.json b/Resources/translations/admin.fr.json index a985b46..6028b97 100644 --- a/Resources/translations/admin.fr.json +++ b/Resources/translations/admin.fr.json @@ -15,6 +15,8 @@ "event.phone_number": "Numéro de téléphone", "event.directory": "Annuaire", "event.searchName": "Evénements", + "event.settings": "Gestion des événements", + "event_settings.defaultImage": "Image par défaut", "sulu_activity.resource.events": "Evénements", "sulu_activity.description.events.created": "{userFullName} a créé l'événement \"{resourceTitle}\"", "sulu_activity.description.events.modified": "{userFullName} a modifié l'événement \"{resourceTitle}\"", diff --git a/Twig/SettingsExtension.php b/Twig/SettingsExtension.php new file mode 100644 index 0000000..c4a6bf8 --- /dev/null +++ b/Twig/SettingsExtension.php @@ -0,0 +1,33 @@ +entityManager = $entityManager; + } + + public function getFunctions(): array + { + return [ + new TwigFunction('event_settings', [$this, 'eventSettings']), + ]; + } + + public function eventSettings() + { + return $this->entityManager->getRepository(Setting::class)->findOneBy([]); + } +} diff --git a/changelog.md b/changelog.md index 02ada1d..0cf7ec9 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## 2.4.6 (03/04/2022) + + + ## 2.4.5 (31/03/2022) - Fix description