Skip to content

Add ability to get global structure data by remote API #732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions meta/AccessTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
*
Expand All @@ -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) {
Expand Down