瀏覽代碼

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

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3694 a333f486-631f-4898-b8df-5754b55c2be0
romainq 10 年之前
父節點
當前提交
5501af41d0

+ 20 - 12
core/csvbulkexport.class.inc.php

@@ -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,16 +348,16 @@ 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
-						// and thus to convert field by field and not the whole row or file at once (see ticket #991)
-						$aData[] = iconv('UTF-8', $this->aStatusInfo['charset'].'//IGNORE//TRANSLIT', $sField);
-					}
-					else
-					{
-						$aData[] = $sField;
-					}
+				}
+				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
+					// and thus to convert field by field and not the whole row or file at once (see ticket #991)
+					$aData[] = iconv('UTF-8', $this->aStatusInfo['charset'].'//IGNORE//TRANSLIT', $sField);
+				}
+				else
+				{
+					$aData[] = $sField;
 				}
 			}
 			$sData .= implode($this->aStatusInfo['separator'], $aData)."\n";

+ 24 - 20
core/excelbulkexport.class.inc.php

@@ -225,29 +225,33 @@ class ExcelBulkExport extends TabularBulkExport
 			$aData = array();
 			foreach($aAliasByField as $aAttCode)
 			{
+				$oObj = $aRow[$aAttCode['alias']];
 				$sField = '';
-				switch($aAttCode['attcode'])
+				if ($oObj)
 				{
-					case 'id':
-						$sField = $aRow[$aAttCode['alias']]->GetKey();
-						break;
-							
-					default:
-					$value = $aRow[$aAttCode['alias']]->Get($aAttCode['attcode']);
-					if ($value instanceOf ormCaseLog)
+					switch($aAttCode['attcode'])
 					{
-						// 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!
-						$sField = trim(preg_replace('/========== ([^=]+) ============/', '********** $1 ************', $value->GetText()));
-					}
-					else if ($value instanceOf DBObjectSet)
-					{
-						$oAttDef = MetaModel::GetAttributeDef(get_class($aRow[$aAttCode['alias']]), $aAttCode['attcode']);
-						$sField =  $oAttDef->GetAsCSV($value, '', '', $aRow[$aAttCode['alias']]);
-					}
-					else
-					{
-						$oAttDef = MetaModel::GetAttributeDef(get_class($aRow[$aAttCode['alias']]), $aAttCode['attcode']);
-						$sField =  $oAttDef->GetEditValue($value, $aRow[$aAttCode['alias']]);
+						case 'id':
+							$sField = $oObj->GetKey();
+							break;
+								
+						default:
+						$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!
+							$sField = trim(preg_replace('/========== ([^=]+) ============/', '********** $1 ************', $value->GetText()));
+						}
+						else if ($value instanceOf DBObjectSet)
+						{
+							$oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $aAttCode['attcode']);
+							$sField =  $oAttDef->GetAsCSV($value, '', '', $oObj);
+						}
+						else
+						{
+							$oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $aAttCode['attcode']);
+							$sField =  $oAttDef->GetEditValue($value, $oObj);
+						}
 					}
 				}
 				$aData[] = $sField;

+ 27 - 10
core/htmlbulkexport.class.inc.php

@@ -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);
-			$sHilightClass = $aRow[$sFirstAlias]->GetHilightClass();
+			$oMainObj = $aRow[$sFirstAlias];
+			$sHilightClass = '';
+			if ($oMainObj)
+			{
+				$sHilightClass = $aRow[$sFirstAlias]->GetHilightClass();
+			}
 			if ($sHilightClass != '')
 			{
 				$sData .= "<tr class=\"$sHilightClass\">";
@@ -194,15 +207,19 @@ class HTMLBulkExport extends TabularBulkExport
 			}
 			foreach($aAliasByField as $aAttCode)
 			{
+				$oObj = $aRow[$aAttCode['alias']];
 				$sField = '';
-				switch($aAttCode['attcode'])
+				if ($oObj)
 				{
-					case 'id':
-						$sField = $aRow[$aAttCode['alias']]->GetHyperlink();
-						break;
-							
-					default:
-						$sField = $aRow[$aAttCode['alias']]->GetAsHtml($aAttCode['attcode']);
+					switch($aAttCode['attcode'])
+					{
+						case 'id':
+							$sField = $aRow[$aAttCode['alias']]->GetHyperlink();
+							break;
+								
+						default:
+							$sField = $aRow[$aAttCode['alias']]->GetAsHtml($aAttCode['attcode']);
+					}
 				}
 				$sValue = ($sField === '') ? '&nbsp;' : $sField;
 				$sData .= "<td>$sValue</td>";

+ 10 - 2
core/spreadsheetbulkexport.class.inc.php

@@ -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()

+ 6 - 6
core/tabularbulkexport.class.inc.php

@@ -100,7 +100,7 @@ abstract class TabularBulkExport extends BulkExport
 			case 'AttributeExternalKey':
 			case 'AttributeHierarchicalKey':
 				$aResult[] = array('code' => $sAttCode, 'unique_label' => $oAttDef->GetLabel(), 'label' => Dict::S('Core:BulkExport:Identifier'), 'attdef' => $oAttDef);
-				$aResult[] = array('code' =>  $sAttCode.'_friendlyname', 'unique_label' => $oAttDef->GetLabel().'->'.Dict::S('Core:FriendlyName-Label'), 'label' => Dict::S('Core:FriendlyName-Label'), 'attdef' => MetaModel::GetAttributeDef($sClass, $sAttCode.'_friendlyname'));
+					$aResult[] = array('code' =>  $sAttCode.'_friendlyname', 'unique_label' => $oAttDef->GetLabel().'->'.Dict::S('Core:FriendlyName-Label'), 'label' => Dict::S('Core:FriendlyName-Label'), 'attdef' => MetaModel::GetAttributeDef($sClass, $sAttCode.'_friendlyname'));
 
 				foreach(MetaModel::ListAttributeDefs($sClass) as $sSubAttCode => $oSubAttDef)
 				{
@@ -158,10 +158,10 @@ abstract class TabularBulkExport extends BulkExport
 			if ($this->IsValidField($sClass, 'id'))
 			{
 				$aAllFields[] = array('code' =>  $sShortAlias.'id', 'unique_label' => $sShortAlias.Dict::S('Core:BulkExport:Identifier'), 'label' => $sShortAlias.'id', 'subattr' => array(
-					array('code' =>  $sShortAlias.'id', 'unique_label' => $sShortAlias.Dict::S('Core:BulkExport:Identifier'), 'label' => $sShortAlias.'id'),
-					array('code' =>  $sShortAlias.'friendlyname', 'unique_label' => $sShortAlias.Dict::S('Core:FriendlyName-Label'), 'label' => $sShortAlias.Dict::S('Core:FriendlyName-Label')),
+						array('code' =>  $sShortAlias.'id', 'unique_label' => $sShortAlias.Dict::S('Core:BulkExport:Identifier'), 'label' => $sShortAlias.'id'),
+						array('code' =>  $sShortAlias.'friendlyname', 'unique_label' => $sShortAlias.Dict::S('Core:FriendlyName-Label'), 'label' => $sShortAlias.Dict::S('Core:FriendlyName-Label')),
 				));
-			}
+				}
 			foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
 			{
 				if($this->IsSubAttribute($sClass, $sAttCode, $oAttDef)) continue;
@@ -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();

+ 10 - 2
core/xmlbulkexport.class.inc.php

@@ -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()

+ 56 - 1
webservices/itoprest.examples.php

@@ -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;