Completed
Push — master ( 574a1e...c86379 )
by Henri
03:52
created

ConceptSearchParameters::getParentLimit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * ConceptSearchParameters is used for search parameters.
5
 */
6
class ConceptSearchParameters
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
9
    private $config;
10
    private $request;
11
    private $vocabs;
12
    private $rest;
13
    private $hidden;
14
    private $unique;
15
16
    public function __construct($request, $config, $rest = false) 
17
    {
18
        $this->request = $request;
19
        $this->config = $config;
20
        $this->rest = $rest;
21
        $this->hidden = true;
22
        $this->unique = $request->getQueryParamBoolean('unique', false);
23
    }
24
25
    public function getLang() 
26
    {
27
        if ($this->rest && $this->request->getQueryParam('labellang')) {
28
            return $this->request->getQueryParam('labellang');
29
        }
30
        return $this->request->getLang();
31
    } 
32
33
    public function getVocabs() 
34
    {
35
        if ($this->vocabs) {
36
            return $this->vocabs;
37
        }
38
        if ($this->request->getVocab()) {
39
            return array($this->request->getVocab());
40
        }
41
        return array();
42
    } 
43
44
    public function getVocabIds()
45
    {
46 View Code Duplication
        if ($this->rest) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
            $vocabs = $this->request->getQueryParam('vocab');
48
            return ($vocabs !== null && $vocabs !== '') ? explode(' ', $vocabs) : null;
49
        }
50 View Code Duplication
        if ($this->request->getQueryParam('vocabs')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
            $vocabs = $this->request->getQueryParam('vocabs'); 
52
            return ($vocabs !== null && $vocabs !== '') ? explode(' ', $vocabs) : null;
53
        }
54
        $vocabs = $this->getVocabs();
55
        if ($vocabs[0]) {
56
            return array($vocabs[0]->getId());
57
        }
58
        return null;
59
    }
60
61
    public function setVocabularies($vocabs) 
62
    {
63
        $this->vocabs = $vocabs;
64
    }
65
    
66
    public function getArrayClass() 
67
    {
68
        if (sizeof($this->getVocabs()) == 1) { // search within vocabulary
69
            $vocabs = $this->getVocabs();
70
            return $vocabs[0]->getConfig()->getArrayClassURI();
71
        }
72
        return null;
73
    }
74
    
75
    public function getSearchTerm() 
76
    {
77
        $term = $this->request->getQueryParam('q') ? $this->request->getQueryParam('q') : $this->request->getQueryParam('query');
78
        if (!$term && $this->rest)
79
            $term = $this->request->getQueryParam('label');
80
        $term = trim($term); // surrounding whitespace is not considered significant
81
        if ($this->rest) {
82
            return $term;
83
        }
84
        return strpos($term, "*") === false ? $term . "*" : $term; // default to prefix search
85
    }
86
    
87
    public function getContentLang() 
88
    {
89
        return $this->request->getContentLang();
90
    }
91
    
92
    public function getSearchLang() 
93
    {
94
        if ($this->rest) {
95
            return $this->request->getQueryParam('lang');
96
        }
97
        return $this->request->getQueryParam('anylang') ? '' : $this->getContentLang();
98
    }
99
100
    public function getTypeLimit() 
101
    {
102
        $type = $this->request->getQueryParam('type') !== '' ? $this->request->getQueryParam('type') : null;
103
        if ($type && strpos($type, '+')) {
104
            $type = explode('+', $type);
105
        } else if ($type && !is_array($type)) {
106
            // if only one type param given place it into an array regardless
107
            $type = array($type);
108
        }
109
        if ($type === null) {
110
            $type = array('skos:Concept');
111 View Code Duplication
            if ($this->request->getVocab() && $this->request->getVocab()->getConfig()->getArrayClassURI()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
                array_push($type, $this->request->getVocab()->getConfig()->getArrayClassURI());
113
            }
114 View Code Duplication
            if ($this->request->getVocab() && $this->request->getVocab()->getConfig()->getGroupClassURI()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
                array_push($type, $this->request->getVocab()->getConfig()->getGroupClassURI());
116
            }
117
        }
118
        return $type;
119
    }
120
121
    public function getGroupLimit() 
122
    {
123
        return $this->request->getQueryParam('group') !== '' ? $this->request->getQueryParam('group') : null;
124
    }
125
    
126
    public function getParentLimit() 
127
    {
128
        return $this->request->getQueryParam('parent') !== '' ? $this->request->getQueryParam('parent') : null;
129
    }
130
    
131
    public function getSchemeLimit() 
132
    {
133
        return $this->request->getQueryParam('scheme') ? explode(' ', $this->request->getQueryParam('scheme')) : null;
134
    }
135
136
    public function getOffset() 
137
    {
138
        return ($this->request->getQueryParam('offset') && is_numeric($this->request->getQueryParam('offset')) && $this->request->getQueryParam('offset') >= 0) ? $this->request->getQueryParam('offset') : 0;
139
    }
140
141
    public function getSearchLimit()
142
    {
143
        return $this->config->getDefaultSearchLimit();
144
    }
145
146
    public function getUnique() {
147
        return $this->unique;
148
    }
149
150
    public function setUnique($unique) {
151
        $this->unique = $unique;
152
    }
153
154
    public function getAdditionalFields() {
155
        return $this->request->getQueryParam('fields') ? explode(' ', $this->request->getQueryParam('fields')) : null;
156
    }
157
    
158
    public function getHidden() {
159
        return $this->hidden;
160
    }
161
    
162
    public function setHidden($hidden) {
163
        $this->hidden = $hidden;
164
    }
165
    
166
}
167