Skip to content

Commit

Permalink
Second step of cleanup, Format code, linting
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Hempel <Philipp.Hempel1@web.de>
  • Loading branch information
Hephi2 committed Jul 21, 2023
1 parent 3634c6a commit a666b09
Show file tree
Hide file tree
Showing 42 changed files with 227 additions and 255 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/RowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function updateSet(
*/
public function destroy(int $id, int $viewId): DataResponse {
return $this->handleError(function () use ($id, $viewId) {
return $this->service->delete($id, $viewId, $this->userId);
return $this->service->delete($id, $viewId, $this->userId);
});
}
}
1 change: 0 additions & 1 deletion lib/Db/ColumnTypes/DatetimeColumnQB.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace OCA\Tables\Db\ColumnTypes;

use OCA\Tables\Db\View;
use OCP\DB\QueryBuilder\IQueryBuilder;
use Psr\Log\LoggerInterface;

Expand Down
1 change: 0 additions & 1 deletion lib/Db/ColumnTypes/NumberColumnQB.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace OCA\Tables\Db\ColumnTypes;

use OCA\Tables\Db\View;
use OCP\DB\QueryBuilder\IQueryBuilder;
use Psr\Log\LoggerInterface;

Expand Down
2 changes: 0 additions & 2 deletions lib/Db/ColumnTypes/SelectionColumnQB.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace OCA\Tables\Db\ColumnTypes;

use OCA\Tables\Db\View;
use OCP\DB\QueryBuilder\IQueryBuilder;
use Psr\Log\LoggerInterface;

