19declare(strict_types=1);
31 private ?DateTimeImmutable $start_date =
null,
32 private ?
int $period =
null,
33 private bool $only_public =
false,
34 private ?
int $min_priority =
null,
35 private ?
int $max_priority =
null,
36 private ?
int $limit =
null,
37 private bool $prevent_nesting =
false,
38 private bool $no_auto_generated =
false,
39 private array $excluded_news_ids = [],
40 private ?
bool $include_read_status =
null,
41 private ?
int $read_user_id =
null,
44 $this->include_read_status = $this->include_read_status ?? !$this->only_public;
53 return $this->start_date;
63 return $this->only_public;
68 return $this->min_priority;
73 return $this->max_priority;
83 return $this->prevent_nesting;
88 return $this->no_auto_generated;
93 return $this->excluded_news_ids;
98 return $this->include_read_status ??
false;
103 return $this->read_user_id;
109 $new->start_date = $start_date;
116 $new->period = $period;
123 $new->only_public = $only_public;
130 $new->min_priority = $min_priority;
137 $new->max_priority = $max_priority;
144 $new->limit = $limit;
151 $new->prevent_nesting = $stop_nesting;
158 $new->no_auto_generated = $no_auto_generated;
165 $new->excluded_news_ids = array_map(
'intval', $excluded_news_ids);
172 $new->include_read_status = $include_read_status;
179 $new->read_user_id = $read_user_id;
195 'start_date' => $this->start_date?->format(
'Y-m-d H:i:s'),
196 'period' => $this->period,
197 'only_public' => $this->only_public,
198 'min_priority' => $this->min_priority,
199 'max_priority' => $this->max_priority,
200 'limit' => $this->limit,
201 'stop_nesting' => $this->prevent_nesting,
202 'no_auto_generated' => $this->no_auto_generated,
203 'excluded_news_ids' => $this->excluded_news_ids,
204 'include_read_status' => $this->include_read_status,
205 'read_user_id' => $this->read_user_id,
214 return $this->min_priority !==
null || $this->max_priority !==
null;
222 if ($this->min_priority !==
null && $this->max_priority !==
null && $this->min_priority > $this->max_priority) {
223 throw new \InvalidArgumentException(
'Min priority cannot be greater than max priority');
226 if ($this->limit !==
null && $this->limit < 0) {
227 throw new \InvalidArgumentException(
'Limit cannot be negative');
News Criteria DTO for querying news items supports caching, JSON serialization, and validation.
withMaxPriority(?int $max_priority)
withPreventNesting(bool $stop_nesting)
withStartDate(?DateTimeImmutable $start_date)
validate()
Validate criteria parameters.
__construct(private ?DateTimeImmutable $start_date=null, private ?int $period=null, private bool $only_public=false, private ?int $min_priority=null, private ?int $max_priority=null, private ?int $limit=null, private bool $prevent_nesting=false, private bool $no_auto_generated=false, private array $excluded_news_ids=[], private ?bool $include_read_status=null, private ?int $read_user_id=null,)
withExcludedNewsIds(array $excluded_news_ids)
withNoAutoGenerated(bool $no_auto_generated)
withIncludeReadStatus(bool $include_read_status)
hasPriorityFilters()
Check if criteria has priority filters.
withMinPriority(?int $min_priority)
withReadUserId(?int $read_user_id)
withOnlyPublic(bool $only_public)