diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 50ca906d0..ae7bb4fe5 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -39,6 +39,8 @@ abstract class DBObject private $m_aCurrValues = array(); protected $m_aOrigValues = array(); + protected $m_aExtendedData = null; + private $m_bDirty = false; // Means: "a modification is ongoing" // 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 @@ -50,11 +52,11 @@ abstract class DBObject 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?) - public function __construct($aRow = null, $sClassAlias = '') + public function __construct($aRow = null, $sClassAlias = '', $aExtendedDataSpec = null) { if (!empty($aRow)) { - $this->FromRow($aRow, $sClassAlias); + $this->FromRow($aRow, $sClassAlias, $aExtendedDataSpec); $this->m_bFullyLoaded = $this->IsFullyLoaded(); return; } @@ -181,7 +183,7 @@ abstract class DBObject $this->m_bFullyLoaded = true; } - protected function FromRow($aRow, $sClassAlias = '') + protected function FromRow($aRow, $sClassAlias = '', $aExtendedDataSpec = null) { if (strlen($sClassAlias) == 0) { @@ -245,6 +247,20 @@ abstract class DBObject $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; } @@ -345,6 +361,14 @@ abstract class DBObject 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 * corresponding to the external key and getting the value from it diff --git a/core/dbobjectset.class.php b/core/dbobjectset.class.php index a55e1172f..418a7955f 100644 --- a/core/dbobjectset.class.php +++ b/core/dbobjectset.class.php @@ -38,11 +38,12 @@ class DBObjectSet private $m_aId2Row; 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_aOrderBy = $aOrderBy; $this->m_aArgs = $aArgs; + $this->m_aExtendedDataSpec = $aExtendedDataSpec; $this->m_iLimitCount = $iLimitCount; $this->m_iLimitStart = $iLimitStart; @@ -241,11 +242,11 @@ class DBObjectSet if ($this->m_bLoaded) return; 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 { - $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); if (!$resQuery) return; @@ -256,7 +257,7 @@ class DBObjectSet $aObjects = array(); 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; } $this->AddObjectExtended($aObjects); @@ -268,7 +269,7 @@ class DBObjectSet 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); if (!$resQuery) return 0; diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 643bda5ac..563bac104 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -1708,7 +1708,7 @@ abstract class MetaModel 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 // @@ -1800,6 +1800,21 @@ abstract class MetaModel $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 // @@ -3656,7 +3671,7 @@ abstract class MetaModel return $aRow; } - public static function GetObjectByRow($sClass, $aRow, $sClassAlias = '') + public static function GetObjectByRow($sClass, $aRow, $sClassAlias = '', $aExtendedDataSpec = null) { self::_check_subclass($sClass); @@ -3685,7 +3700,7 @@ abstract class MetaModel // do the job for the real target class $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) diff --git a/core/sqlquery.class.inc.php b/core/sqlquery.class.inc.php index 271240ad4..e34c3120d 100644 --- a/core/sqlquery.class.inc.php +++ b/core/sqlquery.class.inc.php @@ -46,7 +46,7 @@ class SQLQuery private $m_aValues = array(); // Values to set in case of an update query 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 //if (!CMDBSource::IsTable($sTable)) diff --git a/css/light-grey.css b/css/light-grey.css index 0cdd24416..c0949a8cc 100644 --- a/css/light-grey.css +++ b/css/light-grey.css @@ -917,3 +917,6 @@ span.form_validation { width: 95%; -moz-border-radius: 0.5em; } +.wiki_broken_link { + text-decoration: line-through; +} \ No newline at end of file