1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
/** |
5
|
|
|
* @copyright Copyright (c) 2021 Joas Schilling <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OC\KnownUser; |
25
|
|
|
|
26
|
|
|
use OCP\AppFramework\Db\QBMapper; |
27
|
|
|
use OCP\IDBConnection; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @method KnownUser mapRowToEntity(array $row) |
31
|
|
|
*/ |
32
|
|
|
class KnownUserMapper extends QBMapper { |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param IDBConnection $db |
36
|
|
|
*/ |
37
|
|
|
public function __construct(IDBConnection $db) { |
38
|
|
|
parent::__construct($db, 'known_users', KnownUser::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $knownTo |
43
|
|
|
* @return int Number of deleted entities |
44
|
|
|
*/ |
45
|
|
|
public function deleteKnownTo(string $knownTo): int { |
46
|
|
|
$query = $this->db->getQueryBuilder(); |
47
|
|
|
$query->delete($this->getTableName()) |
48
|
|
|
->where($query->expr()->eq('known_to', $query->createNamedParameter($knownTo))); |
49
|
|
|
|
50
|
|
|
return (int) $query->execute(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $knownUser |
55
|
|
|
* @return int Number of deleted entities |
56
|
|
|
*/ |
57
|
|
|
public function deleteKnownUser(string $knownUser): int { |
58
|
|
|
$query = $this->db->getQueryBuilder(); |
59
|
|
|
$query->delete($this->getTableName()) |
60
|
|
|
->where($query->expr()->eq('known_user', $query->createNamedParameter($knownUser))); |
61
|
|
|
|
62
|
|
|
return (int) $query->execute(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns all "known users" for the given "known to" user |
67
|
|
|
* |
68
|
|
|
* @param string $knownTo |
69
|
|
|
* @return KnownUser[] |
70
|
|
|
*/ |
71
|
|
|
public function getKnownUsers(string $knownTo): array { |
72
|
|
|
$query = $this->db->getQueryBuilder(); |
73
|
|
|
$query->select('*') |
74
|
|
|
->from($this->getTableName()) |
75
|
|
|
->where($query->expr()->eq('known_to', $query->createNamedParameter($knownTo))); |
76
|
|
|
|
77
|
|
|
return $this->findEntities($query); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function createKnownUserFromRow(array $row): KnownUser { |
81
|
|
|
return $this->mapRowToEntity([ |
82
|
|
|
'id' => $row['s_id'], |
83
|
|
|
'known_to' => $row['known_to'], |
84
|
|
|
'known_user' => $row['known_user'], |
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|