1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\SearchModule\Entity; |
15
|
|
|
|
16
|
|
|
use DateTime; |
17
|
|
|
use DateTimeZone; |
18
|
|
|
use Doctrine\ORM\Mapping as ORM; |
19
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
20
|
|
|
use Zikula\Bundle\CoreBundle\UrlInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* SearchResult |
24
|
|
|
* |
25
|
|
|
* @ORM\Entity(repositoryClass="Zikula\SearchModule\Entity\Repository\SearchResultRepository") |
26
|
|
|
* @ORM\Table(name="search_result") |
27
|
|
|
*/ |
28
|
|
|
class SearchResultEntity |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* ID of the search |
32
|
|
|
* |
33
|
|
|
* @ORM\Column(name="id", type="integer", nullable=false) |
34
|
|
|
* @ORM\Id |
35
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
36
|
|
|
* @var int |
37
|
|
|
*/ |
38
|
|
|
private $id; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* title of the search |
42
|
|
|
* |
43
|
|
|
* @ORM\Column(name="title", type="string", length=255, nullable=false) |
44
|
|
|
* @Assert\Length(min="1", max="255") |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $title; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* the matching search text |
51
|
|
|
* |
52
|
|
|
* @ORM\Column(name="text", type="text", nullable=true) |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
private $text; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* the module providing the search hit |
59
|
|
|
* |
60
|
|
|
* @ORM\Column(name="module", type="string", length=100, nullable=true) |
61
|
|
|
* @Assert\AtLeastOneOf( |
62
|
|
|
* @Assert\Blank(), |
63
|
|
|
* @Assert\Length(min="1", max="100") |
64
|
|
|
* ) |
65
|
|
|
* @var string |
66
|
|
|
*/ |
67
|
|
|
private $module; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* additional information about this search result |
71
|
|
|
* |
72
|
|
|
* @ORM\Column(name="extra", type="array") |
73
|
|
|
* @var array |
74
|
|
|
*/ |
75
|
|
|
private $extra = []; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* creation timestamp of this search hit |
79
|
|
|
* |
80
|
|
|
* @ORM\Column(name="created", type="datetime", nullable=true) |
81
|
|
|
* @var DateTime |
82
|
|
|
*/ |
83
|
|
|
private $created; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Last found timestamp of this search hit |
87
|
|
|
* |
88
|
|
|
* @ORM\Column(name="found", type="datetime", nullable=true) |
89
|
|
|
* @var DateTime |
90
|
|
|
*/ |
91
|
|
|
private $found; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Session id associated |
95
|
|
|
* |
96
|
|
|
* @ORM\Column(name="sesid", type="string", length=50, nullable=true) |
97
|
|
|
* @Assert\AtLeastOneOf( |
98
|
|
|
* @Assert\Blank(), |
99
|
|
|
* @Assert\Length(min="1", max="50") |
100
|
|
|
* ) |
101
|
|
|
* @var string |
102
|
|
|
*/ |
103
|
|
|
private $sesid; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Url for found item |
107
|
|
|
* |
108
|
|
|
* @ORM\Column(type="object", nullable=true) |
109
|
|
|
* @var UrlInterface |
110
|
|
|
*/ |
111
|
|
|
private $url; |
112
|
|
|
|
113
|
|
|
public function getId(): ?int |
114
|
|
|
{ |
115
|
|
|
return $this->id; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function setId(int $id): self |
119
|
|
|
{ |
120
|
|
|
$this->id = $id; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getTitle(): string |
126
|
|
|
{ |
127
|
|
|
return $this->title; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function setTitle(string $title): self |
131
|
|
|
{ |
132
|
|
|
$this->title = $title; |
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getText(): ?string |
138
|
|
|
{ |
139
|
|
|
return $this->text; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function setText(string $text): self |
143
|
|
|
{ |
144
|
|
|
$this->text = $text; |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function getModule(): string |
150
|
|
|
{ |
151
|
|
|
return $this->module; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function setModule(string $module): self |
155
|
|
|
{ |
156
|
|
|
$this->module = $module; |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function getExtra(): array |
162
|
|
|
{ |
163
|
|
|
return $this->extra; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param string|array $extra |
168
|
|
|
*/ |
169
|
|
|
public function setExtra($extra): self |
170
|
|
|
{ |
171
|
|
|
if (!is_array($extra)) { |
172
|
|
|
$this->extra = [$extra]; |
173
|
|
|
} else { |
174
|
|
|
$this->extra = $extra; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function getCreated(): DateTime |
181
|
|
|
{ |
182
|
|
|
return $this->created; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function setCreated(DateTime $created): self |
186
|
|
|
{ |
187
|
|
|
$this->created = $created; |
188
|
|
|
|
189
|
|
|
return $this; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function getFound(): DateTime |
193
|
|
|
{ |
194
|
|
|
return $this->found; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function setFound(DateTime $found): self |
198
|
|
|
{ |
199
|
|
|
$this->found = $found; |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function getSesid(): string |
205
|
|
|
{ |
206
|
|
|
return $this->sesid; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function setSesid(string $sesid): self |
210
|
|
|
{ |
211
|
|
|
$this->sesid = $sesid; |
212
|
|
|
|
213
|
|
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function getUrl(): ?UrlInterface |
217
|
|
|
{ |
218
|
|
|
return $this->url; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function setUrl(UrlInterface $url): self |
222
|
|
|
{ |
223
|
|
|
$this->url = $url; |
224
|
|
|
|
225
|
|
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function merge(array $result = []): void |
229
|
|
|
{ |
230
|
|
|
$this->title = $result['title'] ?? 'unknown'; |
231
|
|
|
$this->text = $result['text'] ?? null; |
232
|
|
|
$this->extra = $result['extra'] ?? null; |
233
|
|
|
$this->module = $result['module'] ?? null; |
234
|
|
|
$this->created = isset($result['created']) && $result['created'] instanceof DateTime ? $result['created'] : new DateTime('now', new DateTimeZone('UTC')); |
235
|
|
|
$this->sesid = $result['sesid'] ?? null; |
236
|
|
|
$this->url = isset($result['url']) && $result['url'] instanceof UrlInterface ? $result['url'] : null; |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|