mirror of
https://github.com/Combodo/iTop.git
synced 2026-09-18 23:49:14 +02:00
Enhancement: the default value for a module's parameter can now be specified (and altered) via the XML and will no longer reside in the configuration file.
SVN:trunk[3518]
This commit is contained in:
@@ -40,6 +40,9 @@ class MFCompiler
|
||||
|
||||
$this->aLog = array();
|
||||
$this->sMainPHPCode = '<'.'?'."php\n";
|
||||
$this->sMainPHPCode .= "/**\n";
|
||||
$this->sMainPHPCode .= " * This file was automatically generated by the compiler on ".date('Y-m-d H:i:s')." -- DO NOT EDIT\n";
|
||||
$this->sMainPHPCode .= " */\n";
|
||||
}
|
||||
|
||||
protected function Log($sText)
|
||||
@@ -384,6 +387,10 @@ EOF;
|
||||
$oPortalsNode = $this->oFactory->GetNodes('/itop_design/portals')->item(0);
|
||||
$this->CompilePortals($oPortalsNode, $sTempTargetDir, $sFinalTargetDir);
|
||||
|
||||
// Compile the XML parameters
|
||||
$oParametersNode = $this->oFactory->GetNodes('/itop_design/module_parameters')->item(0);
|
||||
$this->CompileParameters($oParametersNode, $sTempTargetDir, $sFinalTargetDir);
|
||||
|
||||
// Write core/main.php
|
||||
SetupUtils::builddir($sTempTargetDir.'/core');
|
||||
$sPHPFile = $sTempTargetDir.'/core/main.php';
|
||||
@@ -1977,9 +1984,13 @@ EOF;
|
||||
|
||||
uasort($aPortalsConfig, array(get_class($this), 'SortOnRank'));
|
||||
|
||||
$this->sMainPHPCode .= "\n";
|
||||
$this->sMainPHPCode .= "/**\n";
|
||||
$this->sMainPHPCode .= " * Portal(s) definition(s) extracted from the XML definition at compile time\n";
|
||||
$this->sMainPHPCode .= " */\n";
|
||||
$this->sMainPHPCode .= "class PortalDispatcherData\n";
|
||||
$this->sMainPHPCode .= "{\n";
|
||||
$this->sMainPHPCode .= "\tprotected static \$aData = ".str_replace("\n", "\n\t", var_export($aPortalsConfig, true)).";\n\n";
|
||||
$this->sMainPHPCode .= "\tprotected static \$aData = ".var_export($aPortalsConfig, true).";\n\n";
|
||||
$this->sMainPHPCode .= "\tpublic static function GetData(\$sPortalId = null)\n";
|
||||
$this->sMainPHPCode .= "\t{\n";
|
||||
$this->sMainPHPCode .= "\t\tif (\$sPortalId === null) return self::\$aData;\n";
|
||||
@@ -1989,11 +2000,42 @@ EOF;
|
||||
$this->sMainPHPCode .= "}\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function SortOnRank($aConf1, $aConf2)
|
||||
{
|
||||
return ($aConf1['rank'] < $aConf2['rank']) ? -1 : 1;
|
||||
}
|
||||
|
||||
protected function CompileParameters($oParametersNode, $sTempTargetDir, $sFinalTargetDir)
|
||||
{
|
||||
if ($oParametersNode)
|
||||
{
|
||||
// Create some static PHP data in <env-xxx>/core/main.php
|
||||
$oParameters = $oParametersNode->GetNodes('parameters');
|
||||
$aParametersConfig = array();
|
||||
foreach($oParameters as $oParams)
|
||||
{
|
||||
$sModuleId = $oParams->getAttribute('id');
|
||||
$oParamsReader = new MFParameters($oParams);
|
||||
$aParametersConfig[$sModuleId] = $oParamsReader->GetAll();
|
||||
}
|
||||
|
||||
$this->sMainPHPCode .= "\n";
|
||||
$this->sMainPHPCode .= "/**\n";
|
||||
$this->sMainPHPCode .= " * Modules parameters extracted from the XML definition at compile time\n";
|
||||
$this->sMainPHPCode .= " */\n";
|
||||
$this->sMainPHPCode .= "class ModulesXMLParameters\n";
|
||||
$this->sMainPHPCode .= "{\n";
|
||||
$this->sMainPHPCode .= "\tprotected static \$aData = ".var_export($aParametersConfig, true).";\n\n";
|
||||
$this->sMainPHPCode .= "\tpublic static function GetData(\$sModuleId = null)\n";
|
||||
$this->sMainPHPCode .= "\t{\n";
|
||||
$this->sMainPHPCode .= "\t\tif (\$sModuleId === null) return self::\$aData;\n";
|
||||
$this->sMainPHPCode .= "\t\tif (!array_key_exists(\$sModuleId, self::\$aData)) return array();\n";
|
||||
$this->sMainPHPCode .= "\t\treturn self::\$aData[\$sModuleId];\n";
|
||||
$this->sMainPHPCode .= "\t}\n";
|
||||
$this->sMainPHPCode .= "}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user