Skip to content

Commit 4e3e6ab

Browse files
committed
update services and mappers to be able to find and insert tables
1 parent 40e42ad commit 4e3e6ab

17 files changed

+432
-3
lines changed

lib/Db/ColumnMapper.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,22 @@ public function preloadColumns(array $columns, ?array $filters = null, ?array $s
208208
private function getCacheKey(int $id): string {
209209
return 'column_' . $id;
210210
}
211+
212+
/**
213+
* @param int[] $tableIds
214+
*
215+
* @return Column[]
216+
*/
217+
public function findAllByTableIds(array $tableIds): array {
218+
if (empty($tableIds)) {
219+
return [];
220+
}
221+
222+
$qb = $this->db->getQueryBuilder();
223+
$qb->select('*')
224+
->from($this->table)
225+
->where($qb->expr()->in('table_id', $qb->createNamedParameter($tableIds, IQueryBuilder::PARAM_INT_ARRAY)));
226+
227+
return $this->findEntities($qb);
228+
}
211229
}

lib/Db/RowCellBulkFetchTrait.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace OCA\Tables\Db;
9+
10+
use OCP\DB\QueryBuilder\IQueryBuilder;
11+
12+
trait RowCellBulkFetchTrait {
13+
/**
14+
* @param int[] $rowIds
15+
* @param int[] $columnIds
16+
*
17+
* @return array
18+
*/
19+
public function findAllByRowIdsAndColumnIds(array $rowIds, array $columnIds): array {
20+
if (empty($rowIds) || empty($columnIds)) {
21+
return [];
22+
}
23+
$qb = $this->db->getQueryBuilder();
24+
$qb->select('*')
25+
->from($this->table)
26+
->where($qb->expr()->in('row_id', $qb->createNamedParameter($rowIds, IQueryBuilder::PARAM_INT_ARRAY)))
27+
->andWhere($qb->expr()->in('column_id', $qb->createNamedParameter($columnIds, IQueryBuilder::PARAM_INT_ARRAY)));
28+
29+
return $this->findEntities($qb);
30+
}
31+
}

lib/Db/RowCellDatetimeMapper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
namespace OCA\Tables\Db;
99

1010
use OCP\IDBConnection;
11+
use OCA\Tables\Db\RowCellBulkFetchTrait;
1112

