Test Failed
Push — main ( a2096a...c7561b )
by Bingo
15:21
created

hasExcludingConditions()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 8
rs 8.8333
c 0
b 0
f 0
cc 7
nc 7
nop 0
1
<?php
2
3
namespace Jabe\Engine\Impl;
4
5
use Jabe\Engine\{
6
    BadUserRequestException,
7
    ProcessEngineException
8
};
9
use Jabe\Engine\History\{
10
    HistoricProcessInstanceInterface,
11
    HistoricProcessInstanceQueryInterface
12
};
13
use Jabe\Engine\Impl\Cfg\ProcessEngineConfigurationImpl;
14
use Jabe\Engine\Impl\Context\Context;
15
use Jabe\Engine\Impl\Interceptor\{
16
    CommandContext,
17
    CommandExecutorInterface
18
};
19
use Jabe\Engine\Impl\Util\{
20
    CompareUtil,
21
    EnsureUtil,
22
    ImmutablePair
23
};
24
use Jabe\Engine\Impl\Variable\Serializer\VariableSerializersInterface;
25
26
class HistoricProcessInstanceQueryImpl extends AbstractVariableQueryImpl implements HistoricProcessInstanceQueryInterface
27
{
28
    protected $processInstanceId;
29
    protected $processDefinitionId;
30
    protected $processDefinitionName;
31
    protected $processDefinitionNameLike;
32
    protected $businessKey;
33
    protected $businessKeyIn = [];
34
    protected $businessKeyLike;
35
    protected $finished = false;
36
    protected $unfinished = false;
37
    protected $withIncidents = false;
38
    protected $withRootIncidents = false;
39
    protected $incidentType;
40
    protected $incidentStatus;
41
    protected $incidentMessage;
42
    protected $incidentMessageLike;
43
    protected $startedBy;
44
    protected $isRootProcessInstances;
45
    protected $superProcessInstanceId;
46
    protected $subProcessInstanceId;
47
    //protected $superCaseInstanceId;
48
    //protected $subCaseInstanceId;
49
    protected $processKeyNotIn = [];
50
    protected $startedBefore;
51
    protected $startedAfter;
52
    protected $finishedBefore;
53
    protected $finishedAfter;
54
    protected $executedActivityAfter;
55
    protected $executedActivityBefore;
56
    protected $executedJobAfter;
57
    protected $executedJobBefore;
58
    protected $processDefinitionKey;
59
    protected $processDefinitionKeys = [];
60
    protected $processInstanceIds = [];
61
    protected $tenantIds = [];
62
    protected $isTenantIdSet;
63
    protected $executedActivityIds = [];
64
    protected $activeActivityIds = [];
65
    protected $state;
66
    protected $caseInstanceId;
67
    protected $queries = [];
68
    protected $isOrQueryActive = false;
69
    protected $queryVariableNameToValuesMap = [];
70
71
    public function __construct(CommandExecutorInterface $commandExecutor = null)
72
    {
73
        parent::__construct($commandExecutor);
74
        $this->queries[] = $this;
75
    }
76
77
    public function processInstanceId(string $processInstanceId): HistoricProcessInstanceQueryImpl
78
    {
79
        $this->processInstanceId = $processInstanceId;
80
        return $this;
81
    }
82
83
    public function processInstanceIds(array $processInstanceIds): HistoricProcessInstanceQueryInterface
84
    {
85
        EnsureUtil::ensureNotEmpty("Set of process instance ids", "processInstanceIds", $processInstanceIds);
86
        $this->processInstanceIds = $processInstanceIds;
87
        return $this;
88
    }
89
90
    public function processDefinitionId(string $processDefinitionId): HistoricProcessInstanceQueryImpl
91
    {
92
        $this->processDefinitionId = $processDefinitionId;
93
        return $this;
94
    }
95
96
    public function processDefinitionKey(string $processDefinitionKey): HistoricProcessInstanceQueryInterface
97
    {
98
        $this->processDefinitionKey = $processDefinitionKey;
99
        return $this;
100
    }
101
102
    public function processDefinitionKeyIn(array $processDefinitionKeys): HistoricProcessInstanceQueryInterface
103
    {
104
        EnsureUtil::ensureNotNull("processDefinitionKeys", "processDefinitionKeys", $processDefinitionKeys);
105
        $this->processDefinitionKeys = $processDefinitionKeys;
106
        return $this;
107
    }
108
109
    public function processDefinitionName(string $processDefinitionName): HistoricProcessInstanceQueryInterface
110
    {
111
        $this->processDefinitionName = $processDefinitionName;
112
        return $this;
113
    }
114
115
    public function processDefinitionNameLike(string $nameLike): HistoricProcessInstanceQueryInterface
116
    {
117
        $this->processDefinitionNameLike = $nameLike;
118
        return $this;
119
    }
120
121
    public function processInstanceBusinessKey(string $businessKey): HistoricProcessInstanceQueryInterface
122
    {
123
        $this->businessKey = $businessKey;
124
        return $this;
125
    }
126
127
    public function processInstanceBusinessKeyIn(array $businessKeyIn): HistoricProcessInstanceQueryInterface
128
    {
129
        $this->businessKeyIn = $businessKeyIn;
130
        return $this;
131
    }
132
133
    public function processInstanceBusinessKeyLike(string $businessKeyLike): HistoricProcessInstanceQueryInterface
134
    {
135
        $this->businessKeyLike = $businessKeyLike;
136
        return $this;
137
    }
138
139
    public function finished(): HistoricProcessInstanceQueryInterface
140
    {
141
        $this->finished = true;
142
        return $this;
143
    }
144
145
    public function unfinished(): HistoricProcessInstanceQueryInterface
146
    {
147
        $this->unfinished = true;
148
        return $this;
149
    }
150
151
    public function withIncidents(): HistoricProcessInstanceQueryInterface
152
    {
153
        $this->withIncidents = true;
154
        return $this;
155
    }
156
157
    public function withRootIncidents(): HistoricProcessInstanceQueryInterface
158
    {
159
        $this->withRootIncidents = true;
160
        return $this;
161
    }
162
163
    public function incidentType(string $incidentType): HistoricProcessInstanceQueryInterface
164
    {
165
        EnsureUtil::ensureNotNull("incident type", "incidentType", $incidentType);
166
        $this->incidentType = $incidentType;
167
        return $this;
168
    }
169
170
    public function incidentStatus(string $status): HistoricProcessInstanceQueryInterface
171
    {
172
        $this->incidentStatus = $status;
173
        return $this;
174
    }
175
176
    public function incidentMessage(string $incidentMessage): HistoricProcessInstanceQueryInterface
177
    {
178
        EnsureUtil::ensureNotNull("incidentMessage", "incidentMessage", $incidentMessage);
179
        $this->incidentMessage = $incidentMessage;
180
        return $this;
181
    }
182
183
    public function incidentMessageLike(string $incidentMessageLike): HistoricProcessInstanceQueryInterface
184
    {
185
        EnsureUtil::ensureNotNull("incidentMessageLike", "incidentMessageLike", $incidentMessageLike);
186
        $this->incidentMessageLike = $incidentMessageLike;
187
        return $this;
188
    }
189
190
    public function startedBy(string $userId): HistoricProcessInstanceQueryInterface
191
    {
192
        $this->startedBy = $userId;
193
        return $this;
194
    }
195
196
    public function processDefinitionKeyNotIn(array $processDefinitionKeys): HistoricProcessInstanceQueryInterface
197
    {
198
        EnsureUtil::ensureNotContainsNull("processDefinitionKeys", "processDefinitionKeys", $processDefinitionKeys);
199
        EnsureUtil::ensureNotContainsEmptyString("processDefinitionKeys", "processDefinitionKeys", $processDefinitionKeys);
200
        $this->processKeyNotIn = $processDefinitionKeys;
201
        return $this;
202
    }
203
204
    public function startedAfter(string $date): HistoricProcessInstanceQueryInterface
205
    {
206
        $this->startedAfter = $date;
207
        return $this;
208
    }
209
210
    public function startedBefore(string $date): HistoricProcessInstanceQueryInterface
211
    {
212
        $this->startedBefore = $date;
213
        return $this;
214
    }
215
216
    public function finishedAfter(string $date): HistoricProcessInstanceQueryInterface
217
    {
218
        $this->finishedAfter = $date;
219
        $this->finished = true;
220
        return $this;
221
    }
222
223
    public function finishedBefore(string $date): HistoricProcessInstanceQueryInterface
224
    {
225
        $this->finishedBefore = $date;
226
        $this->finished = true;
227
        return $this;
228
    }
229
230
    public function rootProcessInstances(): HistoricProcessInstanceQueryInterface
231
    {
232
        if ($this->superProcessInstanceId != null) {
233
            throw new BadUserRequestException("Invalid query usage: cannot set both rootProcessInstances and superProcessInstanceId");
234
        }
235
        /*if (superCaseInstanceId != null) {
236
            throw new BadUserRequestException("Invalid query usage: cannot set both rootProcessInstances and superCaseInstanceId");
237
        }*/
238
        $this->isRootProcessInstances = true;
239
        return $this;
240
    }
241
242
    public function superProcessInstanceId(string $superProcessInstanceId): HistoricProcessInstanceQueryInterface
243
    {
244
        if ($this->isRootProcessInstances) {
245
            throw new BadUserRequestException("Invalid query usage: cannot set both rootProcessInstances and superProcessInstanceId");
246
        }
247
        $this->superProcessInstanceId = $superProcessInstanceId;
248
        return $this;
249
    }
250
251
    public function subProcessInstanceId(string $subProcessInstanceId): HistoricProcessInstanceQueryInterface
252
    {
253
        $this->subProcessInstanceId = $subProcessInstanceId;
254
        return $this;
255
    }
256
257
    /*public function superCaseInstanceId(string $superCaseInstanceId): HistoricProcessInstanceQueryInterface
258
    {
259
        if ($this->isRootProcessInstances) {
260
            throw new BadUserRequestException("Invalid query usage: cannot set both rootProcessInstances and superCaseInstanceId");
261
        }
262
        $this->superCaseInstanceId = superCaseInstanceId;
263
        return $this;
264
    }
265
266
    public HistoricProcessInstanceQueryInterface subCaseInstanceId(string $subCaseInstanceId) {
267
        $this->subCaseInstanceId = subCaseInstanceId;
268
        return $this;
269
    }
270
271
    public HistoricProcessInstanceQueryInterface caseInstanceId(string $caseInstanceId) {
272
        $this->caseInstanceId = caseInstanceId;
273
        return $this;
274
    }*/
275
276
    public function tenantIdIn(array $tenantIds): HistoricProcessInstanceQueryInterface
277
    {
278
        EnsureUtil::ensureNotNull("tenantIds", "tenantIds", $tenantIds);
279
        $this->tenantIds = $tenantIds;
280
        $this->isTenantIdSet = true;
281
        return $this;
282
    }
283
284
    public function withoutTenantId(): HistoricProcessInstanceQueryInterface
285
    {
286
        $this->tenantIds = null;
287
        $this->isTenantIdSet = true;
288
        return $this;
289
    }
290
291
    protected function hasExcludingConditions(): bool
292
    {
293
        return parent::hasExcludingConditions()
294
            || ($this->finished && $this->unfinished)
295
            || CompareUtil::areNotInAscendingOrder($this->startedAfter, $this->startedBefore)
296
            || CompareUtil::areNotInAscendingOrder($this->finishedAfter, $this->finishedBefore)
297
            || CompareUtil::elementIsContainedInList($this->processDefinitionKey, $this->processKeyNotIn)
298
            || CompareUtil::elementIsNotContainedInList($this->processInstanceId, $this->processInstanceIds);
299
    }
300
301
    public function orderByProcessInstanceBusinessKey(): HistoricProcessInstanceQueryInterface
302
    {
303
        if ($this->isOrQueryActive) {
304
            throw new ProcessEngineException("Invalid query usage: cannot set orderByProcessInstanceBusinessKey() within 'or' query");
305
        }
306
        return $this->orderBy(HistoricProcessInstanceQueryProperty::businessKey());
307
    }
308
309
    public function orderByProcessInstanceDuration(): HistoricProcessInstanceQueryInterface
310
    {
311
        if ($this->isOrQueryActive) {
312
            throw new ProcessEngineException("Invalid query usage: cannot set orderByProcessInstanceDuration() within 'or' query");
313
        }
314
        return $this->orderBy(HistoricProcessInstanceQueryProperty::duration());
315
    }
316
317
    public function orderByProcessInstanceStartTime(): HistoricProcessInstanceQueryInterface
318
    {
319
        if ($this->isOrQueryActive) {
320
            throw new ProcessEngineException("Invalid query usage: cannot set orderByProcessInstanceStartTime() within 'or' query");
321
        }
322
        return $this->orderBy(HistoricProcessInstanceQueryProperty::startTime());
323
    }
324
325
    public function orderByProcessInstanceEndTime(): HistoricProcessInstanceQueryInterface
326
    {
327
        if ($this->isOrQueryActive) {
328
            throw new ProcessEngineException("Invalid query usage: cannot set orderByProcessInstanceEndTime() within 'or' query");
329
        }
330
        return $this->orderBy(HistoricProcessInstanceQueryProperty::endTime());
331
    }
332
333
    public function orderByProcessDefinitionId(): HistoricProcessInstanceQueryInterface
334
    {
335
        if ($this->isOrQueryActive) {
336
            throw new ProcessEngineException("Invalid query usage: cannot set orderByProcessDefinitionId() within 'or' query");
337
        }
338
        return $this->orderBy(HistoricProcessInstanceQueryProperty::processDefinitionId());
339
    }
340
341
    public function orderByProcessDefinitionKey(): HistoricProcessInstanceQueryInterface
342
    {
343
        if ($this->isOrQueryActive) {
344
            throw new ProcessEngineException("Invalid query usage: cannot set orderByProcessDefinitionKey() within 'or' query");
345
        }
346
        return $this->orderBy(HistoricProcessInstanceQueryProperty::processDefinitionKey());
347
    }
348
349
    public function orderByProcessDefinitionName(): HistoricProcessInstanceQueryInterface
350
    {
351
        if ($this->isOrQueryActive) {
352
            throw new ProcessEngineException("Invalid query usage: cannot set orderByProcessDefinitionName() within 'or' query");
353
        }
354
        return $this->orderBy(HistoricProcessInstanceQueryProperty::processDefinitionName());
355
    }
356
357
    public function orderByProcessDefinitionVersion(): HistoricProcessInstanceQueryInterface
358
    {
359
        if ($this->isOrQueryActive) {
360
            throw new ProcessEngineException("Invalid query usage: cannot set orderByProcessDefinitionVersion() within 'or' query");
361
        }
362
        return $this->orderBy(HistoricProcessInstanceQueryProperty::processDefinitionVersion());
363
    }
364
365
    public function orderByProcessInstanceId(): HistoricProcessInstanceQueryInterface
366
    {
367
        if ($this->isOrQueryActive) {
368
            throw new ProcessEngineException("Invalid query usage: cannot set orderByProcessInstanceId() within 'or' query");
369
        }
370
        return $this->orderBy(HistoricProcessInstanceQueryProperty::processInstanceId());
371
    }
372
373
    public function orderByTenantId(): HistoricProcessInstanceQueryInterface
374
    {
375
        if ($this->isOrQueryActive) {
376
            throw new ProcessEngineException("Invalid query usage: cannot set orderByTenantId() within 'or' query");
377
        }
378
        return $this->orderBy(HistoricProcessInstanceQueryProperty::tenantId());
379
    }
380
381
    public function executeCount(CommandContext $commandContext): int
382
    {
383
        $this->checkQueryOk();
384
        EnsureUtil::ensureVariablesInitialized();
385
        return $commandContext
386
            ->getHistoricProcessInstanceManager()
387
            ->findHistoricProcessInstanceCountByQueryCriteria($this);
388
    }
389
390
    public function executeList(CommandContext $commandContext, Page $page): array
391
    {
392
        $this->checkQueryOk();
393
        EnsureUtil::ensureVariablesInitialized();
394
        return $commandContext
395
            ->getHistoricProcessInstanceManager()
396
            ->findHistoricProcessInstancesByQueryCriteria($this, $page);
397
    }
398
399
    public function executeIdsList(CommandContext $commandContext): array
400
    {
401
        $this->checkQueryOk();
402
        EnsureUtil::ensureVariablesInitialized();
403
        return $commandContext
404
            ->getHistoricProcessInstanceManager()
405
            ->findHistoricProcessInstanceIds($this);
406
    }
407
408
    public function executeDeploymentIdMappingsList(CommandContext $commandContext): array
409
    {
410
        $this->checkQueryOk();
411
        EnsureUtil::ensureVariablesInitialized();
412
        return $commandContext
413
            ->getHistoricProcessInstanceManager()
414
            ->findDeploymentIdMappingsByQueryCriteria($this);
415
    }
416
417
    public function getQueryVariableValues(): array
418
    {
419
        return array_values($this->queryVariableNameToValuesMap);
420
    }
421
422
    public function getQueryVariableNameToValuesMap(): array
423
    {
424
        return $this->queryVariableNameToValuesMap;
425
    }
426
427
    protected function ensureVariablesInitialized(): void
428
    {
429
        parent::ensureVariablesInitialized();
430
431
        if (!empty($this->queries)) {
432
            $processEngineConfiguration = Context::getProcessEngineConfiguration();
433
            $variableSerializers = $processEngineConfiguration->getVariableSerializers();
0 ignored issues
show
Bug introduced by
The method getVariableSerializers() does not exist on Jabe\Engine\Impl\Cfg\Pro...EngineConfigurationImpl. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

433
            /** @scrutinizer ignore-call */ 
434
            $variableSerializers = $processEngineConfiguration->getVariableSerializers();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
434
            $dbType = $processEngineConfiguration->getDatabaseType();
435
436
            foreach ($this->queries as $orQuery) {
437
                foreach ($orQuery->getQueryVariableValues() as $var) {
438
                    $var->initialize($variableSerializers, $dbType);
439
                }
440
            }
441
        }
442
    }
443
444
    protected function addVariable(string $name, $value, string $operator, bool $processInstanceScope): void
445
    {
446
        $queryVariableValue = $this->createQueryVariableValue($name, $value, $operator, $processInstanceScope);
447
        if (!array_key_exists($name, $this->queryVariableNameToValuesMap)) {
448
            $this->queryVariableNameToValuesMap[$name] = [$queryVariableValue];
449
        } else {
450
            $this->queryVariableNameToValuesMap[$name][] = $queryVariableValue;
451
        }
452
    }
453
454
    public function getQueries(): array
455
    {
456
        return $this->queries;
457
    }
458
459
    public function addOrQuery(HistoricProcessInstanceQueryImpl $orQuery): void
460
    {
461
        $orQuery->isOrQueryActive = true;
462
        $this->queries[] = $orQuery;
463
    }
464
465
    public function setOrQueryActive(): void
466
    {
467
        $this->isOrQueryActive = true;
468
    }
469
470
    public function isOrQueryActive(): bool
471
    {
472
        return $this->isOrQueryActive;
473
    }
474
475
    public function getActiveActivityIds(): array
476
    {
477
        return $this->activeActivityIds;
478
    }
479
480
    public function getBusinessKey(): string
481
    {
482
        return $this->businessKey;
483
    }
484
485
    public function getBusinessKeyIn(): array
486
    {
487
        return $this->businessKeyIn;
488
    }
489
490
    public function getBusinessKeyLike(): string
491
    {
492
        return $this->businessKeyLike;
493
    }
494
495
    public function getExecutedActivityIds(): array
496
    {
497
        return $this->executedActivityIds;
498
    }
499
500
    public function getExecutedActivityAfter(): string
501
    {
502
        return $this->executedActivityAfter;
503
    }
504
505
    public function getExecutedActivityBefore(): string
506
    {
507
        return $this->executedActivityBefore;
508
    }
509
510
    public function getExecutedJobAfter(): string
511
    {
512
        return $this->executedJobAfter;
513
    }
514
515
    public function getExecutedJobBefore(): string
516
    {
517
        return $this->executedJobBefore;
518
    }
519
520
    public function isOpen(): bool
521
    {
522
        return $this->unfinished;
523
    }
524
525
    public function isUnfinished(): bool
526
    {
527
        return $this->unfinished;
528
    }
529
530
    public function isFinished(): bool
531
    {
532
        return $this->finished;
533
    }
534
535
    public function getProcessDefinitionId(): string
536
    {
537
        return $this->processDefinitionId;
538
    }
539
540
    public function getProcessDefinitionKey(): string
541
    {
542
        return $this->processDefinitionKey;
543
    }
544
545
    public function getProcessDefinitionKeys(): array
546
    {
547
        return $this->processDefinitionKeys;
548
    }
549
550
    public function getProcessDefinitionIdLike(): string
551
    {
552
        return $this->processDefinitionKey . ":%:%";
553
    }
554
555
    public function getProcessDefinitionName(): string
556
    {
557
        return $this->processDefinitionName;
558
    }
559
560
    public function getProcessDefinitionNameLike(): string
561
    {
562
        return $this->processDefinitionNameLike;
563
    }
564
565
    public function getProcessInstanceId(): string
566
    {
567
        return $this->processInstanceId;
568
    }
569
570
    public function getProcessInstanceIds(): array
571
    {
572
        return $this->processInstanceIds;
573
    }
574
575
    public function getStartedBy(): string
576
    {
577
        return $this->startedBy;
578
    }
579
580
    public function getSuperProcessInstanceId(): string
581
    {
582
        return $this->superProcessInstanceId;
583
    }
584
585
    public function setSuperProcessInstanceId(string $superProcessInstanceId): void
586
    {
587
        $this->superProcessInstanceId = $superProcessInstanceId;
588
    }
589
590
    public function getProcessKeyNotIn(): array
591
    {
592
        return $this->processKeyNotIn;
593
    }
594
595
    public function getStartedAfter(): string
596
    {
597
        return $this->startedAfter;
598
    }
599
600
    public function getStartedBefore(): string
601
    {
602
        return $this->startedBefore;
603
    }
604
605
    public function getFinishedAfter(): string
606
    {
607
        return $this->finishedAfter;
608
    }
609
610
    public function getFinishedBefore(): string
611
    {
612
        return $this->finishedBefore;
613
    }
614
615
    /*public String getCaseInstanceId() {
616
        return caseInstanceId;
617
    }*/
618
619
    public function getIncidentType(): string
620
    {
621
        return $this->incidentType;
622
    }
623
624
    public function getIncidentMessage(): string
625
    {
626
        return $this->incidentMessage;
627
    }
628
629
    public function getIncidentMessageLike(): string
630
    {
631
        return $this->incidentMessageLike;
632
    }
633
634
    public function getIncidentStatus(): string
635
    {
636
        return $this->incidentStatus;
637
    }
638
639
    public function getState(): string
640
    {
641
        return $this->state;
642
    }
643
644
    public function getFinishDateBy(): string
645
    {
646
        return $this->finishDateBy;
647
    }
648
649
    public function getStartDateBy(): string
650
    {
651
        return $this->startDateBy;
652
    }
653
654
    public function getStartDateOn(): string
655
    {
656
        return $this->startDateOn;
657
    }
658
659
    public function getStartDateOnBegin(): string
660
    {
661
        return $this->startDateOnBegin;
662
    }
663
664
    public function getStartDateOnEnd(): string
665
    {
666
        return $this->startDateOnEnd;
667
    }
668
669
    public function getFinishDateOn(): string
670
    {
671
        return $this->finishDateOn;
672
    }
673
674
    public function getFinishDateOnBegin(): string
675
    {
676
        return $this->finishDateOnBegin;
677
    }
678
679
    public function getFinishDateOnEnd(): string
680
    {
681
        return $this->finishDateOnEnd;
682
    }
683
684
    public function isTenantIdSet(): bool
685
    {
686
        return $this->isTenantIdSet;
687
    }
688
689
    public function getIsTenantIdSet(): bool
690
    {
691
        return $this->isTenantIdSet;
692
    }
693
694
    public function isWithIncidents(): bool
695
    {
696
        return $this->withIncidents;
697
    }
698
699
    public function isWithRootIncidents(): bool
700
    {
701
        return $this->withRootIncidents;
702
    }
703
704
    protected $startDateBy;
705
    protected $startDateOn;
706
    protected $finishDateBy;
707
    protected $finishDateOn;
708
    protected $startDateOnBegin;
709
    protected $startDateOnEnd;
710
    protected $finishDateOnBegin;
711
    protected $finishDateOnEnd;
712
713
    public function startDateBy(string $date): HistoricProcessInstanceQueryInterface
714
    {
715
        $this->startDateBy = $this->calculateMidnight($date);
716
        return $this;
717
    }
718
719
    public function startDateOn(string $date): HistoricProcessInstanceQueryInterface
720
    {
721
        $this->startDateOn = $date;
722
        $this->startDateOnBegin = $this->calculateMidnight($date);
723
        $this->startDateOnEnd = $this->calculateBeforeMidnight($date);
724
        return $this;
725
    }
726
727
    public function finishDateBy(string $date): HistoricProcessInstanceQueryInterface
728
    {
729
        $this->finishDateBy = $this->calculateBeforeMidnight($date);
730
        return $this;
731
    }
732
733
    public function finishDateOn(string $date): HistoricProcessInstanceQueryInterface
734
    {
735
        $this->finishDateOn = $date;
736
        $this->finishDateOnBegin = $this->calculateMidnight($date);
737
        $this->finishDateOnEnd = $this->calculateBeforeMidnight($date);
738
        return $this;
739
    }
740
741
    private function calculateBeforeMidnight(string $date): string
742
    {
743
        return (new \DateTime())->setTimestamp(strtotime("+1 day -1 second", strtotime($date)))->format('c');
744
    }
745
746
    private function calculateMidnight(string $date): string
747
    {
748
        $date = new \DateTime($date);
749
        $date->setTime(0, 0, 0, 0);
750
        return $date->format('c');
751
    }
752
753
    public function isRootProcessInstances(): bool
754
    {
755
        return $this->isRootProcessInstances;
756
    }
757
758
    public function getSubProcessInstanceId(): string
759
    {
760
        return $this->subProcessInstanceId;
761
    }
762
763
    /*public String getSuperCaseInstanceId() {
764
        return superCaseInstanceId;
765
    }
766
767
    public String getSubCaseInstanceId() {
768
        return subCaseInstanceId;
769
    }*/
770
771
    public function getTenantIds(): array
772
    {
773
        return $this->tenantIds;
774
    }
775
776
    public function executedActivityAfter(string $date): HistoricProcessInstanceQueryInterface
777
    {
778
        $this->executedActivityAfter = $date;
779
        return $this;
780
    }
781
782
    public function executedActivityBefore(string $date): HistoricProcessInstanceQueryInterface
783
    {
784
        $this->executedActivityBefore = $date;
785
        return $this;
786
    }
787
788
    public function executedJobAfter(string $date): HistoricProcessInstanceQueryInterface
789
    {
790
        $this->executedJobAfter = $date;
791
        return $this;
792
    }
793
794
    public function executedJobBefore(string $date): HistoricProcessInstanceQueryInterface
795
    {
796
        $this->executedJobBefore = $date;
797
        return $this;
798
    }
799
800
    public function executedActivityIdIn(array $ids): HistoricProcessInstanceQueryInterface
801
    {
802
        EnsureUtil::ensureNotNull("activity ids", "ids", $ids);
803
        EnsureUtil::ensureNotContainsNull("activity ids", "ids", $ids);
804
        $this->executedActivityIds = $ids;
805
        return $this;
806
    }
807
808
    public function activeActivityIdIn(array $ids): HistoricProcessInstanceQueryInterface
809
    {
810
        EnsureUtil::ensureNotNull("activity ids", "ids", $ids);
811
        EnsureUtil::ensureNotContainsNull("activity ids", "ids", $ids);
812
        $this->activeActivityIds = $ids;
813
        return $this;
814
    }
815
816
    public function active(): HistoricProcessInstanceQueryInterface
817
    {
818
        EnsureUtil::ensureNull("Already querying for historic process instance with another state", "state", $this->state);
819
        $state = HistoricProcessInstanceInterface::STATE_ACTIVE;
0 ignored issues
show
Unused Code introduced by
The assignment to $state is dead and can be removed.
Loading history...
820
        return $this;
821
    }
822
823
    public function suspended(): HistoricProcessInstanceQueryInterface
824
    {
825
        EnsureUtil::ensureNull("Already querying for historic process instance with another state", "state", $this->state);
826
        $this->state = HistoricProcessInstanceInterface::STATE_SUSPENDED;
827
        return $this;
828
    }
829
830
    public function completed(): HistoricProcessInstanceQueryInterface
831
    {
832
        EnsureUtil::ensureNull("Already querying for historic process instance with another state", "state", $this->state);
833
        $this->state = HistoricProcessInstanceInterface::STATE_COMPLETED;
834
        return $this;
835
    }
836
837
    public function externallyTerminated(): HistoricProcessInstanceQueryInterface
838
    {
839
        EnsureUtil::ensureNull("Already querying for historic process instance with another state", "state", $this->state);
840
        $this->state = HistoricProcessInstanceInterface::STATE_EXTERNALLY_TERMINATED;
841
        return $this;
842
    }
843
844
    public function internallyTerminated(): HistoricProcessInstanceQueryInterface
845
    {
846
        EnsureUtil::ensureNull("Already querying for historic process instance with another state", "state", $this->state);
847
        $this->state = HistoricProcessInstanceInterface::STATE_INTERNALLY_TERMINATED;
848
        return $this;
849
    }
850
851
    public function or(): HistoricProcessInstanceQueryInterface
852
    {
853
        if ($this != $this->queries[0]) {
854
            throw new ProcessEngineException("Invalid query usage: cannot set or() within 'or' query");
855
        }
856
        $orQuery = new HistoricProcessInstanceQueryImpl();
857
        $orQuery->isOrQueryActive = true;
858
        $orQuery->queries = $queries;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $queries seems to be never defined.
Loading history...
859
        $this->queries[] = $orQuery;
860
        return $orQuery;
861
    }
862
863
    public function endOr(): HistoricProcessInstanceQueryInterface
864
    {
865
        if (!empty($this->queries) && $this != $this->queries[count($this->queries) - 1]) {
866
            throw new ProcessEngineException("Invalid query usage: cannot set endOr() before or()");
867
        }
868
        return $this->queries[0];
869
    }
870
}
871