class SelectionColumnQB extends SuperColumnQB implements IColumnTypeQB {
Expand Down
8 changes: 4 additions & 4 deletions lib/Db/ColumnTypes/SuperColumnQB.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public function setPlatform(int $platform) {
public function formatCellValue(string $unformattedValue): string {
return 'JSON_UNQUOTE(LOWER('.$unformattedValue.'))';
}
public function passSearchValue(IQueryBuilder &$qb, string $unformattedSearchValue, string $operator, string $searchValuePlaceHolder): void {
public function passSearchValue(IQueryBuilder &$qb, string $unformattedSearchValue, string $operator, string $searchValuePlaceHolder): void {
$lowerCaseSearchValue = strtolower($unformattedSearchValue);
switch ($operator) {
case 'begins-with':
$lowerCaseSearchValue = $lowerCaseSearchValue . '%';
break;
case 'ends-with':
$lowerCaseSearchValue = '%' . $lowerCaseSearchValue;
$lowerCaseSearchValue = '%' . $lowerCaseSearchValue;
break;
case 'contains':
$lowerCaseSearchValue = '%' . $lowerCaseSearchValue . '%';
$lowerCaseSearchValue = '%' . $lowerCaseSearchValue . '%';
break;
default:
break;
Expand All @@ -45,7 +45,7 @@ public function passSearchValue(IQueryBuilder &$qb, string $unformattedSearchVal
* @return string
* @throws InternalError
*/
private function buildSQLString(string $operator, string $formattedCellValue, string $searchValuePlaceHolder) : string{
private function buildSQLString(string $operator, string $formattedCellValue, string $searchValuePlaceHolder) : string {
if ($this->platform === self::DB_PLATFORM_PGSQL) {
return '';
} elseif ($this->platform === self::DB_PLATFORM_SQLITE) {
Expand Down
2 changes: 0 additions & 2 deletions lib/Db/ColumnTypes/TextColumnQB.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace OCA\Tables\Db\ColumnTypes;

use OCA\Tables\Db\View;
use OCP\DB\QueryBuilder\IQueryBuilder;
use Psr\Log\LoggerInterface;

class TextColumnQB extends SuperColumnQB implements IColumnTypeQB {
Expand Down
17 changes: 8 additions & 9 deletions lib/Db/RowMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use OCA\Tables\Db\ColumnTypes\SuperColumnQB;
use OCA\Tables\Db\ColumnTypes\TextColumnQB;
use OCA\Tables\Helper\UserHelper;
use OCA\Tables\Service\ColumnTypes\TextLineBusiness;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
Expand Down Expand Up @@ -39,7 +38,7 @@ public function __construct(IDBConnection $db, LoggerInterface $logger, TextColu
$this->textColumnQB = $textColumnQB;
$this->numberColumnQB = $numberColumnQB;
$this->selectionColumnQB = $selectionColumnQB;
$this->datetimeColumnQB= $datetimeColumnQB;
$this->datetimeColumnQB = $datetimeColumnQB;
$this->genericColumnQB = $columnQB;
$this->columnMapper = $columnMapper;
$this->userHelper = $userHelper;
Expand Down Expand Up @@ -101,15 +100,15 @@ private function buildFilterByColumnType(&$qb, array $filter, string $filterId):

private function getInnerFilterExpressions(&$qb, $filterGroup, int $groupIndex): array {
$innerFilterExpressions = [];
foreach ($filterGroup as $index=>$filter) {
$innerFilterExpressions[] = $this->buildFilterByColumnType($qb, $filter, $groupIndex.$index);
foreach ($filterGroup as $index => $filter) {
$innerFilterExpressions[] = $this->buildFilterByColumnType($qb, $filter, $groupIndex.$index);
}
return $innerFilterExpressions;
}

private function getFilterGroups(&$qb, $filters): array {
$filterGroups = [];
foreach ($filters as $groupIndex=>$filterGroup) {
foreach ($filters as $groupIndex => $filterGroup) {
$filterGroups[] = $qb->expr()->andX(...$this->getInnerFilterExpressions($qb, $filterGroup, $groupIndex));
}
return $filterGroups;
Expand Down Expand Up @@ -140,18 +139,18 @@ private function resolveSearchValue(string $unresolvedSearchValue, string $userI
}

private function addOrderByRules(IQueryBuilder &$qb, $sortArray) {
foreach ($sortArray as $index=>$sortRule) {
foreach ($sortArray as $index => $sortRule) {
$sortMode = $sortRule['mode'];
if (!in_array($sortMode, ['ASC', 'DESC'])) {
continue;
}
$sortColumnPlaceholder = 'sortColumn'.$index;
$orderString = 'JSON_EXTRACT(data, CONCAT( JSON_UNQUOTE(JSON_SEARCH(JSON_EXTRACT(data, \'$[*].columnId\'), \'one\', :'.$sortColumnPlaceholder.')), \'.value\'))';
if (str_starts_with($sortRule['columnType'],'number')) {
if (str_starts_with($sortRule['columnType'], 'number')) {
$orderString = 'CAST('.$orderString.' as int)';
}
$qb->addOrderBy($qb->createFunction($orderString),$sortMode);
$qb->setParameter($sortColumnPlaceholder,$sortRule['columnId'], $qb::PARAM_INT);
$qb->addOrderBy($qb->createFunction($orderString), $sortMode);
$qb->setParameter($sortColumnPlaceholder, $sortRule['columnId'], $qb::PARAM_INT);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Db/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function jsonSerialize(): array {
'lastEditAt' => $this->lastEditAt,
'columns' => $this->getColumnsArray(),
'sort' => $this->getSortArray(),
'isBaseView'=> $this->isBaseView,
'isBaseView' => $this->isBaseView,
'isShared' => !!$this->isShared,
'onSharePermissions' => $this->onSharePermissions,
'hasShares' => $this->hasShares,
Expand Down
6 changes: 4 additions & 2 deletions lib/Db/ViewMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public function find(int $id, bool $skipEnhancement = false): View {
->from($this->table)
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
$view = $this->findEntity($qb);
if(!$skipEnhancement) $this->enhanceByOwnership($view);
if(!$skipEnhancement) {
$this->enhanceByOwnership($view);
}
return $view;
}

Expand Down Expand Up @@ -112,7 +114,7 @@ public function search(string $term = null, ?string $userId = null, ?int $limit

$qb->select('v.*')
->from($this->table, 'v')
->leftJoin('v','tables_tables', 't','t.id = v.table_id');
->leftJoin('v', 'tables_tables', 't', 't.id = v.table_id');

if ($userId !== null && $userId !== '') {
$qb->andWhere($qb->expr()->eq('ownership', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)))
Expand Down
2 changes: 1 addition & 1 deletion lib/Search/SearchTablesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SearchTablesProvider implements IProvider {

public function __construct(IAppManager $appManager,
IL10N $l10n,
ViewService $viewService,
ViewService $viewService,
IURLGenerator $urlGenerator) {
$this->appManager = $appManager;
$this->l10n = $l10n;
Expand Down
9 changes: 5 additions & 4 deletions lib/Service/ColumnService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use OCA\Tables\Db\Column;
use OCA\Tables\Db\ColumnMapper;
use OCA\Tables\Db\TableMapper;
use OCA\Tables\Db\ViewMapper;
use OCA\Tables\Errors\InternalError;
use OCA\Tables\Errors\NotFoundError;
use OCA\Tables\Errors\PermissionError;
Expand Down Expand Up @@ -79,12 +78,14 @@ public function findAllByView(int $viewId, ?string $userId = null): array {
$viewColumnIds = $view->getColumnsArray();
$viewColumns = [];
foreach ($viewColumnIds as $viewColumnId) {
if ($viewColumnId < 0) continue;
if ($viewColumnId < 0) {
continue;
}
try {
$viewColumns[] = $this->mapper->find($viewColumnId);
} catch (DoesNotExistException $e) {
$this->logger->warning($e->getMessage());
throw new NotFoundError($e->getMessage());
$this->logger->warning($e->getMessage());
throw new NotFoundError($e->getMessage());
} catch (MultipleObjectsReturnedException $e) {
$this->logger->error($e->getMessage());
throw new InternalError($e->getMessage());
Expand Down
Loading

0 comments on commit a666b09

Please sign in to comment.