Completed
Pull Request — dev (#67)
by
unknown
01:18
created

EntryQueryEntryrelationshipAdapter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createFilterIncludes() 0 8 1
A filterSingle() 0 10 2
A getFilterColumns() 0 4 1
A getSortColumns() 0 4 1
1
<?php
2
3
/**
4
 * @package toolkit
5
 */
6
/**
7
 * Specialized EntryQueryFieldAdapter that facilitate creation of queries filtering/sorting data from
8
 * an entryrelationship Field.
9
 * @see FieldTextarea
10
 * @since Symphony 3.0.0
11
 */
12
class EntryQueryEntryrelationshipAdapter extends EntryQueryFieldAdapter
13
{
14
    public function createFilterIncludes($filter, array $columns)
15
    {
16
        $field_id = General::intval($this->field->get('id'));
17
        $filter = $this->field->cleanValue($filter);
18
19
        $conditions = $this->field->generateWhereFilter($filter, 'f' . $field_id);
20
        return $conditions;
21
    }
22
23
    /**
24
     * @see EntryQueryFieldAdapter::filterSingle()
25
     *
26
     * @param EntryQuery $query
27
     * @param string $filter
28
     * @return array
29
     */
30
    protected function filterSingle(EntryQuery $query, $filter)
31
    {
32
        General::ensureType([
33
            'filter' => ['var' => $filter, 'type' => 'string'],
34
        ]);
35
        if ($this->isFilterRegex($filter)) {
36
            return $this->createFilterRegexp($filter, $this->getFilterColumns());
37
        }
38
        return $this->createFilterIncludes($filter, $this->getFilterColumns());
39
    }
40
41
    public function getFilterColumns()
42
    {
43
        return ['entries'];
44
    }
45
46
    public function getSortColumns()
47
    {
48
        return ['entries'];
49
    }
50
}
51