mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Use an enum for tag match type
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Dto;
|
||||
|
||||
use App\Enums\TagMatchType;
|
||||
use App\Enums\TimeEntryAggregationType;
|
||||
use App\Enums\TimeEntryAggregationTypeInterval;
|
||||
use App\Enums\TimeEntryRoundingType;
|
||||
@@ -56,7 +57,7 @@ class ReportPropertiesDto implements Castable
|
||||
*/
|
||||
public ?Collection $tagIds = null;
|
||||
|
||||
public ?string $tagMatchType = null;
|
||||
public ?TagMatchType $tagMatchType = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, string>|null
|
||||
@@ -117,7 +118,7 @@ class ReportPropertiesDto implements Castable
|
||||
$dto->clientIds = $data->clientIds !== null ? ReportPropertiesDto::idArrayToCollection($data->clientIds) : null;
|
||||
$dto->projectIds = $data->projectIds !== null ? ReportPropertiesDto::idArrayToCollection($data->projectIds) : null;
|
||||
$dto->tagIds = $data->tagIds !== null ? ReportPropertiesDto::idArrayToCollection($data->tagIds) : null;
|
||||
$dto->tagMatchType = isset($data->tagMatchType) ? ReportPropertiesDto::tagMatchTypeValue($data->tagMatchType) : null;
|
||||
$dto->tagMatchType = isset($data->tagMatchType) ? TagMatchType::from($data->tagMatchType) : null;
|
||||
$dto->taskIds = $data->taskIds ? ReportPropertiesDto::idArrayToCollection($data->taskIds) : null;
|
||||
$dto->group = TimeEntryAggregationType::from($data->group);
|
||||
$dto->subGroup = TimeEntryAggregationType::from($data->subGroup);
|
||||
@@ -147,7 +148,7 @@ class ReportPropertiesDto implements Castable
|
||||
'clientIds' => $value->clientIds?->toArray(),
|
||||
'projectIds' => $value->projectIds?->toArray(),
|
||||
'tagIds' => $value->tagIds?->toArray(),
|
||||
'tagMatchType' => $value->tagMatchType,
|
||||
'tagMatchType' => $value->tagMatchType?->value,
|
||||
'taskIds' => $value->taskIds?->toArray(),
|
||||
'group' => $value->group->value,
|
||||
'subGroup' => $value->subGroup->value,
|
||||
@@ -188,24 +189,6 @@ class ReportPropertiesDto implements Castable
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'contains'|'not_contains'|null
|
||||
*/
|
||||
public static function tagMatchTypeValue(mixed $tagMatchType): ?string
|
||||
{
|
||||
if ($tagMatchType === null) {
|
||||
return null;
|
||||
}
|
||||
if (! is_string($tagMatchType)) {
|
||||
throw new \InvalidArgumentException('The given tag match type is not a string');
|
||||
}
|
||||
if (! in_array($tagMatchType, [TimeEntryFilter::TAG_MATCH_TYPE_CONTAINS, TimeEntryFilter::TAG_MATCH_TYPE_NOT_CONTAINS], true)) {
|
||||
throw new \InvalidArgumentException('The given tag match type is not valid');
|
||||
}
|
||||
|
||||
return $tagMatchType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed>|null $memberIds
|
||||
*/
|
||||
@@ -238,9 +221,9 @@ class ReportPropertiesDto implements Castable
|
||||
$this->tagIds = $tagIds !== null ? ReportPropertiesDto::idArrayToCollection($tagIds) : null;
|
||||
}
|
||||
|
||||
public function setTagMatchType(mixed $tagMatchType): void
|
||||
public function setTagMatchType(?TagMatchType $tagMatchType): void
|
||||
{
|
||||
$this->tagMatchType = ReportPropertiesDto::tagMatchTypeValue($tagMatchType);
|
||||
$this->tagMatchType = $tagMatchType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user