|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2020-2021, Matias De lellis <[email protected]> |
|
4
|
|
|
* @copyright Copyright (c) 2018, Branko Kokanovic <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @author Branko Kokanovic <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU AGPL version 3 or any later version |
|
9
|
|
|
* |
|
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
13
|
|
|
* License, or (at your option) any later version. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
namespace OCA\FaceRecognition\Db; |
|
25
|
|
|
|
|
26
|
|
|
use JsonSerializable; |
|
27
|
|
|
|
|
28
|
|
|
use OCP\AppFramework\Db\Entity; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Person represent one cluster, set of faces. It belongs to $user_id. |
|
32
|
|
|
* |
|
33
|
|
|
* @method string getUser() |
|
34
|
|
|
* @method string getName() |
|
35
|
|
|
* @method void setName(string $name) |
|
36
|
|
|
* @method bool getIsVisible() |
|
37
|
|
|
*/ |
|
38
|
|
|
class Person extends Entity implements JsonSerializable { |
|
39
|
|
|
/** |
|
40
|
|
|
* User this person belongs to |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
* */ |
|
44
|
|
|
protected $user; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Name for this person/cluster. Must exists, even if linked user is set. |
|
48
|
|
|
* |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $name; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Whether this person is visible/relevant to user. |
|
55
|
|
|
* |
|
56
|
|
|
* @var bool |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $isVisible; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Whether this person is still valid |
|
62
|
|
|
* |
|
63
|
|
|
* @var bool |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $isValid; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Last timestamp when this person/cluster was created, or when it was refreshed |
|
69
|
|
|
* |
|
70
|
|
|
* @var \DateTime|null |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $lastGenerationTime; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Foreign key to other user that this person belongs to (if it is on same Nextcloud instance). |
|
76
|
|
|
* It is set by owner of this cluster. It is optional. |
|
77
|
|
|
* |
|
78
|
|
|
* @var string|null |
|
79
|
|
|
*/ |
|
80
|
|
|
protected $linkedUser; |
|
81
|
|
|
|
|
82
|
14 |
|
public function __construct() { |
|
83
|
14 |
|
$this->addType('id', 'integer'); |
|
84
|
14 |
|
$this->addType('user', 'string'); |
|
85
|
14 |
|
$this->addType('isVisible', 'bool'); |
|
86
|
14 |
|
$this->addType('isValid', 'bool'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function jsonSerialize() { |
|
90
|
|
|
return [ |
|
91
|
|
|
'id' => $this->id, |
|
92
|
|
|
'user' => $this->user, |
|
93
|
|
|
'name' => $this->name, |
|
94
|
|
|
'is_visible' => $this->isVisible, |
|
95
|
|
|
'is_valid' => $this->isValid, |
|
96
|
|
|
'last_generation_time' => $this->lastGenerationTime, |
|
97
|
|
|
'linked_user' => $this->linkedUser |
|
98
|
|
|
]; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function setIsVisible($isVisible): void { |
|
102
|
|
|
if (is_bool($isVisible)) { |
|
103
|
|
|
$this->isVisible = $isVisible; |
|
104
|
|
|
} else { |
|
105
|
|
|
$this->isVisible = filter_var($isVisible, FILTER_VALIDATE_BOOLEAN); |
|
106
|
|
|
} |
|
107
|
|
|
$this->markFieldUpdated('isVisible'); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
12 |
|
public function setIsValid($isValid): void { |
|
111
|
12 |
|
if (is_bool($isValid)) { |
|
112
|
12 |
|
$this->isValid = $isValid; |
|
113
|
|
|
} else { |
|
114
|
|
|
$this->isValid = filter_var($isValid, FILTER_VALIDATE_BOOLEAN); |
|
115
|
|
|
} |
|
116
|
12 |
|
$this->markFieldUpdated('isValid'); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|