1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Model;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/**
* @method Ban mapRowToEntity(array $row)
* @method Ban findEntity(IQueryBuilder $query)
* @method Ban[] findEntities(IQueryBuilder $query)
* @template-extends QBMapper<Ban>
*/
class BanMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'talk_bans', Ban::class);
}
/**
* @throws DoesNotExistException
*/
public function findForBannedActorAndRoom(string $bannedActorType, string $bannedActorId, int $roomId): Ban {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
->where($query->expr()->eq('banned_actor_type', $query->createNamedParameter($bannedActorType, IQueryBuilder::PARAM_STR)))
->andWhere($query->expr()->eq('banned_actor_id', $query->createNamedParameter($bannedActorId, IQueryBuilder::PARAM_STR)))
->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)));
return $this->findEntity($query);
}
public function findByRoomId(int $roomId): array {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
->where($query->expr()->eq('room_id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)))
->orderBy('id', 'ASC');
return $this->findEntities($query);
}
/**
* @throws DoesNotExistException
*/
public function findByBanIdAndRoom(int $banId, int $roomId): Ban {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
->where($query->expr()->eq('id', $query->createNamedParameter($banId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)));
return $this->findEntity($query);
}
public function updateDisplayNameForActor(string $actorType, string $actorId, string $displayName): void {
$update = $this->db->getQueryBuilder();
$update->update($this->getTableName())
->set('moderator_displayname', $update->createNamedParameter($displayName))
->where($update->expr()->eq('moderator_actor_type', $update->createNamedParameter($actorType)))
->andWhere($update->expr()->eq('moderator_actor_id', $update->createNamedParameter($actorId)));
$update->executeStatement();
$update = $this->db->getQueryBuilder();
$update->update($this->getTableName())
->set('banned_displayname', $update->createNamedParameter($displayName))
->where($update->expr()->eq('banned_actor_type', $update->createNamedParameter($actorType)))
->andWhere($update->expr()->eq('banned_actor_id', $update->createNamedParameter($actorId)));
$update->executeStatement();
}
}
|