Passed
Push — main ( 552299...788265 )
by Iain
19:00
created

LessThanOrEqualFilter::modifyQueryBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Humbly Arrogant Software Limited 2020-2023.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: 26.06.2026 ( 3 years after 2.2.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace App\Parthenon\Athena\Filters;
16
17
use Doctrine\ORM\Query;
18
use Doctrine\ORM\QueryBuilder;
19
use Parthenon\Athena\Filters\DoctrineFilterInterface;
20
use Parthenon\Athena\Filters\FilterInterface;
21
use Parthenon\Athena\Filters\QueryBuilderTrait;
22
23
class LessThanOrEqualFilter implements DoctrineFilterInterface
24
{
25
    use QueryBuilderTrait;
26
27
    public const NAME = 'less_than_or_equal';
28
29
    protected string $fieldName;
30
31
    private $data;
32
33
    public function modifyQueryBuilder(QueryBuilder $queryBuilder)
34
    {
35
        if (!$this->data) {
36
            return;
37
        }
38
        [$alias, $fieldName] = $this->readyQueryBuilderForAliasAndFieldName($queryBuilder);
39
        $queryBuilder->andWhere($alias.'.'.$fieldName.' <= :'.$this->getSafeFieldName());
40
    }
41
42
    public function modifyQuery(Query $query)
43
    {
44
        if (!$this->data) {
45
            return;
46
        }
47
        $query->setParameter(':'.$this->getSafeFieldName(), $this->data);
48
    }
49
50
    public function getName(): string
51
    {
52
        return static::NAME;
53
    }
54
55
    public function setData($data): FilterInterface
56
    {
57
        $this->data = $data;
58
59
        return $this;
60
    }
61
62
    public function setFieldName(string $fieldName): FilterInterface
63
    {
64
        $this->fieldName = $fieldName;
65
66
        return $this;
67
    }
68
69
    public function getFieldName(): string
70
    {
71
        return $this->fieldName;
72
    }
73
74
    public function getHeaderName(): string
75
    {
76
        return ucwords(str_replace('_', ' ', $this->fieldName));
77
    }
78
79
    public function getData()
80
    {
81
        return $this->data;
82
    }
83
84
    public function hasData(): bool
85
    {
86
        return isset($this->data);
87
    }
88
}
89