1
|
|
|
<?php |
2
|
|
|
namespace OCA\FaceRecognition\Controller; |
3
|
|
|
|
4
|
|
|
use OCP\IRequest; |
5
|
|
|
use OCP\IConfig; |
6
|
|
|
use OCP\Files\IRootFolder; |
7
|
|
|
use OCP\AppFramework\Http; |
8
|
|
|
use OCP\AppFramework\Http\DataResponse; |
9
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
10
|
|
|
use OCP\AppFramework\Http\DataDisplayResponse; |
11
|
|
|
use OCP\AppFramework\Controller; |
12
|
|
|
|
13
|
|
|
use OCA\FaceRecognition\Db\Face; |
14
|
|
|
use OCA\FaceRecognition\Db\FaceMapper; |
15
|
|
|
|
16
|
|
|
use OCA\FaceRecognition\Db\FaceNew; |
17
|
|
|
use OCA\FaceRecognition\Db\FaceNewMapper; |
18
|
|
|
|
19
|
|
|
use OCA\FaceRecognition\Db\Image; |
20
|
|
|
use OCA\FaceRecognition\Db\ImageMapper; |
21
|
|
|
|
22
|
|
|
use OCA\FaceRecognition\Db\Person; |
23
|
|
|
use OCA\FaceRecognition\Db\PersonMapper; |
24
|
|
|
|
25
|
|
|
use OCA\FaceRecognition\Migration\AddDefaultFaceModel; |
26
|
|
|
|
27
|
|
|
class PersonController extends Controller { |
28
|
|
|
|
29
|
|
|
private $config; |
30
|
|
|
private $rootFolder; |
31
|
|
|
private $faceMapper; |
32
|
|
|
private $faceNewMapper; |
33
|
|
|
private $imageMapper; |
34
|
|
|
private $personMapper; |
35
|
|
|
private $userId; |
36
|
|
|
|
37
|
|
|
public function __construct($AppName, IRequest $request, IConfig $config, |
38
|
|
|
IRootFolder $rootFolder, |
39
|
|
|
FaceMapper $facemapper, |
40
|
|
|
FaceNewMapper $faceNewMapper, |
41
|
|
|
ImageMapper $imageMapper, |
42
|
|
|
PersonMapper $personmapper, |
43
|
|
|
$UserId) |
44
|
|
|
{ |
45
|
|
|
parent::__construct($AppName, $request); |
46
|
|
|
$this->config = $config; |
47
|
|
|
$this->rootFolder = $rootFolder; |
48
|
|
|
$this->faceMapper = $facemapper; |
49
|
|
|
$this->imageMapper = $imageMapper; |
50
|
|
|
$this->faceNewMapper = $faceNewMapper; |
51
|
|
|
$this->personMapper = $personmapper; |
52
|
|
|
$this->userId = $UserId; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @NoAdminRequired |
57
|
|
|
*/ |
58
|
|
|
public function index() { |
59
|
|
|
$model = intval($this->config->getAppValue('facerecognition', 'model', AddDefaultFaceModel::DEFAULT_FACE_MODEL_ID)); |
60
|
|
|
|
61
|
|
|
$resp = array(); |
62
|
|
|
$persons = $this->personMapper->findAll($this->userId); |
63
|
|
|
foreach ($persons as $person) { |
64
|
|
|
$cluster = []; |
65
|
|
|
$faces = []; |
66
|
|
|
$personFaces = $this->faceNewMapper->findFacesFromPerson($this->userId, $person->getId(), $model); |
67
|
|
|
foreach ($personFaces as $personFace) { |
68
|
|
|
$image = $this->imageMapper->find($this->userId, $personFace->getImage()); |
69
|
|
|
$face = []; |
70
|
|
|
$face['id'] = $personFace->getId(); |
71
|
|
|
$face['file-id'] = $image->getFile(); |
72
|
|
|
$faces[] = $face; |
73
|
|
|
} |
74
|
|
|
$cluster['name'] = $person->getName(); |
75
|
|
|
$cluster['id'] = $person->getId(); |
76
|
|
|
$cluster['faces'] = $faces; |
77
|
|
|
$resp[] = $cluster; |
78
|
|
|
} |
79
|
|
|
return new DataResponse($resp); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @NoAdminRequired |
84
|
|
|
* |
85
|
|
|
* @param int $id |
86
|
|
|
* @param string $name |
87
|
|
|
*/ |
88
|
|
|
public function updateName($id, $name) { |
89
|
|
|
$person = $this->personMapper->find ($this->userId, $id); |
90
|
|
|
$person->setName($name); |
91
|
|
|
$this->personMapper->update($person); |
92
|
|
|
$newPerson = $this->personMapper->find($this->userId, $id); |
93
|
|
|
return new DataResponse($newPerson); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|