|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ConceptSearchParameters is used for search parameters. |
|
5
|
|
|
*/ |
|
6
|
|
|
class ConceptSearchParameters |
|
|
|
|
|
|
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
|
|
|
return array($this->request->getVocab()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getVocabIds() |
|
42
|
|
|
{ |
|
43
|
|
View Code Duplication |
if ($this->rest) { |
|
|
|
|
|
|
44
|
|
|
$vocabs = $this->request->getQueryParam('vocab'); |
|
45
|
|
|
return ($vocabs !== null && $vocabs !== '') ? explode(' ', $vocabs) : null; |
|
46
|
|
|
} |
|
47
|
|
View Code Duplication |
if ($this->request->getQueryParam('vocabs')) { |
|
|
|
|
|
|
48
|
|
|
$vocabs = $this->request->getQueryParam('vocabs'); |
|
49
|
|
|
return ($vocabs !== null && $vocabs !== '') ? explode(' ', $vocabs) : null; |
|
50
|
|
|
} |
|
51
|
|
|
return array(reset($this->getVocabs())->getId()); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function setVocabularies($vocabs) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->vocabs = $vocabs; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getArrayClass() |
|
60
|
|
|
{ |
|
61
|
|
|
if (sizeof($this->getVocabIds()) == 1) { // search within vocabulary |
|
62
|
|
|
return reset($this->getVocabs())->getConfig()->getArrayClassURI(); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
return null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getSearchTerm() |
|
68
|
|
|
{ |
|
69
|
|
|
$term = $this->request->getQueryParam('q') ? $this->request->getQueryParam('q') : $this->request->getQueryParam('query'); |
|
70
|
|
|
if (!$term && $this->rest) |
|
71
|
|
|
$term = $this->request->getQueryParam('label'); |
|
72
|
|
|
$term = trim($term); // surrounding whitespace is not considered significant |
|
73
|
|
|
return strpos($term, "*") === false ? $term . "*" : $term; // default to prefix search |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getContentLang() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->request->getContentLang(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getConceptGroups() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->vocab->listConceptGroups($content_lang); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getSearchLang() |
|
87
|
|
|
{ |
|
88
|
|
|
if ($this->rest) { |
|
89
|
|
|
return $this->request->getQueryParam('lang'); |
|
90
|
|
|
} |
|
91
|
|
|
return $this->request->getQueryParam('anylang') ? '' : $this->getContentLang(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getTypeLimit() |
|
95
|
|
|
{ |
|
96
|
|
|
$type = $this->request->getQueryParam('type') !== '' ? $this->request->getQueryParam('type') : null; |
|
97
|
|
|
if ($type && strpos($type, '+')) { |
|
98
|
|
|
$type = explode('+', $type); |
|
99
|
|
|
} else if ($type && !is_array($type)) { |
|
100
|
|
|
// if only one type param given place it into an array regardless |
|
101
|
|
|
$type = array($type); |
|
102
|
|
|
} |
|
103
|
|
|
if ($type === null) { |
|
104
|
|
|
$type = array('skos:Concept'); |
|
105
|
|
|
} |
|
106
|
|
|
return $type; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getGroupLimit() |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->request->getQueryParam('group') !== '' ? $this->request->getQueryParam('group') : null; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function getParentLimit() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->request->getQueryParam('parent') !== '' ? $this->request->getQueryParam('parent') : null; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function getOffset() |
|
120
|
|
|
{ |
|
121
|
|
|
return ($this->request->getQueryParam('offset') && is_numeric($this->request->getQueryParam('offset')) && $this->request->getQueryParam('offset') >= 0) ? $this->request->getQueryParam('offset') : 0; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getSearchLimit() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->config->getDefaultSearchLimit(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function getUnique() { |
|
130
|
|
|
return $this->unique; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function setUnique($unique) { |
|
134
|
|
|
$this->unique = $unique; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function getAdditionalFields() { |
|
138
|
|
|
return $this->request->getQueryParam('fields') ? explode(' ', $request->getQueryParam('fields')) : null; |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function getHidden() { |
|
142
|
|
|
return $this->hidden; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function setHidden($hidden) { |
|
146
|
|
|
$this->hidden = $hidden; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function setAdditionalFields($fields) { |
|
150
|
|
|
$this->fields = $fields; |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
} |
|
154
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.