Exports: support multi-column queries (e.g. SELECT l, p FROM Person AS p JOIN Location AS l ON p.location_id = l.id) with null values

SVN:trunk[3694]
This commit is contained in:
Romain Quetiez
2015-08-24 08:01:24 +00:00
parent b1887ae431
commit 5277a9eb38
7 changed files with 153 additions and 53 deletions

View File

@@ -168,9 +168,17 @@ class CSVBulkExport extends TabularBulkExport
}
}
protected function GetSampleData(DBObject $oObj, $sAttCode)
protected function GetSampleData($oObj, $sAttCode)
{
return trim($oObj->GetAsCSV($sAttCode), '"');
if ($oObj)
{
$sRet = trim($oObj->GetAsCSV($sAttCode), '"');
}
else
{
$sRet = '';
}
return $sRet;
}
public function GetHeader()
@@ -340,6 +348,7 @@ class CSVBulkExport extends TabularBulkExport
default:
$sField = $oObj->GetAsCSV($aAttCode['attcode'], $this->aStatusInfo['separator'], $this->aStatusInfo['text_qualifier'], $this->aStatusInfo['localize']);
}
}
if ($this->aStatusInfo['charset'] != 'UTF-8')
{
// Note: due to bugs in the glibc library it's safer to call iconv on the smallest possible string
@@ -351,7 +360,6 @@ class CSVBulkExport extends TabularBulkExport
$aData[] = $sField;
}
}
}
$sData .= implode($this->aStatusInfo['separator'], $aData)."\n";
$iCount++;
}

View File

@@ -225,15 +225,18 @@ class ExcelBulkExport extends TabularBulkExport
$aData = array();
foreach($aAliasByField as $aAttCode)
{
$oObj = $aRow[$aAttCode['alias']];
$sField = '';
if ($oObj)
{
switch($aAttCode['attcode'])
{
case 'id':
$sField = $aRow[$aAttCode['alias']]->GetKey();
$sField = $oObj->GetKey();
break;
default:
$value = $aRow[$aAttCode['alias']]->Get($aAttCode['attcode']);
$value = $oObj->Get($aAttCode['attcode']);
if ($value instanceOf ormCaseLog)
{
// Extract the case log as text and remove the "===" which make Excel think that the cell contains a formula the next time you edit it!
@@ -241,13 +244,14 @@ class ExcelBulkExport extends TabularBulkExport
}
else if ($value instanceOf DBObjectSet)
{
$oAttDef = MetaModel::GetAttributeDef(get_class($aRow[$aAttCode['alias']]), $aAttCode['attcode']);
$sField = $oAttDef->GetAsCSV($value, '', '', $aRow[$aAttCode['alias']]);
$oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $aAttCode['attcode']);
$sField = $oAttDef->GetAsCSV($value, '', '', $oObj);
}
else
{
$oAttDef = MetaModel::GetAttributeDef(get_class($aRow[$aAttCode['alias']]), $aAttCode['attcode']);
$sField = $oAttDef->GetEditValue($value, $aRow[$aAttCode['alias']]);
$oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $aAttCode['attcode']);
$sField = $oAttDef->GetEditValue($value, $oObj);
}
}
}
$aData[] = $sField;

View File

@@ -49,9 +49,17 @@ class HTMLBulkExport extends TabularBulkExport
}
}
protected function GetSampleData(DBObject $oObj, $sAttCode)
protected function GetSampleData($oObj, $sAttCode)
{
return $oObj->GetAsHTML($sAttCode);
if ($oObj)
{
$sRet = $oObj->GetAsHTML($sAttCode);
}
else
{
$sRet = '';
}
return $sRet;
}
public function GetHeader()
@@ -183,7 +191,12 @@ class HTMLBulkExport extends TabularBulkExport
{
set_time_limit($iLoopTimeLimit);
$sFirstAlias = reset($aAliases);
$oMainObj = $aRow[$sFirstAlias];
$sHilightClass = '';
if ($oMainObj)
{
$sHilightClass = $aRow[$sFirstAlias]->GetHilightClass();
}
if ($sHilightClass != '')
{
$sData .= "<tr class=\"$sHilightClass\">";
@@ -194,7 +207,10 @@ class HTMLBulkExport extends TabularBulkExport
}
foreach($aAliasByField as $aAttCode)
{
$oObj = $aRow[$aAttCode['alias']];
$sField = '';
if ($oObj)
{
switch($aAttCode['attcode'])
{
case 'id':
@@ -204,6 +220,7 @@ class HTMLBulkExport extends TabularBulkExport
default:
$sField = $aRow[$aAttCode['alias']]->GetAsHtml($aAttCode['attcode']);
}
}
$sValue = ($sField === '') ? '&nbsp;' : $sField;
$sData .= "<td>$sValue</td>";
}

View File

@@ -68,9 +68,17 @@ class SpreadsheetBulkExport extends TabularBulkExport
$this->aStatusInfo['localize'] = (utils::ReadParam('no_localize', 0) != 1);
}
protected function GetSampleData(DBObject $oObj, $sAttCode)
protected function GetSampleData($oObj, $sAttCode)
{
return $oObj->GetAsHTML($sAttCode);
if ($oObj)
{
$sRet = $oObj->GetAsHTML($sAttCode);
}
else
{
$sRet = '';
}
return $sRet;
}
public function GetHeader()

