Skip to content

Commit

Permalink
Symfony 7.*, Orm annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Bertrams committed Aug 24, 2024
1 parent 9b3676c commit 23fbc5b
Show file tree
Hide file tree
Showing 39 changed files with 262 additions and 475 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"require": {
"php": "^8.1",
"doctrine/doctrine-bundle": "^2.12",
"phpcr/phpcr-migrations-bundle": "^1.6",
"sulu/sulu": "^2.5",
"sulu/automation-bundle": "^2.1",
Expand All @@ -28,8 +29,7 @@
"symfony/http-kernel": "^6.2 | ^7.0",
"symfony/intl": "^6.2 | ^7.0",
"symfony/translation": "^6.2 | ^7.0",
"symfony/security-core": "^6.2 | ^7.0",
"doctrine/doctrine-bundle": "^2.11"
"symfony/security-core": "^6.2 | ^7.0"
},
"require-dev": {
"jackalope/jackalope-doctrine-dbal": "^1.3.4",
Expand Down
101 changes: 30 additions & 71 deletions src/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Manuxi\SuluEventBundle\Entity\Interfaces\AuditableTranslatableInterface;
Expand All @@ -16,12 +17,10 @@
use Manuxi\SuluEventBundle\Entity\Traits\RouteTranslatableTrait;
use Manuxi\SuluEventBundle\Entity\Traits\ShowAuthorTranslatableTrait;
use Manuxi\SuluEventBundle\Entity\Traits\ShowDateTranslatableTrait;
use Manuxi\SuluEventBundle\Repository\EventRepository;

/**
* @ORM\Entity
* @ORM\Table(name="app_event")
* @ORM\Entity(repositoryClass="Manuxi\SuluEventBundle\Repository\EventRepository")
*/
#[ORM\Entity(repositoryClass: EventRepository::class)]
#[ORM\Table(name: 'app_event')]
class Event implements AuditableTranslatableInterface
{
public const RESOURCE_KEY = 'events';
Expand All @@ -36,68 +35,44 @@ class Event implements AuditableTranslatableInterface
use ImageTranslatableTrait;
use ShowAuthorTranslatableTrait;
use ShowDateTranslatableTrait;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;

/**
* @ORM\OneToOne(targetEntity="Manuxi\SuluEventBundle\Entity\EventSeo", mappedBy="event", cascade={"persist", "remove"})
*
* @Serializer\Exclude
*/
#[Serializer\Exclude]
#[ORM\OneToOne(mappedBy: 'event', targetEntity: EventSeo::class, cascade: ['persist', 'remove'])]
private ?EventSeo $eventSeo = null;

/**
* @ORM\OneToOne(targetEntity="Manuxi\SuluEventBundle\Entity\EventExcerpt", mappedBy="event", cascade={"persist", "remove"})
*
* @Serializer\Exclude
*/
#[Serializer\Exclude]
#[ORM\OneToOne(mappedBy: 'event', targetEntity: EventExcerpt::class, cascade: ['persist', 'remove'])]
private ?EventExcerpt $eventExcerpt = null;

/**
* @ORM\Column(type="boolean", nullable=false)
*/
#[ORM\Column(type: Types::BOOLEAN, nullable: false)]
private bool $enabled;

/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $startDate = null;

/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $endDate = null;

/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
private ?string $email = null;

/**
* @ORM\Column(type="string", nullable=true)
*/
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
private ?string $phoneNumber = null;

/**
* @ORM\Column(type="json", nullable=true)
*/
#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $images = null;

/**
* @ORM\ManyToOne(targetEntity="Manuxi\SuluEventBundle\Entity\Location")
* @ORM\JoinColumn(onDelete="SET NULL")
*/
#[ORM\ManyToOne(targetEntity: Location::class)]
#[ORM\JoinColumn(onDelete: 'SET NULL')]
private ?Location $location = null;

/**
* @var Collection<string, EventTranslation>
* @ORM\OneToMany(targetEntity="Manuxi\SuluEventBundle\Entity\EventTranslation", mappedBy="event", cascade={"ALL"}, indexBy="locale", fetch="EXTRA_LAZY")
* @Serializer\Exclude
*/
#[Serializer\Exclude]
#[ORM\OneToMany(mappedBy: 'event', targetEntity: EventTranslation::class, cascade: ['all'], fetch: 'EXTRA_LAZY', indexBy: 'locale')]
private Collection $translations;

private string $locale = 'de';
Expand Down Expand Up @@ -172,9 +147,7 @@ public function setLocation(?Location $location): self
return $this;
}

/**
* @Serializer\VirtualProperty
*/
#[Serializer\VirtualProperty]
public function getLocationId(): ?int
{
if (!$this->location) {
Expand All @@ -184,9 +157,7 @@ public function getLocationId(): ?int
return $this->location->getId();
}

/**
* @Serializer\VirtualProperty(name="title")
*/
#[Serializer\VirtualProperty(name: "title")]
public function getTitle(): ?string
{
$translation = $this->getTranslation($this->locale);
Expand All @@ -208,9 +179,7 @@ public function setTitle(string $title): self
return $this;
}

/**
* @Serializer\VirtualProperty(name="subtitle")
*/
#[Serializer\VirtualProperty(name: "subtitle")]
public function getSubtitle(): ?string
{
$translation = $this->getTranslation($this->locale);
Expand All @@ -232,9 +201,7 @@ public function setSubtitle(?string $subtitle): self
return $this;
}

/**
* @Serializer\VirtualProperty(name="summary")
*/
#[Serializer\VirtualProperty(name: "summary")]
public function getSummary(): ?string
{
$translation = $this->getTranslation($this->locale);
Expand All @@ -256,9 +223,7 @@ public function setSummary(?string $summary): self
return $this;
}

/**
* @Serializer\VirtualProperty(name="text")
*/
#[Serializer\VirtualProperty(name: "text")]
public function getText(): ?string
{
$translation = $this->getTranslation($this->locale);
Expand All @@ -280,9 +245,7 @@ public function setText(string $text): self
return $this;
}

/**
* @Serializer\VirtualProperty(name="footer")
*/
#[Serializer\VirtualProperty(name: "footer")]
public function getFooter(): ?string
{
$translation = $this->getTranslation($this->locale);
Expand Down Expand Up @@ -336,9 +299,7 @@ public function setEventExcerpt(?EventExcerpt $eventExcerpt): self
return $this;
}

/**
* @Serializer\VirtualProperty(name="ext")
*/
#[Serializer\VirtualProperty(name: "ext")]
public function getExt(): array
{
return $this->ext;
Expand Down Expand Up @@ -407,9 +368,7 @@ private function initExt(): self
return $this;
}

/**
* @Serializer\VirtualProperty("availableLocales")
*/
#[Serializer\VirtualProperty(name: "availableLocales")]
public function getAvailableLocales(): array
{
return \array_values($this->translations->getKeys());
Expand Down
24 changes: 8 additions & 16 deletions src/Entity/EventExcerpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,22 @@
use Manuxi\SuluEventBundle\Entity\Interfaces\ExcerptTranslatableInterface;
use Manuxi\SuluEventBundle\Entity\Traits\ExcerptTrait;
use Manuxi\SuluEventBundle\Entity\Traits\ExcerptTranslatableTrait;
use Manuxi\SuluEventBundle\Repository\EventExcerptRepository;

/**
* @ORM\Entity
* @ORM\Table(name="app_event_excerpt")
* @ORM\Entity(repositoryClass="Manuxi\SuluEventBundle\Repository\EventExcerptRepository")
*/
#[ORM\Entity(repositoryClass: EventExcerptRepository::class)]
#[ORM\Table(name: 'app_event_excerpt')]
class EventExcerpt implements ExcerptInterface, ExcerptTranslatableInterface
{
use ExcerptTrait;
use ExcerptTranslatableTrait;

/**
* @ORM\OneToOne(targetEntity="Manuxi\SuluEventBundle\Entity\Event", inversedBy="eventExcerpt", cascade={"persist", "remove"})
* @JoinColumn(name="event_id", referencedColumnName="id", nullable=false)
*
* @Serializer\Exclude
*/
#[Serializer\Exclude]
#[ORM\OneToOne(inversedBy: 'eventExcerpt', targetEntity: Event::class, cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(name: 'event_id', referencedColumnName: "id", nullable: false)]
private ?Event $event = null;

/**
* @ORM\OneToMany(targetEntity="EventExcerptTranslation", mappedBy="eventExcerpt", cascade={"ALL"}, indexBy="locale")
*
* @Serializer\Exclude
*/
#[Serializer\Exclude]
#[ORM\OneToMany(mappedBy: 'eventExcerpt', targetEntity: EventExcerptTranslation::class, cascade: ['all'], indexBy: 'locale')]
private Collection $translations;

public function __construct()
Expand Down
15 changes: 5 additions & 10 deletions src/Entity/EventExcerptTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@

namespace Manuxi\SuluEventBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Manuxi\SuluEventBundle\Entity\Interfaces\ExcerptTranslationInterface;
use Manuxi\SuluEventBundle\Entity\Traits\ExcerptTranslationTrait;
use Manuxi\SuluEventBundle\Repository\EventExcerptTranslationRepository;

/**
* @ORM\Entity
* @ORM\Table(name="app_event_excerpt_translation")
* @ORM\Entity(repositoryClass="Manuxi\SuluEventBundle\Repository\EventExcerptTranslationRepository")
*/
#[ORM\Entity(repositoryClass: EventExcerptTranslationRepository::class)]
#[ORM\Table(name: 'app_event_excerpt_translation')]
class EventExcerptTranslation implements ExcerptTranslationInterface
{
use ExcerptTranslationTrait;

/**
* @ORM\ManyToOne(targetEntity="Manuxi\SuluEventBundle\Entity\EventExcerpt", inversedBy="translations")
* @ORM\JoinColumn(nullable=false)
*/
#[ORM\ManyToOne(targetEntity: EventExcerpt::class, inversedBy: 'translations')]
#[ORM\JoinColumn(nullable: false)]
private EventExcerpt $eventExcerpt;

public function __construct(EventExcerpt $eventExcerpt, string $locale)
Expand Down
24 changes: 8 additions & 16 deletions src/Entity/EventSeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,22 @@
use Manuxi\SuluEventBundle\Entity\Interfaces\SeoTranslatableInterface;
use Manuxi\SuluEventBundle\Entity\Traits\SeoTrait;
use Manuxi\SuluEventBundle\Entity\Traits\SeoTranslatableTrait;
use Manuxi\SuluEventBundle\Repository\EventSeoRepository;

/**
* @ORM\Entity
* @ORM\Table(name="app_event_seo")
* @ORM\Entity(repositoryClass="Manuxi\SuluEventBundle\Repository\EventSeoRepository")
*/
#[ORM\Entity(repositoryClass: EventSeoRepository::class)]
#[ORM\Table(name: 'app_event_seo')]
class EventSeo implements SeoInterface, SeoTranslatableInterface
{
use SeoTrait;
use SeoTranslatableTrait;

/**
* @ORM\OneToOne(targetEntity="Manuxi\SuluEventBundle\Entity\Event", inversedBy="eventSeo", cascade={"persist", "remove"})
* @JoinColumn(name="event_id", referencedColumnName="id", nullable=false)
*
* @Serializer\Exclude
*/
#[Serializer\Exclude]
#[ORM\OneToOne(inversedBy: 'eventSeo', targetEntity: Event::class, cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(name: 'event_id', referencedColumnName: "id", nullable: false)]
private ?Event $event = null;

/**
* @ORM\OneToMany(targetEntity="EventSeoTranslation", mappedBy="eventSeo", cascade={"ALL"}, indexBy="locale")
*
* @Serializer\Exclude
*/
#[Serializer\Exclude]
#[ORM\OneToMany(mappedBy: 'eventSeo', targetEntity: EventSeoTranslation::class, cascade: ['all'], indexBy: 'locale')]
private Collection $translations;

public function __construct()
Expand Down
14 changes: 5 additions & 9 deletions src/Entity/EventSeoTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@
use Doctrine\ORM\Mapping as ORM;
use Manuxi\SuluEventBundle\Entity\Interfaces\SeoTranslationInterface;
use Manuxi\SuluEventBundle\Entity\Traits\SeoTranslationTrait;
use Manuxi\SuluEventBundle\Repository\EventSeoTranslationRepository;

/**
* @ORM\Entity
* @ORM\Table(name="app_event_seo_translation")
* @ORM\Entity(repositoryClass="Manuxi\SuluEventBundle\Repository\EventSeoTranslationRepository")
*/
#[ORM\Entity(repositoryClass: EventSeoTranslationRepository::class)]
#[ORM\Table(name: 'app_event_seo_translation')]
class EventSeoTranslation implements SeoTranslationInterface
{
use SeoTranslationTrait;

/**
* @ORM\ManyToOne(targetEntity="Manuxi\SuluEventBundle\Entity\EventSeo", inversedBy="translations")
* @ORM\JoinColumn(nullable=false)
*/
#[ORM\ManyToOne(targetEntity: EventSeo::class, inversedBy: 'translations')]
#[ORM\JoinColumn(nullable: false)]
private EventSeo $eventSeo;

public function __construct(EventSeo $eventSeo, string $locale)
Expand Down
Loading

0 comments on commit 23fbc5b

Please sign in to comment.