mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Core: Join any table to an OQL query (prerequisite to Data Exchange)
SVN:trunk[1061]
This commit is contained in:
@@ -39,6 +39,8 @@ abstract class DBObject
|
|||||||
private $m_aCurrValues = array();
|
private $m_aCurrValues = array();
|
||||||
protected $m_aOrigValues = array();
|
protected $m_aOrigValues = array();
|
||||||
|
|
||||||
|
protected $m_aExtendedData = null;
|
||||||
|
|
||||||
private $m_bDirty = false; // Means: "a modification is ongoing"
|
private $m_bDirty = false; // Means: "a modification is ongoing"
|
||||||
// The object may have incorrect external keys, then any attempt of reload must be avoided
|
// The object may have incorrect external keys, then any attempt of reload must be avoided
|
||||||
private $m_bCheckStatus = null; // Means: the object has been verified and is consistent with integrity rules
|
private $m_bCheckStatus = null; // Means: the object has been verified and is consistent with integrity rules
|
||||||
@@ -50,11 +52,11 @@ abstract class DBObject
|
|||||||
private $m_aLoadedAtt = array(); // Compound objects can be partially loaded, array of sAttCode
|
private $m_aLoadedAtt = array(); // Compound objects can be partially loaded, array of sAttCode
|
||||||
|
|
||||||
// Use the MetaModel::NewObject to build an object (do we have to force it?)
|
// Use the MetaModel::NewObject to build an object (do we have to force it?)
|
||||||
public function __construct($aRow = null, $sClassAlias = '')
|
public function __construct($aRow = null, $sClassAlias = '', $aExtendedDataSpec = null)
|
||||||
{
|
{
|
||||||
if (!empty($aRow))
|
if (!empty($aRow))
|
||||||
{
|
{
|
||||||
$this->FromRow($aRow, $sClassAlias);
|
$this->FromRow($aRow, $sClassAlias, $aExtendedDataSpec);
|
||||||
$this->m_bFullyLoaded = $this->IsFullyLoaded();
|
$this->m_bFullyLoaded = $this->IsFullyLoaded();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -181,7 +183,7 @@ abstract class DBObject
|
|||||||
$this->m_bFullyLoaded = true;
|
$this->m_bFullyLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function FromRow($aRow, $sClassAlias = '')
|
protected function FromRow($aRow, $sClassAlias = '', $aExtendedDataSpec = null)
|
||||||
{
|
{
|
||||||
if (strlen($sClassAlias) == 0)
|
if (strlen($sClassAlias) == 0)
|
||||||
{
|
{
|
||||||
@@ -245,6 +247,20 @@ abstract class DBObject
|
|||||||
$bFullyLoaded = false;
|
$bFullyLoaded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load extended data
|
||||||
|
if ($aExtendedDataSpec != null)
|
||||||
|
{
|
||||||
|
$aExtendedDataSpec['table'];
|
||||||
|
foreach($aExtendedDataSpec['fields'] as $sColumn)
|
||||||
|
{
|
||||||
|
$sColRef = $sClassAlias.'_extdata_'.$sColumn;
|
||||||
|
if (array_key_exists($sColRef, $aRow))
|
||||||
|
{
|
||||||
|
$this->m_aExtendedData[$sColumn] = $aRow[$sColRef];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return $bFullyLoaded;
|
return $bFullyLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,6 +361,14 @@ abstract class DBObject
|
|||||||
return $this->m_aOrigValues[$sAttCode];
|
return $this->m_aOrigValues[$sAttCode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns data loaded by the mean of a dynamic and explicit JOIN
|
||||||
|
*/
|
||||||
|
public function GetExtendedData()
|
||||||
|
{
|
||||||
|
return $this->m_aExtendedData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the value of an external field by (re)loading the object
|
* Updates the value of an external field by (re)loading the object
|
||||||
* corresponding to the external key and getting the value from it
|
* corresponding to the external key and getting the value from it
|
||||||
|
|||||||
@@ -38,11 +38,12 @@ class DBObjectSet
|
|||||||
private $m_aId2Row;
|
private $m_aId2Row;
|
||||||
private $m_iCurrRow;
|
private $m_iCurrRow;
|
||||||
|
|
||||||
public function __construct(DBObjectSearch $oFilter, $aOrderBy = array(), $aArgs = array(), $iLimitCount = 0, $iLimitStart = 0)
|
public function __construct(DBObjectSearch $oFilter, $aOrderBy = array(), $aArgs = array(), $aExtendedDataSpec = null, $iLimitCount = 0, $iLimitStart = 0)
|
||||||
{
|
{
|
||||||
$this->m_oFilter = $oFilter;
|
$this->m_oFilter = $oFilter;
|
||||||
$this->m_aOrderBy = $aOrderBy;
|
$this->m_aOrderBy = $aOrderBy;
|
||||||
$this->m_aArgs = $aArgs;
|
$this->m_aArgs = $aArgs;
|
||||||
|
$this->m_aExtendedDataSpec = $aExtendedDataSpec;
|
||||||
$this->m_iLimitCount = $iLimitCount;
|
$this->m_iLimitCount = $iLimitCount;
|
||||||
$this->m_iLimitStart = $iLimitStart;
|
$this->m_iLimitStart = $iLimitStart;
|
||||||
|
|
||||||
@@ -241,11 +242,11 @@ class DBObjectSet
|
|||||||
if ($this->m_bLoaded) return;
|
if ($this->m_bLoaded) return;
|
||||||
if ($this->m_iLimitCount > 0)
|
if ($this->m_iLimitCount > 0)
|
||||||
{
|
{
|
||||||
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs, $this->m_iLimitCount, $this->m_iLimitStart);
|
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs, $this->m_aExtendedDataSpec, $this->m_iLimitCount, $this->m_iLimitStart);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs);
|
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs, $this->m_aExtendedDataSpec);
|
||||||
}
|
}
|
||||||
$resQuery = CMDBSource::Query($sSQL);
|
$resQuery = CMDBSource::Query($sSQL);
|
||||||
if (!$resQuery) return;
|
if (!$resQuery) return;
|
||||||
@@ -256,7 +257,7 @@ class DBObjectSet
|
|||||||
$aObjects = array();
|
$aObjects = array();
|
||||||
foreach ($this->m_oFilter->GetSelectedClasses() as $sClassAlias => $sClass)
|
foreach ($this->m_oFilter->GetSelectedClasses() as $sClassAlias => $sClass)
|
||||||
{
|
{
|
||||||
$oObject = MetaModel::GetObjectByRow($sClass, $aRow, $sClassAlias);
|
$oObject = MetaModel::GetObjectByRow($sClass, $aRow, $sClassAlias, $this->m_aExtendedDataSpec);
|
||||||
$aObjects[$sClassAlias] = $oObject;
|
$aObjects[$sClassAlias] = $oObject;
|
||||||
}
|
}
|
||||||
$this->AddObjectExtended($aObjects);
|
$this->AddObjectExtended($aObjects);
|
||||||
@@ -268,7 +269,7 @@ class DBObjectSet
|
|||||||
|
|
||||||
public function Count()
|
public function Count()
|
||||||
{
|
{
|
||||||
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs, 0, 0, true);
|
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs, null, 0, 0, true);
|
||||||
$resQuery = CMDBSource::Query($sSQL);
|
$resQuery = CMDBSource::Query($sSQL);
|
||||||
if (!$resQuery) return 0;
|
if (!$resQuery) return 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1708,7 +1708,7 @@ abstract class MetaModel
|
|||||||
return $aScalarArgs;
|
return $aScalarArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function MakeSelectQuery(DBObjectSearch $oFilter, $aOrderBy = array(), $aArgs = array(), $iLimitCount = 0, $iLimitStart = 0, $bGetCount = false)
|
public static function MakeSelectQuery(DBObjectSearch $oFilter, $aOrderBy = array(), $aArgs = array(), $aExtendedDataSpec = null, $iLimitCount = 0, $iLimitStart = 0, $bGetCount = false)
|
||||||
{
|
{
|
||||||
// Hide objects that are not visible to the current user
|
// Hide objects that are not visible to the current user
|
||||||
//
|
//
|
||||||
@@ -1800,6 +1800,21 @@ abstract class MetaModel
|
|||||||
$aOrderSpec[$sSelectedAlias."friendlyname"] = true;
|
$aOrderSpec[$sSelectedAlias."friendlyname"] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Join to an additional table, if required...
|
||||||
|
//
|
||||||
|
if ($aExtendedDataSpec != null)
|
||||||
|
{
|
||||||
|
$sTableAlias = '_extended_data_';
|
||||||
|
$aExtendedFields = array();
|
||||||
|
foreach($aExtendedDataSpec['fields'] as $sColumn)
|
||||||
|
{
|
||||||
|
$sColRef = $oFilter->GetClassAlias().'_extdata_'.$sColumn;
|
||||||
|
$aExtendedFields[$sColRef] = new FieldExpressionResolved($sColumn, $sTableAlias);;
|
||||||
|
}
|
||||||
|
$oSelectExt = new SQLQuery($aExtendedDataSpec['table'], $sTableAlias, $aExtendedFields);
|
||||||
|
$oSelect->AddInnerJoin($oSelectExt, 'id', $aExtendedDataSpec['join_key'] /*, $sTableAlias*/);
|
||||||
|
}
|
||||||
|
|
||||||
// Go
|
// Go
|
||||||
//
|
//
|
||||||
@@ -3656,7 +3671,7 @@ abstract class MetaModel
|
|||||||
return $aRow;
|
return $aRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetObjectByRow($sClass, $aRow, $sClassAlias = '')
|
public static function GetObjectByRow($sClass, $aRow, $sClassAlias = '', $aExtendedDataSpec = null)
|
||||||
{
|
{
|
||||||
self::_check_subclass($sClass);
|
self::_check_subclass($sClass);
|
||||||
|
|
||||||
@@ -3685,7 +3700,7 @@ abstract class MetaModel
|
|||||||
// do the job for the real target class
|
// do the job for the real target class
|
||||||
$sClass = $aRow[$sClassAlias."finalclass"];
|
$sClass = $aRow[$sClassAlias."finalclass"];
|
||||||
}
|
}
|
||||||
return new $sClass($aRow, $sClassAlias);
|
return new $sClass($aRow, $sClassAlias, $aExtendedDataSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetObject($sClass, $iKey, $bMustBeFound = true, $bAllowAllData = false)
|
public static function GetObject($sClass, $iKey, $bMustBeFound = true, $bAllowAllData = false)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class SQLQuery
|
|||||||
private $m_aValues = array(); // Values to set in case of an update query
|
private $m_aValues = array(); // Values to set in case of an update query
|
||||||
private $m_aJoinSelects = array();
|
private $m_aJoinSelects = array();
|
||||||
|
|
||||||
public function __construct($sTable, $sTableAlias, $aFields, $aFullTextNeedles, $bToDelete = true, $aValues = array())
|
public function __construct($sTable, $sTableAlias, $aFields, $aFullTextNeedles = array(), $bToDelete = true, $aValues = array())
|
||||||
{
|
{
|
||||||
// This check is not needed but for developping purposes
|
// This check is not needed but for developping purposes
|
||||||
//if (!CMDBSource::IsTable($sTable))
|
//if (!CMDBSource::IsTable($sTable))
|
||||||
|
|||||||
@@ -917,3 +917,6 @@ span.form_validation {
|
|||||||
width: 95%;
|
width: 95%;
|
||||||
-moz-border-radius: 0.5em;
|
-moz-border-radius: 0.5em;
|
||||||
}
|
}
|
||||||
|
.wiki_broken_link {
|
||||||
|
text-decoration: line-through;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user