From a7e0058e66dada4710d7297ba8dae99f82aa21a1 Mon Sep 17 00:00:00 2001 From: Maxim S Date: Sat, 8 Mar 2025 17:36:36 +0100 Subject: [PATCH] Add ability to get global structure data by remote API --- meta/AccessTable.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/meta/AccessTable.php b/meta/AccessTable.php index b4b4d50d..f263e48d 100644 --- a/meta/AccessTable.php +++ b/meta/AccessTable.php @@ -456,6 +456,32 @@ protected function consolidateData($DBdata, $asarray = false) { $data = []; + if ($this->isGlobalData()) { + foreach ($DBdata as $i => $db_data_row) { + $new_data = [ + 'id' => $db_data_row['rid'], + ...$this->consolidateRowData([$db_data_row], $asarray) + ]; + $data[] = $new_data; + } + } else { + $data = $this->consolidateRowData($DBdata, $asarray); + } + + return $data; + } + + /** + * Creates a proper result array from the database data for single row + * + * @param array $DBdata the data row + * @param bool $asarray return data as associative array (true) or as array of Values (false) + * @return array|Value[] + */ + protected function consolidateRowData($DBdata, $asarray = false) + { + $data = []; + $sep = Search::CONCAT_SEPARATOR; foreach ($this->schema->getColumns(false) as $col) { @@ -488,6 +514,15 @@ protected function consolidateData($DBdata, $asarray = false) return $data; } + /** + * Determine is the data taken from global struct + * @return bool + */ + protected function isGlobalData() + { + return !$this->pid && !$this->rid; + } + /** * Builds the SQL statement to select the data for this page and schema * @@ -502,6 +537,12 @@ protected function buildGetDataSQL($idColumn = 'pid') $QB = new QueryBuilder(); $QB->addTable($stable, 'DATA'); $QB->addSelectColumn('DATA', $idColumn, strtoupper($idColumn)); + + // add record ids for global data records + if ($this->isGlobalData()) { + $QB->addSelectColumn('DATA', 'rid'); + } + $QB->addGroupByStatement("DATA.$idColumn"); foreach ($this->schema->getColumns(false) as $col) {