-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathRowCellUsergroupMapper.php
More file actions
64 lines (53 loc) · 1.98 KB
/
Copy pathRowCellUsergroupMapper.php
File metadata and controls
64 lines (53 loc) · 1.98 KB
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
<?php
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Tables\Db;
use OCA\Tables\Constants\UsergroupType;
use OCA\Tables\Helper\CircleHelper;
use OCA\Tables\Helper\GroupHelper;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\IUserSession;
/** @template-extends RowCellMapperSuper<RowCellUsergroup, array, array> */
class RowCellUsergroupMapper extends RowCellMapperSuper {
use RowCellBulkFetchTrait;
protected string $table = 'tables_row_cells_usergroup';
public function __construct(
IDBConnection $db,
private IUserManager $userManager,
private CircleHelper $circleHelper,
private GroupHelper $groupHelper,
protected IUserSession $userSession,
) {
parent::__construct($db, $this->table, RowCellUsergroup::class);
}
public function filterValueToQueryParam(Column $column, mixed $value): mixed {
return $value;
}
public function applyDataToEntity(Column $column, RowCellSuper $cell, $data): void {
if (!RowCellUsergroup::verifyUserGroupArray($data)) {
throw new \InvalidArgumentException('Provided value is not valid user group data');
}
$cell->setValueWrapper($data);
}
public function formatEntity(Column $column, RowCellSuper $cell) {
$displayName = $cell->getValue();
if ($cell->getValueType() === UsergroupType::USER) {
$displayName = $this->userManager->getDisplayName($cell->getValue()) ?? $cell->getValue();
} elseif ($cell->getValueType() === UsergroupType::CIRCLE) {
$displayName = $this->circleHelper->getCircleDisplayName($cell->getValue(), ($this->userSession->getUser()?->getUID() ?: '')) ?: $cell->getValue();
} elseif ($cell->getValueType() === UsergroupType::GROUP) {
$displayName = $this->groupHelper->getGroupDisplayName($cell->getValue()) ?: $cell->getValue();
}
return [
'id' => $cell->getValue(),
'type' => $cell->getValueType(),
'displayName' => $displayName,
];
}
public function hasMultipleValues(): bool {
return true;
}
}