Add new properties and change constructor

[MAILPOET-3427]
This commit is contained in:
Jan Lysý
2021-10-22 10:28:29 +02:00
committed by Veljko V
parent c51d5afd48
commit 78e763deee

View File

@ -1,4 +1,4 @@
<?php <?php declare(strict_types = 1);
namespace MailPoet\Entities; namespace MailPoet\Entities;
@ -23,19 +23,30 @@ class DynamicSegmentFilterData {
*/ */
private $filterData; private $filterData;
/**
* @ORM\Column(type="string", nullable=true)
* @var string|null
*/
private $filterType;
/**
* @ORM\Column(type="string", nullable=true)
* @var string|null
*/
private $action;
public function __construct( public function __construct(
array $filterData string $filterType,
string $action,
array $filterData = []
) { ) {
$this->filterType = $filterType;
$this->action = $action;
$this->filterData = $filterData; $this->filterData = $filterData;
} }
public function getData(): ?array { public function getData(): ?array {
$filterData = $this->filterData; return $this->filterData;
// bc compatibility, the wordpress user role segment didn't have action
if (($this->filterData['segmentType'] ?? null) === self::TYPE_USER_ROLE && !isset($this->filterData['action'])) {
$filterData['action'] = UserRole::TYPE;
}
return $filterData;
} }
/** /**
@ -46,7 +57,14 @@ class DynamicSegmentFilterData {
} }
public function getFilterType(): ?string { public function getFilterType(): ?string {
$filterData = $this->getData(); return $this->filterType;
return $filterData['segmentType'] ?? null; }
public function getAction(): ?string {
// bc compatibility, the wordpress user role segment didn't have action
if ($this->getFilterType() === self::TYPE_USER_ROLE && !$this->action) {
return UserRole::TYPE;
}
return $this->action;
} }
} }