Compiler: reviewed the xml format to facilitate generalization of operations (e.g. compute a delta)

SVN:trunk[1955]
This commit is contained in:
Romain Quetiez
2012-04-15 08:35:31 +00:00
parent b6ac94a8f1
commit 60d63839f6
14 changed files with 9930 additions and 4796 deletions

View File

@@ -141,14 +141,13 @@ EOF;
foreach($oClasses as $oClass)
{
$sClass = $oClass->getAttribute("name");
try
{
$this->CompileClass($oClass, $sResultFile, $sRelativeDir, $oP);
}
catch (ssDOMFormatException $e)
{
$sClass = $oClass->getAttribute("name");
$sClass = $oClass->getAttribute("id");
throw new Exception("Failed to process class '$sClass', from '$sModuleRootDir': ".$e->getMessage());
}
}
@@ -175,9 +174,9 @@ EOF;
$aMenusToLoad = array();
foreach($oMenus as $oMenu)
{
if ($oParent = $this->GetOptionalElement($oMenu, 'parent'))
if ($sParent = $oMenu->GetChildText('parent', null))
{
$aMenusToLoad[] = $oParent->GetAttribute('value');
$aMenusToLoad[] = $sParent;
}
// Note: the order matters: the parents must be defined BEFORE
$aMenusToLoad[] = $oMenu->GetAttribute('id');
@@ -192,7 +191,7 @@ EOF;
}
catch (ssDOMFormatException $e)
{
$sMenu = $oMenu->getAttribute("name");
$sMenu = $oMenu->getAttribute("id");
throw new Exception("Failed to process menu '$sMenu', from '$sModuleRootDir': ".$e->getMessage());
}
}
@@ -260,104 +259,6 @@ EOF;
}
}
/**
* Helper to browse the DOM -could be factorized in ModelFactory
* Returns the node directly under the given node, and that is supposed to be always present and unique
*/
protected function GetUniqueElement($oDOMNode, $sTagName, $bMustExist = true)
{
$oNode = null;
if ($oDOMNode->hasChildNodes())
{
foreach($oDOMNode->childNodes as $oChildNode)
{
if ($oChildNode->nodeName == $sTagName)
{
$oNode = $oChildNode;
break;
}
}
}
if ($bMustExist && is_null($oNode))
{
throw new DOMFormatException('Missing unique tag: '.$sTagName);
}
return $oNode;
}
/**
* Helper to browse the DOM -could be factorized in ModelFactory
* Returns the node directly under the given node, or null is missing
*/
protected function GetOptionalElement($oDOMNode, $sTagName)
{
return $this->GetUniqueElement($oDOMNode, $sTagName, false);
}
/**
* Helper to browse the DOM -could be factorized in ModelFactory
* Returns the TEXT of the given node (possibly from several subnodes)
*/
protected function GetNodeText($oNode)
{
$sText = '';
if ($oNode->hasChildNodes())
{
foreach($oNode->childNodes as $oChildNode)
{
if ($oChildNode instanceof DOMCharacterData) // Base class of DOMText and DOMCdataSection
{
$sText .= $oChildNode->wholeText;
}
}
}
return $sText;
}
/**
* Helper to browse the DOM -could be factorized in ModelFactory
* Assumes the given node to be either a text or
* <items>
* <item [key]="..."]>value<item>
* <item [key]="..."]>value<item>
* </items>
* where value can be the either a text or an array of items... recursively
* Returns a PHP array
*/
protected function GetNodeAsArrayOfItems($oNode)
{
$oItems = $this->GetOptionalElement($oNode, 'items');
if ($oItems)
{
$res = array();
if ($oItems->hasChildNodes())
{
foreach($oItems->childNodes as $oItem)
{
// When an attribute is msising
if ($oItem->hasAttributes() && $oItem->hasAttribute('key'))
{
$key = $oItem->getAttribute('key');
$res[$key] = $this->GetNodeAsArrayOfItems($oItem);
}
else
{
$res[] = $this->GetNodeAsArrayOfItems($oItem);
}
}
}
}
else
{
$res = $this->GetNodeText($oNode);
}
return $res;
}
/**
* Helper to format the flags for an attribute, in a given state
* @param object $oAttNode DOM node containing the information to build the flags
@@ -376,7 +277,7 @@ EOF;
$aFlags = array();
foreach ($aNodeAttributeToFlag as $sNodeAttribute => $sFlag)
{
$bFlag = ($oAttNode->GetAttribute($sNodeAttribute) == '1');
$bFlag = ($oAttNode->GetOptionalElement($sNodeAttribute) != null);
if ($bFlag)
{
$aFlags[] = $sFlag;
@@ -426,22 +327,22 @@ EOF;
protected function CompileClass($oClass, $sResFile, $sModuleRelativeDir, $oP)
{
$sClass = $oClass->getAttribute('name');
$oProperties = $this->GetUniqueElement($oClass, 'properties');
$sClass = $oClass->getAttribute('id');
$oProperties = $oClass->GetUniqueElement('properties');
// Class caracteristics
//
$aClassParams = array();
$aClassParams['category'] = "'".$oClass->getAttribute('category')."'";
$aClassParams['category'] = "'".$oProperties->GetChildText('category')."'";
$aClassParams['key_type'] = "'autoincrement'";
$oNaming = $this->GetUniqueElement($oProperties, 'naming');
$oNameAttributes = $this->GetUniqueElement($oNaming, 'attributes');
$oNaming = $oProperties->GetUniqueElement('naming');
$oNameAttributes = $oNaming->GetUniqueElement('attributes');
$oAttributes = $oNameAttributes->getElementsByTagName('attribute');
$aNameAttCodes = array();
foreach($oAttributes as $oAttribute)
{
$aNameAttCodes[] = $oAttribute->getAttribute('name');
$aNameAttCodes[] = $oAttribute->getAttribute('id');
}
if (count($aNameAttCodes) > 1)
{
@@ -459,10 +360,10 @@ EOF;
}
$aClassParams['name_attcode'] = $sNameAttCode;
$oLifecycle = $this->GetOptionalElement($oClass, 'lifecycle');
$oLifecycle = $oClass->GetOptionalElement('lifecycle');
if ($oLifecycle)
{
$sStateAttCode = $oLifecycle->getAttribute('attribute');
$sStateAttCode = $oLifecycle->GetChildText('attribute');
}
else
{
@@ -470,43 +371,41 @@ EOF;
}
$aClassParams['state_attcode'] = "'$sStateAttCode'";
$oReconciliation = $this->GetUniqueElement($oProperties, 'reconciliation');
$oReconciliation = $oProperties->GetUniqueElement('reconciliation');
$oReconcAttributes = $oReconciliation->getElementsByTagName('attribute');
$aReconcAttCodes = array();
foreach($oReconcAttributes as $oAttribute)
{
$aReconcAttCodes[] = $oAttribute->getAttribute('name');
$aReconcAttCodes[] = $oAttribute->getAttribute('id');
}
$sReconcKeys = "array('".implode("', '", $aReconcAttCodes)."')";
$aClassParams['reconc_keys'] = $sReconcKeys;
$aClassParams['db_table'] = "'".$oClass->getAttribute('db_table')."'";
$aClassParams['db_key_field'] = "'".$oClass->getAttribute('db_key_field')."'";
$aClassParams['db_finalclass_field'] = "'".$oClass->getAttribute('db_final_class_field')."'";
$aClassParams['db_table'] = "'".$oProperties->GetChildText('db_table')."'";
$aClassParams['db_key_field'] = "'".$oProperties->GetChildText('db_key_field')."'";
$aClassParams['db_finalclass_field'] = "'".$oProperties->GetChildText('db_final_class_field')."'";
$oDisplayTemplate = $this->GetOptionalElement($oProperties, 'display_template');
if ($oDisplayTemplate && (strlen($oDisplayTemplate->textContent) > 0))
if (($sDisplayTemplate = $oProperties->GetChildText('display_template')) && (strlen($sDisplayTemplate) > 0))
{
$sDisplayTemplate = $sModuleRelativeDir.'/'.$oDisplayTemplate->textContent;
$sDisplayTemplate = $sModuleRelativeDir.'/'.$sDisplayTemplate;
$aClassParams['display_template'] = "utils::GetAbsoluteUrlModulesRoot().'$sDisplayTemplate'";
}
$oIcon = $this->GetOptionalElement($oProperties, 'icon');
if ($oIcon && (strlen($oIcon->textContent) > 0))
if (($sIcon = $oProperties->GetChildText('icon')) && (strlen($sIcon) > 0))
{
$sIcon = $sModuleRelativeDir.'/'.$oIcon->textContent;
$sIcon = $sModuleRelativeDir.'/'.$sIcon;
$aClassParams['icon'] = "utils::GetAbsoluteUrlModulesRoot().'$sIcon'";
}
$oOrder = $this->GetOptionalElement($oProperties, 'order');
$oOrder = $oProperties->GetOptionalElement('order');
if ($oOrder)
{
$oColumnsNode = $this->GetUniqueElement($oOrder, 'columns');
$oColumnsNode = $oOrder->GetUniqueElement('columns');
$oColumns = $oColumnsNode->getElementsByTagName('column');
$aSortColumns = array();
foreach($oColumns as $oColumn)
{
$aSortColumns[] = "'".$oColumn->getAttribute('name')."' => ".(($oColumn->getAttribute('ascending') == 'true') ? 'true' : 'false');
$aSortColumns[] = "'".$oColumn->getAttribute('id')."' => ".(($oColumn->getAttribute('ascending') == 'true') ? 'true' : 'false');
}
if (count($aSortColumns) > 0)
{
@@ -526,15 +425,7 @@ EOF;
// Comment on top of the class declaration
//
$oComment = $this->GetOptionalElement($oProperties, 'comment');
if ($oComment)
{
$sCodeComment = $oComment->textContent;
}
else
{
$sCodeComment = '';
}
$sCodeComment = $oProperties->GetChildText('comment');
// Fields
//
@@ -542,17 +433,17 @@ EOF;
foreach($this->oFactory->ListFields($oClass) as $oField)
{
// $oField
$sAttCode = $oField->getAttribute('name');
$sAttCode = $oField->getAttribute('id');
$sAttType = $oField->getAttribute('xsi:type');
$aDependencies = array();
$oDependencies = $this->GetOptionalElement($oField, 'dependencies');
$oDependencies = $oField->GetOptionalElement('dependencies');
if (!is_null($oDependencies))
{
$oDepNodes = $oDependencies->getElementsByTagName('attribute');
foreach($oDepNodes as $oDepAttribute)
{
$aDependencies[] = "'".$oDepAttribute->getAttribute('name')."'";
$aDependencies[] = "'".$oDepAttribute->getAttribute('id')."'";
}
}
$sDependencies = 'array('.implode(', ', $aDependencies).')';
@@ -561,31 +452,30 @@ EOF;
if ($sAttType == 'AttributeLinkedSetIndirect')
{
$aParameters['linked_class'] = "'".$oField->getAttribute('linked_class')."'";
$aParameters['ext_key_to_me'] = "'".$oField->getAttribute('ext_key_to_me')."'";
$aParameters['ext_key_to_remote'] = "'".$oField->getAttribute('ext_key_to_remote')."'";
$aParameters['linked_class'] = "'".$oField->GetChildText('linked_class')."'";
$aParameters['ext_key_to_me'] = "'".$oField->GetChildText('ext_key_to_me')."'";
$aParameters['ext_key_to_remote'] = "'".$oField->GetChildText('ext_key_to_remote')."'";
// todo - utile ?
$aParameters['allowed_values'] = 'null';
$aParameters['count_min'] = $oField->getAttribute('count_min');
$aParameters['count_max'] = $oField->getAttribute('count_max');
$aParameters['count_min'] = $oField->GetChildText('count_min');
$aParameters['count_max'] = $oField->GetChildText('count_max');
$aParameters['depends_on'] = $sDependencies;
}
elseif ($sAttType == 'AttributeLinkedSet')
{
$aParameters['linked_class'] = "'".$oField->getAttribute('linked_class')."'";
$aParameters['ext_key_to_me'] = "'".$oField->getAttribute('ext_key_to_me')."'";
$aParameters['linked_class'] = "'".$oField->GetChildText('linked_class')."'";
$aParameters['ext_key_to_me'] = "'".$oField->GetChildText('ext_key_to_me')."'";
// todo - utile ?
$aParameters['allowed_values'] = 'null';
$aParameters['count_min'] = $oField->getAttribute('count_min');
$aParameters['count_max'] = $oField->getAttribute('count_max');
$aParameters['count_min'] = $oField->GetChildText('count_min');
$aParameters['count_max'] = $oField->GetChildText('count_max');
$aParameters['depends_on'] = $sDependencies;
}
elseif ($sAttType == 'AttributeExternalKey')
{
$aParameters['targetclass'] = "'".$oField->getAttribute('target_class')."'";
// todo = v<>rifier l'utilit<EFBFBD>
$aParameters['targetclass'] = "'".$oField->GetChildText('target_class')."'";
$aParameters['jointype'] = 'null';
if (($sOql = $oField->getAttribute('filter')) != '')
if ($sOql = $oField->GetChildText('filter'))
{
$sEscapedOql = addslashes($sOql);
$aParameters['allowed_values'] = "new ValueSetObjects('$sEscapedOql')"; // or "new ValueSetObjects('SELECT xxxx')"
@@ -594,14 +484,14 @@ EOF;
{
$aParameters['allowed_values'] = 'null'; // or "new ValueSetObjects('SELECT xxxx')"
}
$aParameters['sql'] = "'".$oField->getAttribute('sql')."'";
$aParameters['is_null_allowed'] = $oField->getAttribute('is_null_allowed') == 'true' ? 'true' : 'false';
$aParameters['on_target_delete'] = $oField->getAttribute('on_target_delete');
$aParameters['sql'] = "'".$oField->GetChildText('sql')."'";
$aParameters['is_null_allowed'] = $oField->GetChildText('is_null_allowed') == 'true' ? 'true' : 'false';
$aParameters['on_target_delete'] = $oField->GetChildText('on_target_delete');
$aParameters['depends_on'] = $sDependencies;
}
elseif ($sAttType == 'AttributeHierarchicalKey')
{
if (($sOql = $oField->getAttribute('filter')) != '')
if ($sOql = $oField->GetChildText('filter'))
{
$sEscapedOql = addslashes($sOql);
$aParameters['allowed_values'] = "new ValueSetObjects('$sEscapedOql')"; // or "new ValueSetObjects('SELECT xxxx')"
@@ -610,29 +500,29 @@ EOF;
{
$aParameters['allowed_values'] = 'null'; // or "new ValueSetObjects('SELECT xxxx')"
}
$aParameters['sql'] = "'".$oField->getAttribute('sql')."'";
$aParameters['is_null_allowed'] = $oField->getAttribute('is_null_allowed') == 'true' ? 'true' : 'false';
$aParameters['on_target_delete'] = $oField->getAttribute('on_target_delete');
$aParameters['sql'] = "'".$oField->GetChildText('sql')."'";
$aParameters['is_null_allowed'] = $oField->GetChildText('is_null_allowed') == 'true' ? 'true' : 'false';
$aParameters['on_target_delete'] = $oField->GetChildText('on_target_delete');
$aParameters['depends_on'] = $sDependencies;
}
elseif ($sAttType == 'AttributeExternalField')
{
$aParameters['allowed_values'] = 'null';
$aParameters['extkey_attcode'] = "'".$oField->getAttribute('extkey_attcode')."'";
$aParameters['target_attcode'] = "'".$oField->getAttribute('target_attcode')."'";
$aParameters['extkey_attcode'] = "'".$oField->GetChildText('extkey_attcode')."'";
$aParameters['target_attcode'] = "'".$oField->GetChildText('target_attcode')."'";
}
elseif ($sAttType == 'AttributeURL')
{
$aParameters['target'] = "'".$oField->getAttribute('target')."'";
$aParameters['target'] = "'".$oField->GetChildText('target')."'";
$aParameters['allowed_values'] = 'null';
$aParameters['sql'] = "'".$oField->getAttribute('sql')."'";
$aParameters['default_value'] = "'".$oField->getAttribute('default_value')."'";
$aParameters['is_null_allowed'] = $oField->getAttribute('is_null_allowed') == 'true' ? 'true' : 'false';
$aParameters['sql'] = "'".$oField->GetChildText('sql')."'";
$aParameters['default_value'] = "'".$oField->GetChildText('default_value')."'";
$aParameters['is_null_allowed'] = $oField->GetChildText('is_null_allowed') == 'true' ? 'true' : 'false';
$aParameters['depends_on'] = $sDependencies;
}
elseif ($sAttType == 'AttributeEnum')
{
$oValues = $this->GetUniqueElement($oField, 'values');
$oValues = $oField->GetUniqueElement('values');
$oValueNodes = $oValues->getElementsByTagName('value');
$aValues = array();
foreach($oValueNodes as $oValue)
@@ -643,9 +533,9 @@ EOF;
// new style... $sValues = 'array('.implode(', ', $aValues).')';
$sValues = '"'.implode(',', $aValues).'"';
$aParameters['allowed_values'] = "new ValueSetEnum($sValues)";
$aParameters['sql'] = "'".$oField->getAttribute('sql')."'";
$aParameters['default_value'] = "'".$oField->getAttribute('default_value')."'";
$aParameters['is_null_allowed'] = $oField->getAttribute('is_null_allowed') == 'true' ? 'true' : 'false';
$aParameters['sql'] = "'".$oField->GetChildText('sql')."'";
$aParameters['default_value'] = "'".$oField->GetChildText('default_value')."'";
$aParameters['is_null_allowed'] = $oField->GetChildText('is_null_allowed') == 'true' ? 'true' : 'false';
$aParameters['depends_on'] = $sDependencies;
}
elseif ($sAttType == 'AttributeBlob')
@@ -655,12 +545,12 @@ EOF;
else
{
$aParameters['allowed_values'] = 'null'; // or "new ValueSetEnum('SELECT xxxx')"
$aParameters['sql'] = "'".$oField->getAttribute('sql')."'";
$aParameters['default_value'] = "'".$oField->getAttribute('default_value')."'";
$aParameters['is_null_allowed'] = $oField->getAttribute('is_null_allowed') == 'true' ? 'true' : 'false';
$aParameters['sql'] = "'".$oField->GetChildText('sql')."'";
$aParameters['default_value'] = "'".$oField->GetChildText('default_value')."'";
$aParameters['is_null_allowed'] = $oField->GetChildText('is_null_allowed') == 'true' ? 'true' : 'false';
$aParameters['depends_on'] = $sDependencies;
if ($sValidationPattern = $oField->getAttribute('validation_pattern'))
if ($sValidationPattern = $oField->GetChildText('validation_pattern'))
{
$aParameters['validation_pattern'] = '"'.addslashes($sValidationPattern).'"';
}
@@ -683,19 +573,19 @@ EOF;
$sLifecycle .= "\t\t// Lifecycle (status attribute: $sStateAttCode)\n";
$sLifecycle .= "\t\t//\n";
$oStimuli = $this->GetUniqueElement($oLifecycle, 'stimuli');
$oStimuli = $oLifecycle->GetUniqueElement('stimuli');
foreach ($oStimuli->getElementsByTagName('stimulus') as $oStimulus)
{
$sStimulus = $oStimulus->getAttribute('name');
$sStimulusClass = $oStimulus->getAttribute('type');
$sStimulus = $oStimulus->getAttribute('id');
$sStimulusClass = $oStimulus->getAttribute('xsi:type');
$sLifecycle .= " MetaModel::Init_DefineStimulus(new ".$sStimulusClass."(\"".$sStimulus."\", array()));\n";
}
$oStates = $this->GetUniqueElement($oLifecycle, 'states');
$oStates = $oLifecycle->GetUniqueElement('states');
foreach ($oStates->getElementsByTagName('state') as $oState)
{
$sState = $oState->getAttribute('name');
$sState = $oState->getAttribute('id');
$sLifecycle .= " MetaModel::Init_DefineState(\n";
$sLifecycle .= " \"".$sState."\",\n";
@@ -703,13 +593,13 @@ EOF;
$sLifecycle .= " \"attribute_inherit\" => '',\n";
$sLifecycle .= " \"attribute_list\" => array(\n";
$oFlags = $this->GetUniqueElement($oState, 'flags');
$oFlags = $oState->GetUniqueElement('flags');
foreach ($oFlags->getElementsByTagName('attribute') as $oAttributeNode)
{
$sFlags = $this->FlagsToPHP($oAttributeNode);
if (strlen($sFlags) > 0)
{
$sAttCode = $oAttributeNode->GetAttribute('name');
$sAttCode = $oAttributeNode->GetAttribute('id');
$sLifecycle .= " '$sAttCode' => $sFlags,\n";
}
}
@@ -718,17 +608,17 @@ EOF;
$sLifecycle .= " )\n";
$sLifecycle .= " );\n";
$oTransitions = $this->GetUniqueElement($oState, 'transitions');
$oTransitions = $oState->GetUniqueElement('transitions');
foreach ($oTransitions->getElementsByTagName('transition') as $oTransition)
{
$sStimulus = $oTransition->getAttribute('stimulus');
$sTargetState = $oTransition->getAttribute('target');
$sStimulus = $oTransition->GetChildText('stimulus');
$sTargetState = $oTransition->GetChildText('target');
$oActions = $this->GetUniqueElement($oTransition, 'actions');
$oActions = $oTransition->GetUniqueElement('actions');
$aVerbs = array();
foreach ($oActions->getElementsByTagName('action') as $oAction)
{
$sVerb = $oAction->getAttribute('verb');
$sVerb = $oAction->GetChildText('verb');
$aVerbs[] = "'$sVerb'";
}
$sActions = implode(', ', $aVerbs);
@@ -745,14 +635,14 @@ EOF;
'list' => 'list'
);
$oPresentation = $this->GetUniqueElement($oClass, 'presentation');
$oPresentation = $oClass->GetUniqueElement('presentation');
$sZlists = '';
foreach ($aListRef as $sListCode => $sListTag)
{
$oListNode = $this->GetOptionalElement($oPresentation, $sListTag);
$oListNode = $oPresentation->GetOptionalElement($sListTag);
if ($oListNode)
{
$aAttributes = $this->GetNodeAsArrayOfItems($oListNode);
$aAttributes = $oListNode->GetNodeAsArrayOfItems();
$sZAttributes = var_export($aAttributes, true);
$sZlists .= " MetaModel::Init_SetZListItems('$sListCode', $sZAttributes);\n";
@@ -761,14 +651,13 @@ EOF;
// Methods
$sMethods = "";
$oMethods = $this->GetUniqueElement($oClass, 'methods');
$oMethods = $oClass->GetUniqueElement('methods');
foreach($oMethods->getElementsByTagName('method') as $oMethod)
{
$sMethodCode = $this->GetNodeText($oMethod);
$oMethodComment = $this->GetOptionalElement($oMethod, 'comment');
if ($oMethodComment)
$sMethodCode = $oMethod->GetChildText('code');
if ($sMethodComment = $oMethod->GetChildText('comment', null))
{
$sMethods .= "\n\t".$oMethodComment->textContent."\n".$sMethodCode."\n";
$sMethods .= "\n\t$sMethodComment\n".$sMethodCode."\n";
}
else
{
@@ -779,15 +668,15 @@ EOF;
// Let's make the whole class declaration
//
$sPHP = "\n\n$sCodeComment\n";
if ($oClass->getAttribute('abstract') == 'true')
if ($oProperties->GetChildText('abstract') == 'true')
{
$sPHP .= 'abstract class '.$oClass->getAttribute('name');
$sPHP .= 'abstract class '.$oClass->getAttribute('id');
}
else
{
$sPHP .= 'class '.$oClass->getAttribute('name');
$sPHP .= 'class '.$oClass->getAttribute('id');
}
$sPHP .= " extends ".$oClass->getAttribute('parent')."\n";
$sPHP .= " extends ".$oClass->GetUniqueElement('properties')->GetChildText('parent', 'DBObject')."\n";
$sPHP .=
<<<EOF
{
@@ -816,10 +705,9 @@ EOF;
$sMenuId = $oMenu->getAttribute("id");
$sMenuClass = $oMenu->getAttribute("xsi:type");
$oParent = $this->GetOptionalElement($oMenu, 'parent');
if ($oParent)
$sParent = $oMenu->GetChildText('parent', null);
if ($sParent)
{
$sParent = $oParent->GetAttribute('value');
$sParentSpec = "\$__comp_menus__['$sParent']->GetIndex()";
}
else
@@ -827,45 +715,44 @@ EOF;
$sParentSpec = '-1';
}
$fRank = $this->GetUniqueElement($oMenu, 'rank')->GetAttribute('value');
$fRank = $oMenu->GetChildText('rank');
switch($sMenuClass)
{
case 'WebPageMenuNode':
$sUrl = $this->GetUniqueElement($oMenu, 'url')->GetAttribute('value');
$sUrl = $oMenu->GetChildText('url');
$sUrlSpec = $this->PathToPHP($sUrl, $sModuleRelativeDir, true /* Url */);
$sNewMenu = "new WebPageMenuNode('$sMenuId', $sUrlSpec, $sParentSpec, $fRank);";
break;
case 'TemplateMenuNode':
$sTemplateFile = $this->GetUniqueElement($oMenu, 'template_file')->GetAttribute('value');
$sTemplateFile = $oMenu->GetChildText('template_file');
$sTemplateSpec = $this->PathToPHP($sTemplateFile, $sModuleRelativeDir);
$sNewMenu = "new TemplateMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank);";
break;
case 'OQLMenuNode':
$sOQL = $this->GetUniqueElement($oMenu, 'oql')->GetAttribute('value');
$bSearch = ($this->GetUniqueElement($oMenu, 'do_search')->GetAttribute('value') == '1') ? 'true' : 'false';
$sOQL = $oMenu->GetChildText('oql');
$bSearch = ($oMenu->GetChildText('do_search') == '1') ? 'true' : 'false';
$sNewMenu = "new OQLMenuNode('$sMenuId', '$sOQL', $sParentSpec, $fRank, $bSearch);";
break;
case 'NewObjectMenuNode':
$sClass = $this->GetUniqueElement($oMenu, 'class')->GetAttribute('value');
$sClass = $oMenu->GetChildText('class');
$sNewMenu = "new NewObjectMenuNode('$sMenuId', '$sClass', $sParentSpec, $fRank);";
break;
case 'SearchMenuNode':
$sClass = $this->GetUniqueElement($oMenu, 'class')->GetAttribute('value');
$sClass = $oMenu->GetChildText('class');
$sNewMenu = "new SearchMenuNode('$sMenuId', '$sClass', $sParentSpec, $fRank);";
break;
case 'MenuGroup':
default:
if ($oEnableClass = $this->GetOptionalElement($oMenu, 'enable_class'))
if ($sEnableClass = $oMenu->GetChildText('enable_class'))
{
$sEnableClass = $oEnableClass->GetAttribute('value');
$sEnableAction = $this->GetUniqueElement($oMenu, 'enable_action')->GetAttribute('value');
$sEnablePermission = $this->GetUniqueElement($oMenu, 'enable_permission')->GetAttribute('value');
$sEnableStimulus = $this->GetUniqueElement($oMenu, 'enable_stimulus')->GetAttribute('value');
$sEnableAction = $oMenu->GetChildText('enable_action');
$sEnablePermission = $oMenu->GetChildText('enable_permission');
$sEnableStimulus = $oMenu->GetChildText('enable_stimulus');
if (strlen($sEnableStimulus) > 0)
{
$sNewMenu = "new MenuGroup('$sMenuId', $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission, '$sEnableStimulus');";
@@ -884,14 +771,14 @@ EOF;
$sIndent = '';
$aPHPMenu = array("\$__comp_menus__['$sMenuId'] = $sNewMenu");
if ($oAutoReload = $this->GetOptionalElement($oMenu, 'auto_reload'))
if ($sAutoReload = $oMenu->GetChildText('auto_reload'))
{
$sAutoReload = addslashes($oAutoReload->GetAttribute("value"));
$sAutoReload = addslashes($sAutoReload);
$aPHPMenu[] = "\$__comp_menus__['$sMenuId']->SetParameters(array('auto_reload' => '$sAutoReload'));";
}
$oAdminOnly = $this->GetOptionalElement($oMenu, 'enable_admin_only');
if ($oAdminOnly && $oAdminOnly->GetAttribute('value') == '1')
$sAdminOnly = $oMenu->GetChildText('enable_admin_only');
if ($sAdminOnly && ($sAdminOnly == '1'))
{
$sPHP = $sIndent."if (UserRights::IsAdministrator())\n";
$sPHP .= $sIndent."{\n";

View File

@@ -15,12 +15,20 @@
<xsd:complexType>
<xsd:sequence>
<xsd:element name="comment" type="xsd:string" minOccurs="0"/>
<xsd:element name="is_link" type="xsd:string" minOccurs="0"/>
<xsd:element name="category" type="xsd:string"/>
<xsd:element name="parent" type="xsd:string"/>
<xsd:element name="abstract" type="xsd:string"/>
<xsd:element name="key_type" type="xsd:string"/>
<xsd:element name="db_table" type="xsd:string"/>
<xsd:element name="db_key_field" type="xsd:string"/>
<xsd:element name="db_final_class_field" type="xsd:string"/>
<xsd:element name="naming">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="format" type="xsd:string"/>
<xsd:element name="attributes" type="ListOfAttributes"/>
</xsd:sequence>
<xsd:attribute name="format" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="display_template" type="xsd:string"/>
@@ -40,8 +48,11 @@
<xsd:sequence>
<xsd:element name="column">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="ascending" type="xsd:string"/>
<xsd:sequence>
<xsd:element name="ascending" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string" use="required"/>
<xsd:attribute name="order" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
@@ -64,15 +75,12 @@
<xsd:complexType>
<xsd:sequence>
<xsd:element name="attribute" type="xsd:string"/>
<xsd:element name="stimuli">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="stimulus" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="stimulus" type="Stimulus" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
@@ -88,12 +96,14 @@
<xsd:sequence>
<xsd:element name="attribute" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="mandatory" type="xsd:string"/>
<xsd:attribute name="must_prompt" type="xsd:string"/>
<xsd:attribute name="must_change" type="xsd:string"/>
<xsd:attribute name="hidden" type="xsd:string"/>
<xsd:attribute name="read_only" type="xsd:string"/>
<xsd:sequence>
<xsd:element name="mandatory" type="xsd:string" minOccurs="0"/>
<xsd:element name="must_prompt" type="xsd:string" minOccurs="0"/>
<xsd:element name="must_change" type="xsd:string" minOccurs="0"/>
<xsd:element name="hidden" type="xsd:string" minOccurs="0"/>
<xsd:element name="read_only" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
@@ -106,27 +116,29 @@
<xsd:element name="transition" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="stimulus" type="xsd:string"/>
<xsd:element name="target" type="xsd:string"/>
<xsd:element name="actions">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="action" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="verb" type="xsd:string"/>
<xsd:sequence>
<xsd:element name="verb" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="stimulus" type="xsd:string"/>
<xsd:attribute name="target" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="id" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
@@ -134,7 +146,6 @@
</xsd:element>
</xsd:sequence>
<xsd:attribute name="attribute" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="methods">
@@ -144,11 +155,12 @@
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element name="comment" type="xsd:string" minOccurs="0"/>
<xsd:element name="static" type="xsd:string"/>
<xsd:element name="access" type="xsd:string"/>
<xsd:element name="type" type="xsd:string"/>
<xsd:element name="code" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="static" type="xsd:string"/>
<xsd:attribute name="access" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string"/>
<xsd:attribute name="id" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
@@ -164,15 +176,7 @@
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="category" type="xsd:string"/>
<xsd:attribute name="parent" type="xsd:string"/>
<xsd:attribute name="abstract" type="xsd:string"/>
<xsd:attribute name="key_type" type="xsd:string"/>
<xsd:attribute name="is_link" type="xsd:string"/>
<xsd:attribute name="db_table" type="xsd:string"/>
<xsd:attribute name="db_key_field" type="xsd:string"/>
<xsd:attribute name="db_final_class_field" type="xsd:string"/>
<xsd:attribute name="id" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
@@ -195,7 +199,7 @@
<!-- ====================================== -->
<!-- Types for the classes -->
<!-- Class: Atttributes -->
<!-- ====================================== -->
<xsd:complexType name="ListOfAttributes">
<xsd:sequence>
@@ -206,23 +210,37 @@
<xsd:complexType name="Attribute">
<xsd:sequence>
<xsd:element name="filter" type="xsd:string" minOccurs="0"/>
<xsd:element name="values" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="dependencies" type="ListOfAttributes" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="id" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="AttributeSql">
<xsd:complexContent>
<xsd:extension base="Attribute">
<xsd:attribute name="sql" type="xsd:string"/>
<xsd:attribute name="is_null_allowed" type="xsd:string"/>
<xsd:sequence>
<xsd:element name="sql" type="xsd:string"/>
<xsd:element name="default_value" type="xsd:string"/>
<xsd:element name="is_null_allowed" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="AttributeBlob">
<xsd:complexContent>
<xsd:extension base="AttributeSql">
<xsd:extension base="Attribute">
<xsd:sequence>
<xsd:element name="is_null_allowed" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -230,7 +248,8 @@
<xsd:complexType name="AttributeScalar">
<xsd:complexContent>
<xsd:extension base="AttributeSql">
<xsd:attribute name="default_value" type="xsd:string"/>
<xsd:sequence>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -288,7 +307,9 @@
<xsd:complexType name="AttributeURL">
<xsd:complexContent>
<xsd:extension base="AttributeString">
<xsd:attribute name="target" type="xsd:string"/>
<xsd:sequence>
<xsd:element name="target" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -303,25 +324,6 @@
<xsd:complexType name="AttributeEnum">
<xsd:complexContent>
<xsd:extension base="AttributeString">
<xsd:sequence>
<xsd:element name="values">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="AttributeExternalKeyBase">
<xsd:complexContent>
<xsd:extension base="AttributeSql">
<xsd:attribute name="filter" type="xsd:string"/>
<xsd:attribute name="on_target_delete" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -329,25 +331,39 @@
<xsd:complexType name="AttributeExternalKey">
<xsd:complexContent>
<xsd:extension base="AttributeExternalKeyBase">
<xsd:attribute name="target_class" type="xsd:string"/>
<xsd:attribute name="jointype" type="xsd:string"/>
<xsd:extension base="Attribute">
<xsd:sequence>
<xsd:element name="sql" type="xsd:string"/>
<xsd:element name="target_class" type="xsd:string"/>
<xsd:element name="is_null_allowed" type="xsd:string"/>
<xsd:element name="filter" type="xsd:string" minOccurs="0"/>
<xsd:element name="on_target_delete" type="xsd:string"/>
<xsd:element name="jointype" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="AttributeHierarchicalKey">
<xsd:complexContent>
<xsd:extension base="AttributeExternalKeyBase">
<xsd:extension base="Attribute">
<xsd:sequence>
<xsd:element name="sql" type="xsd:string"/>
<xsd:element name="is_null_allowed" type="xsd:string"/>
<xsd:element name="on_target_delete" type="xsd:string"/>
<xsd:element name="filter" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="AttributeExternalField">
<xsd:complexContent>
<xsd:extension base="AttributeSql">
<xsd:attribute name="extkey_attcode" type="xsd:string"/>
<xsd:attribute name="target_attcode" type="xsd:string"/>
<xsd:extension base="Attribute">
<xsd:sequence>
<xsd:element name="extkey_attcode" type="xsd:string"/>
<xsd:element name="target_attcode" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -362,10 +378,12 @@
<xsd:complexType name="AttributeLinkedSet">
<xsd:complexContent>
<xsd:extension base="Attribute">
<xsd:attribute name="linked_class" type="xsd:string"/>
<xsd:attribute name="ext_key_to_me" type="xsd:string"/>
<xsd:attribute name="count_min" type="xsd:integer"/>
<xsd:attribute name="count_max" type="xsd:integer"/>
<xsd:sequence>
<xsd:element name="linked_class" type="xsd:string"/>
<xsd:element name="ext_key_to_me" type="xsd:string"/>
<xsd:element name="count_min" type="xsd:string"/>
<xsd:element name="count_max" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -373,11 +391,18 @@
<xsd:complexType name="AttributeLinkedSetIndirect">
<xsd:complexContent>
<xsd:extension base="AttributeLinkedSet">
<xsd:sequence>
<xsd:element name="ext_key_to_remote" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="ext_key_to_remote" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<!-- ====================================== -->
<!-- Class: ZList (presentation) -->
<!-- ====================================== -->
<xsd:complexType name="ItemList">
<xsd:sequence>
<xsd:element name="items" type="Items" minOccurs="0"/>
@@ -392,12 +417,34 @@
<xsd:sequence>
<xsd:element name="items" type="Items" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="key" type="xsd:string"/>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<!-- ====================================== -->
<!-- Class: Stimulus -->
<!-- ====================================== -->
<xsd:complexType name="Stimulus">
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="StimulusUserAction">
<xsd:complexContent>
<xsd:extension base="Stimulus">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="StimulusInternal">
<xsd:complexContent>
<xsd:extension base="Stimulus">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<!-- ====================================== -->
<!-- Types for the menus -->
@@ -486,7 +533,10 @@
</xsd:complexType>
<xsd:complexType name="MenuProperty">
<xsd:attribute name="value" type="xsd:string"/>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:simpleType name="MenuType">

View File

@@ -284,6 +284,7 @@ class ModelFactory
{
$this->sRootDir = $sRootDir;
$this->oDOMDocument = new DOMDocument('1.0', 'UTF-8');
$this->oDOMDocument->registerNodeClass('DOMElement', 'MFDOMElement');
$this->oRoot = $this->oDOMDocument->CreateElement('itop_design');
$this->oDOMDocument->AppendChild($this->oRoot);
$this->oClasses = $this->oDOMDocument->CreateElement('classes');
@@ -319,6 +320,7 @@ class ModelFactory
foreach($aDataModels as $sXmlFile)
{
$oDocument = new DOMDocument('1.0', 'UTF-8');
$oDocument->registerNodeClass('DOMElement', 'MFDOMElement');
libxml_clear_errors();
$oDocument->load($sXmlFile, LIBXML_NOBLANKS);
$bValidated = $oDocument->schemaValidate(APPROOT.'setup/itop_design.xsd');
@@ -326,6 +328,7 @@ class ModelFactory
if (count($aErrors) > 0)
{
self::$aLoadErrors[$sModuleName] = $aErrors;
return;
}
$oXPath = new DOMXPath($oDocument);
@@ -338,15 +341,8 @@ class ModelFactory
$oNodeList = $oXPath->query('/itop_design/classes/class');
foreach($oNodeList as $oNode)
{
if ($oNode->hasAttribute('parent'))
{
$sParentClass = $oNode->GetAttribute('parent');
}
else
{
$sParentClass = '';
}
$sClassName = $oNode->GetAttribute('name');
$sParentClass = $oNode->GetUniqueElement('properties')->GetChildText('parent', '');
$sClassName = $oNode->GetAttribute('id');
$aClasses[$sClassName] = array('name' => $sClassName, 'parent' => $sParentClass, 'node' => $oNode);
}
@@ -474,9 +470,9 @@ class ModelFactory
*/
protected function ClassExists(DOMNode $oClassNode)
{
if ($oClassNode->hasAttribute('name'))
if ($oClassNode->hasAttribute('id'))
{
$sClassName = $oClassNode->GetAttribute('name');
$sClassName = $oClassNode->GetAttribute('id');
}
else
{
@@ -504,9 +500,9 @@ class ModelFactory
*/
public function AddClass(DOMNode $oClassNode, $sModuleName)
{
if ($oClassNode->hasAttribute('name'))
if ($oClassNode->hasAttribute('id'))
{
$sClassName = $oClassNode->GetAttribute('name');
$sClassName = $oClassNode->GetAttribute('id');
}
else
{
@@ -517,11 +513,7 @@ class ModelFactory
throw new Exception("ModelFactory::AddClass: Cannot add the already existing class $sClassName");
}
$sParentClass = '';
if ($oClassNode->hasAttribute('parent'))
{
$sParentClass = $oClassNode->GetAttribute('parent');
}
$sParentClass = $oClassNode->GetUniqueElement('properties')->GetChildText('parent', '');
//echo "Adding class: $sClassName, parent: $sParentClass<br/>";
if (!in_array($sParentClass, self::$aWellKnownParents) && $this->ClassNameExists($sParentClass))
@@ -549,7 +541,7 @@ class ModelFactory
}
else
{
throw new Exception("ModelFactory::AddClass: Cannot add the class $sClassName, unknown parent class: $sParentClass");
throw new Exception("ModelFactory::AddClass: Cannot add the class $sClassName, unknown parent class: $sParentClass (loaded classes: ".implode(', ', array_keys(self::$aLoadedClasses)).")");
}
}
@@ -605,7 +597,7 @@ class ModelFactory
}
}
$this->_priv_AlterNode($oDestNode, $oClassNode);
$sClassName = $oDestNode->getAttribute('name');
$sClassName = $oDestNode->getAttribute('id');
if ($sOriginalName != $sClassName)
{
unset(self::$aLoadedClasses[$sOriginalName]);
@@ -711,10 +703,10 @@ class ModelFactory
{
$sOperation = $oChildNode->getAttribute('_operation');
$sPath = $oChildNode->tagName;
$sName = $oChildNode->getAttribute('name');
$sName = $oChildNode->getAttribute('id');
if ($sName != '')
{
$sPath .= "[@name='$sName']";
$sPath .= "[@id='$sName']";
}
switch($sOperation)
{
@@ -762,15 +754,17 @@ class ModelFactory
return
<<<EOF
<?xml version="1.0" encoding="utf-8"?>
<class name="$sName" parent="" db_table="" category="" abstract="" key_type="autoincrement" db_key_field="id" db_final_class_field="finalclass">
<properties>
<class id="$sName">
<comment/>
<properties>
</properties>
<naming format=""><attributes/></naming>
<reconciliation><attributes/></reconciliation>
<display_template/>
<icon>$sIcon</icon>
</properties>
<fields/>
<lifecycle/>
<methods/>
<presentation>
<details><items/></details>
@@ -857,15 +851,15 @@ EOF
$oClassNode = null;
}
}
$sXPath = "fields/field[@name='$sAttCode']";
$sXPath = "fields/field[@id='$sAttCode']";
if ($bFlattenLayers)
{
$sXPath = "fields/field[(@name='$sAttCode' and (not(@_operation) or @_operation!='removed'))]";
$sXPath = "fields/field[(@id='$sAttCode' and (not(@_operation) or @_operation!='removed'))]";
}
$oFieldNode = $this->_priv_GetNodes($sXPath, $oClassNode)->item(0);
if (($oFieldNode == null) && ($oClassNode->getAttribute('parent') != ''))
if (($oFieldNode == null) && ($sParentClass = $oClassNode->GetUniqueElement('properties')->GetChildText('parent')))
{
return $this->GetField($oClassNode->getAttribute('parent'), $sAttCode, $bFlattenLayers);
return $this->GetField($sParentClass, $sAttCode, $bFlattenLayers);
}
return $oFieldNode;
}
@@ -888,7 +882,7 @@ EOF
public function AddField(DOMNode $oClassNode, $sFieldCode, $sFieldType, $sSQL, $defaultValue, $bIsNullAllowed, $aExtraParams)
{
$oNewField = $this->oDOMDocument->createElement('field');
$oNewField->setAttribute('name', $sFieldCode);
$oNewField->setAttribute('id', $sFieldCode);
$this->_priv_AlterField($oNewField, $sFieldType, $sSQL, $defaultValue, $bIsNullAllowed, $aExtraParams);
$oFields = $oClassNode->getElementsByTagName('fields')->item(0);
$oFields->AppendChild($oNewField);
@@ -897,7 +891,7 @@ EOF
public function RemoveField(DOMNode $oClassNode, $sFieldCode)
{
$sXPath = "fields/field[@name='$sFieldCode']";
$sXPath = "fields/field[@id='$sFieldCode']";
$oFieldNodes = $this->_priv_GetNodes($sXPath, $oClassNode);
if (is_object($oFieldNodes) && (is_object($oFieldNodes->item(0))))
{
@@ -916,7 +910,7 @@ EOF
public function AlterField(DOMNode $oClassNode, $sFieldCode, $sFieldType, $sSQL, $defaultValue, $bIsNullAllowed, $aExtraParams)
{
$sXPath = "fields/field[@name='$sFieldCode']";
$sXPath = "fields/field[@id='$sFieldCode']";
$oFieldNodes = $this->_priv_GetNodes($sXPath, $oClassNode);
if (is_object($oFieldNodes) && (is_object($oFieldNodes->item(0))))
{
@@ -1031,7 +1025,7 @@ EOF
foreach($aDeps as $sAttCode)
{
$oDep = $this->oDOMDocument->createElement('attribute');
$oDep->setAttribute('name', $sAttCode);
$oDep->setAttribute('id', $sAttCode);
$oDependencies->addChild($oDep);
}
$oFieldNode->addChild($oDependencies);
@@ -1225,7 +1219,7 @@ EOF
case 'removed':
// marked as deleted, let's remove the node from the tree
$oParent = $oClassNode->parentNode;
$sClass = $oClassNode->GetAttribute('name');
$sClass = $oClassNode->GetAttribute('id');
echo "Calling removeChild...<br/>";
$oParent->removeChild($oClassNode);
unset(self::$aLoadedClasses[$sClass]);
@@ -1246,6 +1240,7 @@ EOF
public function GetDelta()
{
$oDelta = new DOMDocument('1.0', 'UTF-8');
$oDelta->registerNodeClass('DOMElement', 'MFDOMElement');
$oRootNode = $oDelta->createElement('itop_design');
$oDelta->appendChild($oRootNode);
$oClasses = $oDelta->createElement('classes');
@@ -1272,7 +1267,7 @@ EOF
}
else
{
$sName = $oChildNode->getAttribute('name');;
$sName = $oChildNode->getAttribute('id');;
$sOperation = $oChildNode->getAttribute('_operation');
}
@@ -1292,18 +1287,18 @@ echo str_repeat('+', $iDepth)." $sNodeName [$sName], operation: $sOperation\n";
{
$oDestNode->appendChild($oDeletedNode);
}
echo "<p>".str_repeat('+', $iDepth).$oChildNode->getAttribute('name')." was removed...</p>";
echo "<p>".str_repeat('+', $iDepth).$oChildNode->getAttribute('id')." was removed...</p>";
break;
case 'added':
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('name')." was created...</p>";
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('id')." was created...</p>";
$oModifiedNode = $oDoc->importNode($oChildNode, true); // Copies all the node's attributes, and the child nodes as well
if ($oChildNode instanceof DOMElement)
{
$oModifiedNode->removeAttribute('_source');
if ($oModifiedNode->tagName == 'class')
{
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('name')." inserting under 'classes'...</p>";
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('id')." inserting under 'classes'...</p>";
// classes are always located under the root node
$oDoc->firstChild->appendChild($oModifiedNode);
@@ -1322,7 +1317,7 @@ echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAtt
}
else
{
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('name')." inserting in the hierarchy...</p>";
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('id')." inserting in the hierarchy...</p>";
$oDestNode->appendChild($oModifiedNode);
}
}
@@ -1333,7 +1328,7 @@ echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAtt
break;
case 'replaced':
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('name')." was replaced...</p>";
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('id')." was replaced...</p>";
$oModifiedNode = $oDoc->importNode($oChildNode, true); // Copies all the node's attributes, and the child nodes as well
if ($oChildNode instanceof DOMElement)
{
@@ -1343,7 +1338,7 @@ echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAtt
break;
case 'modified':
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('name')." was modified...</p>";
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('id')." was modified...</p>";
if ($oChildNode instanceof DOMElement)
{
echo str_repeat('+', $iDepth)." Copying (NON recursively) the modified node\n";
@@ -1370,11 +1365,11 @@ echo str_repeat('+', $iDepth)." Copying (recursively) the modified node\n";
default:
// No change: do nothing
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('name')." was NOT modified...</p>";
echo "<p>".str_repeat('+', $iDepth).$oChildNode->tagName.':'.$oChildNode->getAttribute('id')." was NOT modified...</p>";
$oModifiedNode = $oDoc->importNode($oChildNode, true); // Importing the node for future recusrsion if needed
if ($oChildNode->tagName == 'class')
{
echo "<p>".str_repeat('+', $iDepth)."Checking if a subclass of ".$oChildNode->getAttribute('name')." was modified...</p>";
echo "<p>".str_repeat('+', $iDepth)."Checking if a subclass of ".$oChildNode->getAttribute('id')." was modified...</p>";
// classes are always located under the root node
$this->_priv_ImportModifiedChildren($oDoc, $oModifiedNode, $oChildNode);
}
@@ -1454,15 +1449,22 @@ echo "<p>".str_repeat('+', $iDepth)."Checking if a subclass of ".$oChildNode->ge
public function _priv_SetNodeAttribute(DOMNode $oNode, $sAttributeName, $atttribueValue)
{
}
}
/**
* MFDOMElement: helper to read the information from the DOM
* @package ModelFactory
*/
class MFDOMElement extends DOMElement
{
/**
* Helper to browse the DOM -could be factorized in ModelFactory
* Returns the node directly under the given node, and that is supposed to be always present and unique
* Returns the node directly under the given node
*/
protected function GetUniqueElement($oDOMNode, $sTagName, $bMustExist = true)
public function GetUniqueElement($sTagName, $bMustExist = true)
{
$oNode = null;
foreach($oDOMNode->childNodes as $oChildNode)
foreach($this->childNodes as $oChildNode)
{
if ($oChildNode->nodeName == $sTagName)
{
@@ -1478,35 +1480,53 @@ echo "<p>".str_repeat('+', $iDepth)."Checking if a subclass of ".$oChildNode->ge
}
/**
* Helper to browse the DOM -could be factorized in ModelFactory
* Returns the node directly under the given node, or null is missing
* Returns the node directly under the current node, or null if missing
*/
protected function GetOptionalElement($oDOMNode, $sTagName)
public function GetOptionalElement($sTagName)
{
return $this->GetUniqueElement($oDOMNode, $sTagName, false);
return $this->GetUniqueElement($sTagName, false);
}
/**
* Helper to browse the DOM -could be factorized in ModelFactory
* Returns the TEXT of the given node (possibly from several subnodes)
* Returns the TEXT of the current node (possibly from several subnodes)
*/
protected function GetNodeText($oNode)
public function GetText($sDefault = null)
{
$sText = '';
foreach($oNode->childNodes as $oChildNode)
$sText = null;
foreach($this->childNodes as $oChildNode)
{
if ($oChildNode instanceof DOMCharacterData) // Base class of DOMText and DOMCdataSection
{
if (is_null($sText)) $sText = '';
$sText .= $oChildNode->wholeText;
}
}
return $sText;
if (is_null($sText))
{
return $sDefault;
}
else
{
return $sText;
}
}
/**
* Helper to browse the DOM -could be factorized in ModelFactory
* Assumes the given node to be either a text or
* Get the TEXT value from the child node
*/
public function GetChildText($sTagName, $sDefault = null)
{
$sRet = $sDefault;
if ($oChild = $this->GetOptionalElement($sTagName))
{
$sRet = $oChild->GetText($sDefault);
}
return $sRet;
}
/**
* Assumes the current node to be either a text or
* <items>
* <item [key]="..."]>value<item>
* <item [key]="..."]>value<item>
@@ -1514,31 +1534,30 @@ echo "<p>".str_repeat('+', $iDepth)."Checking if a subclass of ".$oChildNode->ge
* where value can be the either a text or an array of items... recursively
* Returns a PHP array
*/
public function GetNodeAsArrayOfItems($oNode)
public function GetNodeAsArrayOfItems()
{
$oItems = $this->GetOptionalElement($oNode, 'items');
$oItems = $this->GetOptionalElement('items');
if ($oItems)
{
$res = array();
foreach($oItems->childNodes as $oItem)
{
// When an attribute is missing
if ($oItem->hasAttribute('key'))
if ($oItem->hasAttribute('id'))
{
$key = $oItem->getAttribute('key');
$res[$key] = $this->GetNodeAsArrayOfItems($oItem);
$key = $oItem->getAttribute('id');
$res[$key] = $oItem->GetNodeAsArrayOfItems();
}
else
{
$res[] = $this->GetNodeAsArrayOfItems($oItem);
$res[] = $oItem->GetNodeAsArrayOfItems();
}
}
}
else
{
$res = $this->GetNodeText($oNode);
$res = $this->GetText();
}
return $res;
}
}