Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows entities to be extended by a custom parent class #12

Merged
merged 8 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"symfony/dotenv": "^4.4",
"symfony/flex": "^1.7",
"symfony/web-profiler-bundle": "^4.4",
"phpmd/phpmd": "@stable"
"phpmd/phpmd": "@stable",
"http-interop/http-factory-guzzle": "^1.2"
},
"prefer-stable": true,
"autoload": {
Expand Down
83 changes: 9 additions & 74 deletions src/Entity/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Timestampable;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
Expand All @@ -28,10 +26,6 @@
use Sylius\Component\Resource\Model\TranslatableInterface;
use Sylius\Component\Resource\Model\TranslatableTrait;

/**
* @ORM\Entity
* @ORM\Table(name="mbiz_alert_message")
*/
class Message implements ResourceInterface, TimestampableInterface, ToggleableInterface, TranslatableInterface, Timestampable
{
use TimestampableTrait;
Expand All @@ -44,81 +38,22 @@ class Message implements ResourceInterface, TimestampableInterface, ToggleableIn
getTranslation as private doGetTranslation;
}

/**
* @var int|null
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
protected ?int $id = null;

/**
* @var bool
* @ORM\Column(type="boolean", options={"default"=true})
*/
protected $enabled = true;

/**
* @var bool
* @ORM\Column(name="customers_only", type="boolean", options={"default"=false})
*/
protected $customersOnly = false;

/**
* @var string|null
* @ORM\Column(type="string")
*/
protected $name;

/**
* @var string|null
* @ORM\Column(type="string", nullable=true)
*/
protected $description;
protected bool $customersOnly = false;

/**
* @var Collection<int, ChannelInterface>
* @ORM\ManyToMany(targetEntity="\Sylius\Component\Core\Model\ChannelInterface")
* @ORM\JoinTable(
* name="mbiz_alert_message_channels",
* joinColumns={@ORM\JoinColumn(name="message_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="channel_id", referencedColumnName="id")}
* )
*/
private $channels;
protected ?string $name = null;

/**
* @var DateTimeInterface|null
* @ORM\Column(name="created_at", type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
protected $createdAt;
protected ?string $description = null;

/**
* @var DateTimeInterface|null
* @ORM\Column(name="updated_at", type="datetime")
* @Gedmo\Timestampable(on="update")
*/
protected $updatedAt;
/** @var Collection<int, ChannelInterface> */
protected Collection $channels;

/**
* @var string|null
* @ORM\Column(name="template_html", type="text", nullable=true)
*/
private $templateHtml;
protected ?string $templateHtml = null;

/**
* @var DateTimeInterface|null
* @ORM\Column(name="from_date", type="datetime", nullable=true)
*/
private $fromDate;
protected ?DateTimeInterface $fromDate = null;

/**
* @var DateTimeInterface|null
* @ORM\Column(name="to_date", type="datetime", nullable=true)
*/
private $toDate;
protected ?DateTimeInterface $toDate = null;

/**
* Message constructor.
Expand Down
29 changes: 4 additions & 25 deletions src/Entity/MessageTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,16 @@

namespace MonsieurBiz\SyliusAlertMessagePlugin\Entity;

use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Resource\Model\AbstractTranslation;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\TranslationInterface;

/**
* @ORM\Entity
* @ORM\Table(name="mbiz_alert_message_translation")
*/
class MessageTranslation extends AbstractTranslation implements TranslationInterface, ResourceInterface
class MessageTranslation extends AbstractTranslation implements ResourceInterface
{
/**
* @var int|null
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private $id;
protected ?int $id = null;

/**
* @var string|null
* @ORM\Column(type="string", nullable=true)
*/
private $title;
protected ?string $title = null;

/**
* @var string|null
* @ORM\Column(type="text")
*/
private $message;
protected ?string $message = null;

public function getId(): ?int
{
Expand Down
54 changes: 54 additions & 0 deletions src/Resources/config/doctrine/Message.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>

<mapped-superclass name="MonsieurBiz\SyliusAlertMessagePlugin\Entity\Message" table="mbiz_alert_message">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
<field name="enabled" column="enabled" type="boolean">
<options>
<option name="default">1</option>
</options>
</field>

<field name="customersOnly" column="customers_only" type="boolean">
<options>
<option name="default">0</option>
</options>
</field>

<field name="name" column="name" type="string" />
<field name="description" column="description" type="string" nullable="true" />

<many-to-many field="channels" target-entity="Sylius\Component\Core\Model\ChannelInterface">
<join-table name="mbiz_alert_message_channels">
<join-columns>
<join-column name="message_id" />
</join-columns>
<inverse-join-columns>
<join-column name="channel_id" />
</inverse-join-columns>
</join-table>
</many-to-many>

<field name="createdAt" column="created_at" type="datetime_immutable">
<gedmo:timestampable on="create"/>
</field>

<field name="updatedAt" column="updated_at" type="datetime">
<gedmo:timestampable on="update"/>
</field>

<field name="templateHtml" column="template_html" type="text" nullable="true" />
<field name="fromDate" column="from_date" type="datetime" nullable="true" />
<field name="toDate" column="to_date" type="datetime" nullable="true" />
</mapped-superclass>

</doctrine-mapping>
19 changes: 19 additions & 0 deletions src/Resources/config/doctrine/MessageTranslation.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>

<mapped-superclass name="MonsieurBiz\SyliusAlertMessagePlugin\Entity\MessageTranslation" table="mbiz_alert_message_translation">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>

<field name="title" column="title" type="string" nullable="true" />
<field name="message" column="message" type="text" />
</mapped-superclass>

</doctrine-mapping>
Loading