Skip to content

Commit

Permalink
Update AnalyticsDatasource.php
Browse files Browse the repository at this point in the history
Signed-off-by: Rello <Rello@users.noreply.github.com>
  • Loading branch information
Rello committed Jul 3, 2024
1 parent 97a5c32 commit d83fc2a
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions lib/Analytics/AnalyticsDatasource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
use OCA\Tables\Errors\InternalError;
use OCA\Tables\Errors\NotFoundError;
use OCA\Tables\Errors\PermissionError;
use OCA\Tables\Service\TableService;
use OCA\Tables\Service\ViewService;
use OCA\Tables\Service\ColumnService;
use OCA\Tables\Service\RowService;
use OCA\Tables\Service\TableService;
use OCA\Tables\Service\ViewService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IL10N;
use Psr\Log\LoggerInterface;

class AnalyticsDatasource implements IDatasource {
class AnalyticsDatasource implements IDatasource
{
private LoggerInterface $logger;
private IL10N $l10n;
private TableService $tableService;
Expand All @@ -39,10 +40,11 @@ public function __construct(
LoggerInterface $logger,
TableService $tableService,
ViewService $viewService,
ColumnService $columnService,
ColumnService $columnService,
RowService $rowService,
?string $userId
) {
)
{
$this->l10n = $l10n;
$this->logger = $logger;
$this->tableService = $tableService;
Expand All @@ -55,14 +57,16 @@ public function __construct(
/**
* @return string Display Name of the datasource
*/
public function getName(): string {
public function getName(): string
{
return $this->l10n->t('Nextcloud Tables');
}

/**
* @return int 2 digit unique datasource id
*/
public function getId(): int {
public function getId(): int
{
return 55;
}

Expand Down Expand Up @@ -92,7 +96,8 @@ public function getId(): int {
* @throws NotFoundError
* @throws PermissionError
*/
public function getTemplate(): array {
public function getTemplate(): array
{
$tableString = '';
$template = [];
$tables = [];
Expand Down Expand Up @@ -138,17 +143,18 @@ public function getTemplate(): array {
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function readData($option): array {
public function readData($option): array
{
// get the ids which come in the format tableId:viewId
$ids = explode(':', $option['tableId']);
$this->userId = $option['user_id'];

if (count($ids) === 1) {
// it's a table
$data = $this->getData((int) $ids[0], null, null);
$data = $this->getData((int)$ids[0], null, null);
} elseif (count($ids) === 2) {
// it's a view
$data = $this->getData((int) $ids[1], null, null, 'view');
$data = $this->getData((int)$ids[1], null, null, 'view');
}

// extract the header from the first row
Expand Down Expand Up @@ -186,9 +192,9 @@ public function readData($option): array {
}

/**
* Get the data from the table backend
* this was taken over from the former API
*
* Get the data from the table backend
* this was taken over from the former API
*
* @param int $nodeId
* @param int|null $limit
* @param int|null $offset
Expand All @@ -200,7 +206,8 @@ public function readData($option): array {
* @throws NotFoundError
* @throws PermissionError
*/
private function getData(int $nodeId, ?int $limit, ?int $offset, ?string $nodeType = null): array {
private function getData(int $nodeId, ?int $limit, ?int $offset, ?string $nodeType = null): array
{
if ($nodeType === 'view') {
$columns = $this->columnService->findAllByView($nodeId, $this->userId);
$rows = $this->rowService->findAllByView($nodeId, $this->userId, $limit, $offset);
Expand Down Expand Up @@ -253,7 +260,8 @@ private function getData(int $nodeId, ?int $limit, ?int $offset, ?string $nodeTy
* @param array $row
* @return array
*/
private function minimizeRow(array $selectedColumns, array $row): array {
private function minimizeRow(array $selectedColumns, array $row): array
{
$rowMinimized = [];
foreach ($selectedColumns as $selectedColumn) {
if ((int)$selectedColumn) {
Expand Down

0 comments on commit d83fc2a

Please sign in to comment.