Add dynamic segments filter entity
[MAILPOET-3077]
This commit is contained in:
committed by
Veljko V
parent
814686e8d2
commit
d18d3b052d
68
lib/Entities/DynamicSegmentFilterEntity.php
Normal file
68
lib/Entities/DynamicSegmentFilterEntity.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Entities;
|
||||
|
||||
use MailPoet\Doctrine\EntityTraits\AutoincrementedIdTrait;
|
||||
use MailPoet\Doctrine\EntityTraits\CreatedAtTrait;
|
||||
use MailPoet\Doctrine\EntityTraits\SafeToOneAssociationLoadTrait;
|
||||
use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait;
|
||||
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="dynamic_segment_filters")
|
||||
*/
|
||||
class DynamicSegmentFilterEntity {
|
||||
use AutoincrementedIdTrait;
|
||||
use CreatedAtTrait;
|
||||
use UpdatedAtTrait;
|
||||
use SafeToOneAssociationLoadTrait;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="MailPoet\Entities\SegmentEntity", inversedBy="filters")
|
||||
* @var SegmentEntity|null
|
||||
*/
|
||||
private $segment;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="serialized_array")
|
||||
* @var array|null
|
||||
*/
|
||||
private $filterData;
|
||||
|
||||
public function __construct(SegmentEntity $segment, array $filterData) {
|
||||
$this->segment = $segment;
|
||||
$this->filterData = $filterData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SegmentEntity|null
|
||||
*/
|
||||
public function getSegment() {
|
||||
$this->safelyLoadToOneAssociation('segment');
|
||||
return $this->segment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getFilterData() {
|
||||
return $this->filterData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSegmentType() {
|
||||
$filterData = $this->getFilterData();
|
||||
return $filterData['segmentType'] ?? null;
|
||||
}
|
||||
|
||||
public function setSegment(SegmentEntity $segment) {
|
||||
$this->segment = $segment;
|
||||
}
|
||||
|
||||
public function setFilterData(array $filterData) {
|
||||
$this->filterData = $filterData;
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ use MailPoet\Doctrine\EntityTraits\AutoincrementedIdTrait;
|
||||
use MailPoet\Doctrine\EntityTraits\CreatedAtTrait;
|
||||
use MailPoet\Doctrine\EntityTraits\DeletedAtTrait;
|
||||
use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait;
|
||||
use MailPoetVendor\Doctrine\Common\Collections\ArrayCollection;
|
||||
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
||||
use MailPoetVendor\Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
@ -43,6 +44,19 @@ class SegmentEntity {
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="MailPoet\Entities\DynamicSegmentFilterEntity", mappedBy="segment")
|
||||
* @var DynamicSegmentFilterEntity[]|ArrayCollection
|
||||
*/
|
||||
private $dynamicFilters;
|
||||
|
||||
public function __construct(string $name, string $type, string $description = '') {
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
$this->dynamicFilters = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@ -84,4 +98,11 @@ class SegmentEntity {
|
||||
public function setDescription($description) {
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DynamicSegmentFilterEntity[]|ArrayCollection
|
||||
*/
|
||||
public function getDynamicFilters() {
|
||||
return $this->dynamicFilters;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user