View File

@@ -266,13 +266,13 @@ EOF
return true; //$oAttDef->IsScalar();
}
protected function GetSampleData(DBObject $oObj, $sAttCode)
protected function GetSampleData($oObj, $sAttCode)
{
if ($oObj == null) return '';
return $oObj->GetEditValue($sAttCode);
}
protected function GetSampleKey(DBObject $oObj)
protected function GetSampleKey($oObj)
{
if ($oObj == null) return '';
return $oObj->GetKey();

View File

@@ -63,9 +63,17 @@ class XMLBulkExport extends BulkExport
$this->aStatusInfo['localize'] = (utils::ReadParam('no_localize', 0) != 1);
}
protected function GetSampleData(DBObject $oObj, $sAttCode)
protected function GetSampleData($oObj, $sAttCode)
{
return $oObj->GetAsXML($sAttCode);
if ($oObj)
{
$sRet = $oObj->GetAsXML($sAttCode);
}
else
{
$sRet = '';
}
return $sRet;
}
public function GetHeader()

View File

@@ -158,8 +158,63 @@ $aOperations = array(
'depth' => 4, // max recursion depth
),
);
$aOperations = array(
array(
'operation' => 'core/create', // operation code
'comment' => 'Automatic creation of attachment blah blah...', // comment recorded in the change tracking log
'class' => 'Attachment',
'output_fields' => 'id, friendlyname', // list of fields to show in the results (* or a,b,c)
// Values for the object to create
'fields' => array(
'item_class' => 'UserRequest',
'item_id' => 1,
'item_org_id' => 3,
'contents' => array(
'data' => 'iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAIAAAC0tAIdAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACmSURBVChTfZHRDYMwDESzQ2fqhHx3C3ao+MkW/WlnaFxfzk7sEnE6JHJ+NgaKZN2zLHVN2ssfkae0Da7FQ5PRk/ve4Hcx19Ie6CEGuh/6vMgNhwanHVUNbt73lUDbYJ+6pg8b3+m2RehsVPdMXyvQY+OVkB+Rrv64lUjb3nq+aCA6v4leRqtfaIgimr53atBy9PlfUhoh3fFCNDmErv9FWR6ylBL5AREbmHBnFj5lAAAAAElFTkSuQmCC',
'filename' => 'myself.png',
'mimetype' => 'image/png'
),
),
),
array(
'operation' => 'core/get', // operation code
'class' => 'Attachment',
'key' => 'SELECT Attachment',
'output_fields' => '*',
)
);
$aOperations = array(
array(
'operation' => 'core/get', // operation code
'class' => 'PhysicalDevice',
'key' => 'SELECT PhysicalDevice WHERE id < 3',
'output_fields' => '*+', // list of fields to show in the results (* or a,b,c)
),
);
$aOperations = array(
array(
'operation' => 'core/create', // operation code
'comment' => 'Synchronization from blah...', // comment recorded in the change tracking log
'class' => 'UserRequest',
'output_fields' => 'id, friendlyname', // list of fields to show in the results (* or a,b,c)
// Values for the object to create
'fields' => array(
'org_id' => "SELECT Organization WHERE name = 'Demo'",
'caller_id' => array('name' => 'monet', 'first_name' => 'claude'),
'title' => 'issue blah',
'description' => 'something happened'
),
),
);
$aXXXOperations = array(
array(
'operation' => 'core/check_credentials', // operation code
'user' => 'admin',
'password' => 'admin',
),
);
if (true)
if (false)
{
echo "Please edit the sample script and configure the server URL";
exit;