Add getter for operator

[MAILPOET-3954]
This commit is contained in:
Jan Lysý
2021-11-25 17:20:18 +01:00
committed by Veljko V
parent d9d91de0f6
commit bdd4587fd3

View File

@@ -3,6 +3,7 @@
namespace MailPoet\Entities; namespace MailPoet\Entities;
use MailPoet\Segments\DynamicSegments\Filters\UserRole; use MailPoet\Segments\DynamicSegments\Filters\UserRole;
use MailPoet\Segments\DynamicSegments\Filters\WooCommerceProduct;
use MailPoetVendor\Doctrine\ORM\Mapping as ORM; use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
/** /**
@@ -17,9 +18,9 @@ class DynamicSegmentFilterData {
public const CONNECT_TYPE_AND = 'and'; public const CONNECT_TYPE_AND = 'and';
public const CONNECT_TYPE_OR = 'or'; public const CONNECT_TYPE_OR = 'or';
const OPERATOR_ANY = 'any'; public const OPERATOR_ALL = 'all';
const OPERATOR_ALL = 'all'; public const OPERATOR_ANY = 'any';
const OPERATOR_NONE = 'none'; public const OPERATOR_NONE = 'none';
/** /**
* @ORM\Column(type="serialized_array") * @ORM\Column(type="serialized_array")
@@ -79,4 +80,20 @@ class DynamicSegmentFilterData {
} }
return $this->filterData['action'] ?? null; return $this->filterData['action'] ?? null;
} }
public function getOperator(): ?string {
$operator = $this->filterData['operator'] ?? null;
if (!$operator) {
return $this->getDefaultOperator();
}
return $operator;
}
private function getDefaultOperator(): ?string {
if ($this->getFilterType() === self::TYPE_WOOCOMMERCE && $this->getAction() === WooCommerceProduct::ACTION_PRODUCT) {
return self::OPERATOR_ANY;
}
return null;
}
} }