|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Circles - Bring cloud-users closer together. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Maxence Lange <[email protected]> |
|
9
|
|
|
* @copyright 2017 |
|
10
|
|
|
* @license GNU AGPL version 3 or any later version |
|
11
|
|
|
* |
|
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
15
|
|
|
* License, or (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace OCA\Circles\Model; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
class SearchResult implements \JsonSerializable { |
|
31
|
|
|
|
|
32
|
|
|
/** @var string */ |
|
33
|
|
|
private $ident; |
|
34
|
|
|
|
|
35
|
|
|
/** @var int */ |
|
36
|
|
|
private $type; |
|
37
|
|
|
|
|
38
|
|
|
/** @var string */ |
|
39
|
|
|
private $instance = ''; |
|
40
|
|
|
|
|
41
|
|
|
/** @var array */ |
|
42
|
|
|
private $data = []; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* SearchResult constructor. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $ident |
|
49
|
|
|
* @param int $type |
|
50
|
|
|
* @param array $data |
|
51
|
|
|
*/ |
|
52
|
|
|
function __construct($ident = '', $type = 0, $instance = '', $data = []) { |
|
|
|
|
|
|
53
|
|
|
$this->setIdent($ident); |
|
54
|
|
|
$this->setType($type); |
|
55
|
|
|
$this->setInstance($instance); |
|
56
|
|
|
$this->setData($data); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param string $ident |
|
62
|
|
|
*/ |
|
63
|
|
|
public function setIdent($ident) { |
|
64
|
|
|
$this->ident = $ident; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getIdent() { |
|
71
|
|
|
return $this->ident; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param string $instance |
|
77
|
|
|
*/ |
|
78
|
|
|
public function setInstance($instance) { |
|
79
|
|
|
$this->instance = $instance; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getInstance() { |
|
86
|
|
|
return $this->instance; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param int $type |
|
92
|
|
|
*/ |
|
93
|
|
|
public function setType($type) { |
|
94
|
|
|
$this->type = $type; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return int |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getType() { |
|
101
|
|
|
return $this->type; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param array $data |
|
107
|
|
|
*/ |
|
108
|
|
|
public function setData($data) { |
|
109
|
|
|
$this->data = $data; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return array |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getData() { |
|
116
|
|
|
if (!key_exists('display', $this->data)) { |
|
117
|
|
|
return ['display' => $this->getIdent()]; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $this->data; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Specify data which should be serialized to JSON |
|
126
|
|
|
* |
|
127
|
|
|
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
|
128
|
|
|
* @return mixed data which can be serialized by <b>json_encode</b>, |
|
|
|
|
|
|
129
|
|
|
* which is a value of any type other than a resource. |
|
130
|
|
|
* @since 5.4.0 |
|
131
|
|
|
*/ |
|
132
|
|
|
function jsonSerialize() { |
|
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
return [ |
|
135
|
|
|
'ident' => $this->getIdent(), |
|
136
|
|
|
'instance' => $this->getInstance(), |
|
137
|
|
|
'type' => $this->getType(), |
|
138
|
|
|
'data' => $this->getData() |
|
139
|
|
|
]; |
|
140
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.