1213
/** @template-extends RowCellMapperSuper<RowCellDatetime, string, string> */
1314
class RowCellDatetimeMapper extends RowCellMapperSuper {
15+
use RowCellBulkFetchTrait;
16+
1417
protected string $table = 'tables_row_cells_datetime';
1518

1619
public function __construct(IDBConnection $db) {

lib/Db/RowCellNumberMapper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
use OCP\DB\QueryBuilder\IQueryBuilder;
1111
use OCP\IDBConnection;
12+
use OCA\Tables\Db\RowCellBulkFetchTrait;
1213

1314
/** @template-extends RowCellMapperSuper<RowCellNumber, int|float|null, int|float|null> */
1415
class RowCellNumberMapper extends RowCellMapperSuper {
16+
use RowCellBulkFetchTrait;
17+
1518
protected string $table = 'tables_row_cells_number';
1619

1720
public function __construct(IDBConnection $db) {

lib/Db/RowCellSelectionMapper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
namespace OCA\Tables\Db;
99

1010
use OCP\IDBConnection;
11+
use OCA\Tables\Db\RowCellBulkFetchTrait;
1112

1213
/**
1314
* @template-extends RowCellMapperSuper<RowCellSelection, string, string|array>
1415
*/
1516
class RowCellSelectionMapper extends RowCellMapperSuper {
17+
use RowCellBulkFetchTrait;
18+
1619
protected string $table = 'tables_row_cells_selection';
1720

1821
public function __construct(IDBConnection $db) {

lib/Db/RowCellTextMapper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
namespace OCA\Tables\Db;
99

1010
use OCP\IDBConnection;
11+
use OCA\Tables\Db\RowCellBulkFetchTrait;
1112

1213
/** @template-extends RowCellMapperSuper<RowCellText, string, string> */
1314
class RowCellTextMapper extends RowCellMapperSuper {
15+
use RowCellBulkFetchTrait;
16+
1417
protected string $table = 'tables_row_cells_text';
1518

1619
public function __construct(IDBConnection $db) {

lib/Db/RowCellUsergroupMapper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
use OCA\Tables\Constants\UsergroupType;
1111
use OCA\Tables\Helper\CircleHelper;
1212
use OCA\Tables\Helper\GroupHelper;
13+
use OCA\Tables\Db\RowCellBulkFetchTrait;
1314
use OCP\IDBConnection;
1415
use OCP\IUserManager;
1516
use OCP\IUserSession;
1617

1718
/** @template-extends RowCellMapperSuper<RowCellUsergroup, array, array> */
1819
class RowCellUsergroupMapper extends RowCellMapperSuper {
20+
use RowCellBulkFetchTrait;
21+
1922
protected string $table = 'tables_row_cells_usergroup';
2023

2124
public function __construct(

lib/Db/RowSleeveMapper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,20 @@ public function countRows(int $tableId): int {
122122
return 0;
123123
}
124124
}
125+
126+
/**
127+
* @param int[] $tableIds
128+
*
129+
* @return RowSleeve[]
130+
*/
131+
public function findAllByTableIds(array $tableIds): array {
132+
if (empty($tableIds)) {
133+
return [];
134+
}
135+
$qb = $this->db->getQueryBuilder();
136+
$qb->select('*')
137+
->from($this->table)
138+
->where($qb->expr()->in('table_id', $qb->createNamedParameter($tableIds, IQueryBuilder::PARAM_INT_ARRAY)));
139+
return $this->findEntities($qb);
140+
}
125141
}

lib/Db/ShareMapper.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,37 @@ public function deleteByNode(int $nodeId, string $nodeType):void {
199199
->andWhere($qb->expr()->eq('node_type', $qb->createNamedParameter($nodeType, IQueryBuilder::PARAM_STR)))
200200
->executeStatement();
201201
}
202+
203+
/**
204+
* @param int[] $tableIds
205+
* @param int[] $contextIds
206+
*
207+
* @return Share[]
208+
*/
209+
// add better function name
210+
public function findByNodeIdsAndTypes(array $tableIds, array $contextIds): array {
211+
$qb = $this->db->getQueryBuilder();
212+
$qb->select('*')
213+
->from($this->table);
214+
215+
$orX = $qb->expr()->orX();
216+
if (!empty($tableIds)) {
217+
$orX->add(
218+
$qb->expr()->andX(
219+
$qb->expr()->eq('node_type', $qb->createNamedParameter('table', IQueryBuilder::PARAM_STR)),
220+
$qb->expr()->in('node_id', $qb->createNamedParameter($tableIds, IQueryBuilder::PARAM_INT_ARRAY))
221+
)
222+
);
223+
}
224+
if (!empty($contextIds)) {
225+
$orX->add(
226+
$qb->expr()->andX(
227+
$qb->expr()->eq('node_type', $qb->createNamedParameter('context', IQueryBuilder::PARAM_STR)),
228+
$qb->expr()->in('node_id', $qb->createNamedParameter($contextIds, IQueryBuilder::PARAM_INT_ARRAY))
229+
)
230+
);
231+
}
232+
$qb->where($orX);
233+
return $this->findEntities($qb);
234+
}
202235
}

lib/Db/TableMapper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,8 @@ public function insert(Entity $entity): Table {
137137
$this->cache[(string)$entity->getId()] = $entity;
138138
return $entity;
139139
}
140+
141+
public function getDbConnection() {
142+
return $this->db;
143+
}
140144
}

0 commit comments

Comments
 (0)