1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2017, 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
|
|
|
* Image represent one image file for one user. |
32
|
|
|
* |
33
|
|
|
* @method string getUser() |
34
|
|
|
* @method void setUser(string $user) |
35
|
|
|
* |
36
|
|
|
* @method integer getFile() |
37
|
|
|
* @method void setFile(integer $file) |
38
|
|
|
* |
39
|
|
|
* @method integer getModel() |
40
|
|
|
* @method void setModel(integer $model) |
41
|
|
|
* |
42
|
|
|
* @method void setError(string $error) |
43
|
|
|
* |
44
|
|
|
* @method void setLastProcessedTime($lastProcessedTime) |
45
|
|
|
* |
46
|
|
|
* @method void setProcessingDuration(int $processingDuration) |
47
|
|
|
* |
48
|
|
|
*/ |
49
|
|
|
class Image extends Entity implements JsonSerializable { |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* User this image belongs to. |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
* */ |
56
|
|
|
public $user; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* File that this image refer to. |
60
|
|
|
* todo: add proper getters in whole class |
61
|
|
|
* |
62
|
|
|
* @var integer |
63
|
|
|
*/ |
64
|
|
|
public $file; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Face model that processed this image. |
68
|
|
|
* |
69
|
|
|
* @var integer |
70
|
|
|
*/ |
71
|
|
|
protected $model; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Whether this image is processed or not. Needed because image doesn't have to have any faces on it, |
75
|
|
|
* yet we still need to know if it is being processed or not. |
76
|
|
|
* |
77
|
|
|
* @var bool |
78
|
|
|
*/ |
79
|
|
|
protected $isProcessed; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Description of error that happened during image processing. |
83
|
|
|
* If it exist, image processing should be skipped even if $is_processed is false. |
84
|
|
|
* |
85
|
|
|
* @var string|null |
86
|
|
|
*/ |
87
|
|
|
protected $error; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Timestamp when this image was last processed. |
91
|
|
|
* |
92
|
|
|
* @var \DateTime|null |
93
|
|
|
*/ |
94
|
|
|
protected $lastProcessedTime; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Duration (in ms) it took to completely process this image. Should serve as a way to give estimates to user. |
98
|
|
|
* |
99
|
|
|
* @var integer|null |
100
|
|
|
*/ |
101
|
|
|
protected $processingDuration; |
102
|
|
|
|
103
|
|
|
public function __construct() { |
104
|
|
|
$this->addType('isProcessed', 'bool'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function jsonSerialize() { |
108
|
|
|
return [ |
109
|
|
|
'id' => $this->id, |
110
|
|
|
'user' => $this->user, |
111
|
|
|
'file' => $this->file, |
112
|
|
|
'model' => $this->model, |
113
|
|
|
'is_processed' => $this->isProcessed, |
114
|
|
|
'error' => $this->error, |
115
|
|
|
'last_processed_time' => $this->lastProcessedTime, |
116
|
4 |
|
'processing_duration' => $this->processingDuration |
117
|
4 |
|
]; |
118
|
|
|
} |
119
|
|
|
|
120
|
4 |
|
public function setIsProcessed($isProcessed) { |
121
|
|
|
if (is_bool($isProcessed)) { |
122
|
4 |
|
$this->isProcessed = $isProcessed; |
123
|
4 |
|
} else { |
124
|
|
|
$this->isProcessed = filter_var($isProcessed, FILTER_VALIDATE_BOOLEAN); |
125
|
|
|
} |
126
|
|
|
$this->markFieldUpdated('isProcessed'); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|