mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 17:48:43 +02:00
Implemented the capability to modify queries by the mean of a plugin (make it work with APC cache)
SVN:1.2[1842]
This commit is contained in:
@@ -68,10 +68,6 @@ class DBObjectSearch
|
||||
$this->m_aParentConditions = array();
|
||||
|
||||
$this->m_aModifierProperties = array();
|
||||
foreach (MetaModel::EnumPlugins('iQueryModifier') as $sPluginClass => $oQueryModifier)
|
||||
{
|
||||
$this->m_aModifierProperties[$sPluginClass] = ApplicationContext::GetPluginProperties($sPluginClass);
|
||||
}
|
||||
}
|
||||
|
||||
public function AllowAllData() {$this->m_bAllowAllData = true;}
|
||||
|
||||
@@ -1934,12 +1934,40 @@ if (!array_key_exists($sAttCode, self::$m_aAttribDefs[$sClass]))
|
||||
}
|
||||
}
|
||||
|
||||
// Compute query modifiers properties (can be set in the search itself, by the context, etc.)
|
||||
//
|
||||
$aModifierProperties = array();
|
||||
foreach (MetaModel::EnumPlugins('iQueryModifier') as $sPluginClass => $oQueryModifier)
|
||||
{
|
||||
// Lowest precedence: the application context
|
||||
$aPluginProps = ApplicationContext::GetPluginProperties($sPluginClass);
|
||||
// Highest precedence: programmatically specified (or OQL)
|
||||
foreach($oFilter->GetModifierProperties($sPluginClass) as $sProp => $value)
|
||||
{
|
||||
$aPluginProps[$sProp] = $value;
|
||||
}
|
||||
if (count($aPluginProps) > 0)
|
||||
{
|
||||
$aModifierProperties[$sPluginClass] = $aPluginProps;
|
||||
}
|
||||
}
|
||||
|
||||
if (self::$m_bQueryCacheEnabled || self::$m_bTraceQueries)
|
||||
{
|
||||
// Need to identify the query
|
||||
$sOqlQuery = $oFilter->ToOql();
|
||||
|
||||
$sRawId = $sOqlQuery;
|
||||
if (count($aModifierProperties))
|
||||
{
|
||||
array_multisort($aModifierProperties);
|
||||
$sModifierProperties = json_encode($aModifierProperties);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sModifierProperties = '';
|
||||
}
|
||||
|
||||
$sRawId = $sOqlQuery.$sModifierProperties;
|
||||
if (!is_null($aAttToLoad))
|
||||
{
|
||||
foreach($aAttToLoad as $sAlias => $aAttributes)
|
||||
@@ -2035,7 +2063,7 @@ if (!array_key_exists($sAttCode, self::$m_aAttribDefs[$sClass]))
|
||||
|
||||
if (!isset($oSelect))
|
||||
{
|
||||
$oBuild = new QueryBuilderContext($oFilter);
|
||||
$oBuild = new QueryBuilderContext($oFilter, $aModifierProperties);
|
||||
|
||||
$oKPI = new ExecutionKPI();
|
||||
$oSelect = self::MakeQuery($oBuild, $oFilter, $aAttToLoad, array(), true /* main query */);
|
||||
|
||||
@@ -28,16 +28,19 @@ class QueryBuilderContext
|
||||
protected $m_oRootFilter;
|
||||
protected $m_aClassAliases;
|
||||
protected $m_aTableAliases;
|
||||
protected $m_aModifierProperties;
|
||||
|
||||
public $m_oQBExpressions;
|
||||
|
||||
public function __construct($oFilter)
|
||||
public function __construct($oFilter, $aModifierProperties)
|
||||
{
|
||||
$this->m_oRootFilter = $oFilter;
|
||||
$this->m_oQBExpressions = new QueryBuilderExpressions($oFilter->GetCriteria());
|
||||
|
||||
$this->m_aClassAliases = $oFilter->GetJoinedClasses();
|
||||
$this->m_aTableAliases = array();
|
||||
|
||||
$this->m_aModifierProperties = $aModifierProperties;
|
||||
}
|
||||
|
||||
public function GetRootFilter()
|
||||
@@ -54,6 +57,18 @@ class QueryBuilderContext
|
||||
{
|
||||
return MetaModel::GenerateUniqueAlias($this->m_aClassAliases, $sNewName, $sRealName);
|
||||
}
|
||||
|
||||
public function GetModifierProperties($sPluginClass)
|
||||
{
|
||||
if (array_key_exists($sPluginClass, $this->m_aModifierProperties))
|
||||
{
|
||||
return $this->m_aModifierProperties[$sPluginClass];
|
||||
}
|
||||
else
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user