commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
SearchDateRangeValueModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
15 use DateTimeImmutable;
16 use stdClass;
17 
22 {
27  protected $field;
28 
33  protected $boost;
34 
39  protected $fieldType;
40 
45  protected $gte;
46 
51  protected $gt;
52 
57  protected $lte;
58 
63  protected $lt;
64 
65 
69  public function __construct(
70  ?string $field = null,
71  ?float $boost = null,
72  ?string $fieldType = null,
73  ?DateTimeImmutable $gte = null,
74  ?DateTimeImmutable $gt = null,
75  ?DateTimeImmutable $lte = null,
76  ?DateTimeImmutable $lt = null
77  ) {
78  $this->field = $field;
79  $this->boost = $boost;
80  $this->fieldType = $fieldType;
81  $this->gte = $gte;
82  $this->gt = $gt;
83  $this->lte = $lte;
84  $this->lt = $lt;
85  }
86 
91  public function getField()
92  {
93  if (is_null($this->field)) {
95  $data = $this->raw(self::FIELD_FIELD);
96  if (is_null($data)) {
97  return null;
98  }
99  $this->field = (string) $data;
100  }
101 
102  return $this->field;
103  }
104 
109  public function getBoost()
110  {
111  if (is_null($this->boost)) {
113  $data = $this->raw(self::FIELD_BOOST);
114  if (is_null($data)) {
115  return null;
116  }
117  $this->boost = (float) $data;
118  }
119 
120  return $this->boost;
121  }
122 
129  public function getFieldType()
130  {
131  if (is_null($this->fieldType)) {
133  $data = $this->raw(self::FIELD_FIELD_TYPE);
134  if (is_null($data)) {
135  return null;
136  }
137  $this->fieldType = (string) $data;
138  }
139 
140  return $this->fieldType;
141  }
142 
147  public function getGte()
148  {
149  if (is_null($this->gte)) {
151  $data = $this->raw(self::FIELD_GTE);
152  if (is_null($data)) {
153  return null;
154  }
155  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATE_FORMAT, $data);
156  if (false === $data) {
157  return null;
158  }
159  $this->gte = $data;
160  }
161 
162  return $this->gte;
163  }
164 
169  public function getGt()
170  {
171  if (is_null($this->gt)) {
173  $data = $this->raw(self::FIELD_GT);
174  if (is_null($data)) {
175  return null;
176  }
177  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATE_FORMAT, $data);
178  if (false === $data) {
179  return null;
180  }
181  $this->gt = $data;
182  }
183 
184  return $this->gt;
185  }
186 
191  public function getLte()
192  {
193  if (is_null($this->lte)) {
195  $data = $this->raw(self::FIELD_LTE);
196  if (is_null($data)) {
197  return null;
198  }
199  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATE_FORMAT, $data);
200  if (false === $data) {
201  return null;
202  }
203  $this->lte = $data;
204  }
205 
206  return $this->lte;
207  }
208 
213  public function getLt()
214  {
215  if (is_null($this->lt)) {
217  $data = $this->raw(self::FIELD_LT);
218  if (is_null($data)) {
219  return null;
220  }
221  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATE_FORMAT, $data);
222  if (false === $data) {
223  return null;
224  }
225  $this->lt = $data;
226  }
227 
228  return $this->lt;
229  }
230 
231 
235  public function setField(?string $field): void
236  {
237  $this->field = $field;
238  }
239 
243  public function setBoost(?float $boost): void
244  {
245  $this->boost = $boost;
246  }
247 
251  public function setFieldType(?string $fieldType): void
252  {
253  $this->fieldType = $fieldType;
254  }
255 
259  public function setGte(?DateTimeImmutable $gte): void
260  {
261  $this->gte = $gte;
262  }
263 
267  public function setGt(?DateTimeImmutable $gt): void
268  {
269  $this->gt = $gt;
270  }
271 
275  public function setLte(?DateTimeImmutable $lte): void
276  {
277  $this->lte = $lte;
278  }
279 
283  public function setLt(?DateTimeImmutable $lt): void
284  {
285  $this->lt = $lt;
286  }
287 
288 
289  #[\ReturnTypeWillChange]
290  public function jsonSerialize()
291  {
292  $data = $this->toArray();
293  if (isset($data[SearchDateRangeValue::FIELD_GTE]) && $data[SearchDateRangeValue::FIELD_GTE] instanceof \DateTimeImmutable) {
294  $data[SearchDateRangeValue::FIELD_GTE] = $data[SearchDateRangeValue::FIELD_GTE]->format('Y-m-d');
295  }
296 
297  if (isset($data[SearchDateRangeValue::FIELD_GT]) && $data[SearchDateRangeValue::FIELD_GT] instanceof \DateTimeImmutable) {
298  $data[SearchDateRangeValue::FIELD_GT] = $data[SearchDateRangeValue::FIELD_GT]->format('Y-m-d');
299  }
300 
301  if (isset($data[SearchDateRangeValue::FIELD_LTE]) && $data[SearchDateRangeValue::FIELD_LTE] instanceof \DateTimeImmutable) {
302  $data[SearchDateRangeValue::FIELD_LTE] = $data[SearchDateRangeValue::FIELD_LTE]->format('Y-m-d');
303  }
304 
305  if (isset($data[SearchDateRangeValue::FIELD_LT]) && $data[SearchDateRangeValue::FIELD_LT] instanceof \DateTimeImmutable) {
306  $data[SearchDateRangeValue::FIELD_LT] = $data[SearchDateRangeValue::FIELD_LT]->format('Y-m-d');
307  }
308  return (object) $data;
309  }
310 }
__construct(?string $field=null, ?float $boost=null, ?string $fieldType=null, ?DateTimeImmutable $gte=null, ?DateTimeImmutable $gt=null, ?DateTimeImmutable $lte=null, ?DateTimeImmutable $lt=null)