XML Modelization of the relations: no option to restrict the browsing to downstream

SVN:trunk[3556]
This commit is contained in:
Romain Quetiez
2015-04-23 10:11:33 +00:00
parent 7c210f4d1c
commit fa333504c6
6 changed files with 79 additions and 51 deletions

View File

@@ -1183,11 +1183,11 @@ abstract class MetaModel
{
if ($bDown)
{
// The legacy convention is confusing with regard to the way we have conceptualized the relations:
// In the former representation, the main stream was named after "up"
// Now, the relation from A to B says that something is transmitted from A to B, thus going DOWNstream as described in a petri net.
$sKey = "Relation:$sRelCode/DownStream";
$sLegacy = Dict::S("Relation:$sRelCode/VerbUp", $sKey);
// The legacy convention is confusing with regard to the way we have conceptualized the relations:
// In the former representation, the main stream was named after "up"
// Now, the relation from A to B says that something is transmitted from A to B, thus going DOWNstream as described in a petri net.
$sKey = "Relation:$sRelCode/DownStream";
$sLegacy = Dict::S("Relation:$sRelCode/VerbUp", $sKey);
}
else
{
@@ -1265,17 +1265,25 @@ abstract class MetaModel
throw new Exception("Wrong definition for the relation $sRelCode/{$aNeighbourData['sDefinedInClass']}/{$aNeighbourData['sNeighbour']}: ".$e->getMessage());
}
if ($aNeighbourData['sDirection'] == 'down')
{
$aNeighbourData['sQueryUp'] = null;
}
$sArrowId = $aNeighbourData['sDefinedInClass'].'_'.$sNeighbourId;
$aQueries[$sClass]['down'][$sArrowId] = $aNeighbourData;
// Compute the reverse index
if ($aNeighbourData['sDefinedInClass'] == $sClass)
{
$sFromClass = $aNeighbourData['sFromClass'];
$sToClass = $aNeighbourData['sToClass'];
foreach (self::EnumChildClasses($sToClass, ENUM_CHILD_CLASSES_ALL) as $sSubClass)
if ($aNeighbourData['sDirection'] == 'both')
{
$aQueries[$sSubClass]['up'][$sArrowId] = $aNeighbourData;
$sFromClass = $aNeighbourData['sFromClass'];
$sToClass = $aNeighbourData['sToClass'];
foreach (self::EnumChildClasses($sToClass, ENUM_CHILD_CLASSES_ALL) as $sSubClass)
{
$aQueries[$sSubClass]['up'][$sArrowId] = $aNeighbourData;
}
}
}
}
@@ -1320,7 +1328,9 @@ abstract class MetaModel
'sDefinedInClass' => $sClass,
'sFromClass' => $sClass,
'sToClass' => $sRemoteClass,
'sDirection' => 'down',
'sQueryDown' => $aLegacyEntry['sQuery'],
'sQueryUp' => null,
'sNeighbour' => $sRemoteClass // Normalize the neighbour id
);
}
@@ -1354,6 +1364,8 @@ abstract class MetaModel
'sDefinedInClass' => $sRemoteClass,
'sFromClass' => $sRemoteClass,
'sToClass' => $sClass,
'sDirection' => 'both',
'sQueryDown' => null,
'sQueryUp' => $aLegacyEntry['sQuery'],
'sNeighbour' => $sClass// Normalize the neighbour id
);
@@ -1388,6 +1400,7 @@ abstract class MetaModel
if (isset($aQueries[$sRemoteClass]['down'][$sLocalClass]))
{
$aQueries[$sRemoteClass]['down'][$sLocalClass]['sQueryUp'] = $aNeighbourData['sQueryUp'];
$aQueries[$sRemoteClass]['down'][$sLocalClass]['sDirection'] = 'both';
}
else
{
@@ -1396,7 +1409,7 @@ abstract class MetaModel
}
}
}
// Foreach "down" legacy query, update its "up" counterpart
// Foreach "down" legacy query, update its "up" counterpart (if any)
foreach ($aQueries[$sClass]['down'] as $sNeighbourId => $aNeighbourData)
{
if (!$aNeighbourData['_legacy_']) continue; // Skip modern definitions
@@ -1404,7 +1417,10 @@ abstract class MetaModel
$sLocalClass = $aNeighbourData['sFromClass'];
foreach (self::EnumChildClasses($aNeighbourData['sToClass'], ENUM_CHILD_CLASSES_ALL) as $sRemoteClass)
{
//$aQueries[$sRemoteClass]['up'][$sLocalClass]['sQueryDown'] = $aNeighbourData['sQueryDown'];
if (isset($aQueries[$sRemoteClass]['up'][$sLocalClass]))
{
$aQueries[$sRemoteClass]['up'][$sLocalClass]['sQueryDown'] = $aNeighbourData['sQueryDown'];
}
}
}
}

View File

@@ -1380,7 +1380,6 @@
<duplicates/>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -1469,6 +1468,7 @@
<neighbours>
<neighbour id="contact">
<attribute>contacts_list</attribute>
<direction>down</direction>
</neighbour>
<neighbour id="applicationsolution">
<attribute>applicationsolution_list</attribute>
@@ -1743,7 +1743,6 @@
<count_max>0</count_max>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -2208,7 +2207,6 @@
<is_null_allowed>true</is_null_allowed>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -2522,7 +2520,6 @@
<duplicates/>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -2835,7 +2832,6 @@
<min_up_type>count</min_up_type>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -2976,7 +2972,6 @@
<display_style>list</display_style>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -3138,7 +3133,6 @@
<display_style>list</display_style>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -3268,7 +3262,6 @@
<count_max>0</count_max>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -3416,7 +3409,6 @@
<count_max>0</count_max>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -3564,7 +3556,6 @@
<count_max>0</count_max>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -3946,7 +3937,6 @@
<target_attcode>name</target_attcode>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -4067,7 +4057,6 @@
<target_attcode>name</target_attcode>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -4194,7 +4183,6 @@
<target>_blank</target>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>

View File

@@ -231,7 +231,18 @@
<count_max>0</count_max>
</field>
</fields>
<methods/>
<methods>
<method id="GetRelationQueries">
<comment>/**
* Placeholder for backward compatibility (iTop &lt;= 2.1.0)
* in case an extension attempts to redefine this function...
*/</comment>
<static>true</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public static function GetRelationQueries($sRelCode){return parent::GetRelationQueries($sRelCode);} ]]></code>
</method>
</methods>
<presentation>
<details>
<items>
@@ -401,7 +412,18 @@
</reconciliation>
</properties>
<fields/>
<methods/>
<methods>
<method id="GetRelationQueries">
<comment>/**
* Placeholder for backward compatibility (iTop &lt;= 2.1.0)
* in case an extension attempts to redefine this function...
*/</comment>
<static>true</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public static function GetRelationQueries($sRelCode){return parent::GetRelationQueries($sRelCode);} ]]></code>
</method>
</methods>
<presentation>
<details>
<items>
@@ -762,7 +784,6 @@
<target_attcode>name</target_attcode>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>

View File

@@ -34,7 +34,6 @@
<count_max>0</count_max>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -299,7 +298,6 @@
<duplicates/>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -560,7 +558,6 @@
<count_max>0</count_max>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -821,7 +818,6 @@
<count_max>0</count_max>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -1099,7 +1095,6 @@
<target_attcode>name</target_attcode>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -1206,7 +1201,6 @@
<target_attcode>name</target_attcode>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -1452,7 +1446,6 @@
<duplicates/>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>

View File

@@ -157,7 +157,6 @@
<count_max>0</count_max>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -300,7 +299,6 @@
<target_attcode>name</target_attcode>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -456,7 +454,6 @@
<min_up_mode>user</min_up_mode>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>
@@ -649,7 +646,6 @@
<is_null_allowed>true</is_null_allowed>
</field>
</fields>
<methods/>
<presentation>
<details>
<items>

View File

@@ -1452,29 +1452,43 @@ EOF;
if ($oNeighbour->tagName != 'neighbour') continue;
$sNeighbourId = $oNeighbour->getAttribute('id');
if (($oNeighbour->GetChildText('query_down') != '') && ($oNeighbour->GetChildText('query_up') == ''))
{
throw new DOMFormatException("Relation '$sRelationId/$sNeighbourId': missing the query_up specification");
}
if (($oNeighbour->GetChildText('query_up') != '') && ($oNeighbour->GetChildText('query_down') == ''))
{
throw new DOMFormatException("Relation '$sRelationId/$sNeighbourId': missing the query_down specification");
}
if (($oNeighbour->GetChildText('query_down') == '') && ($oNeighbour->GetChildText('attribute') == ''))
$sDirection = $oNeighbour->GetChildText('direction', 'both');
$sAttribute = $oNeighbour->GetChildText('attribute');
$sQueryDown = $oNeighbour->GetChildText('query_down');
$sQueryUp = $oNeighbour->GetChildText('query_up');
if (($sQueryDown == '') && ($sAttribute == ''))
{
throw new DOMFormatException("Relation '$sRelationId/$sNeighbourId': either a query or an attribute must be specified");
}
if (($oNeighbour->GetChildText('query_down') != '') && ($oNeighbour->GetChildText('attribute') != ''))
if (($sQueryDown != '') && ($sAttribute != ''))
{
throw new DOMFormatException("Relation '$sRelationId/$sNeighbourId': both a query and and attribute have been specified... which one should be used?");
}
if ($sDirection == 'both')
{
if (($sAttribute == '') && ($sQueryUp == ''))
{
throw new DOMFormatException("Relation '$sRelationId/$sNeighbourId': missing the query_up specification");
}
}
elseif ($sDirection == 'down')
{
// Ok
}
else
{
throw new DOMFormatException("Relation '$sRelationId/$sNeighbourId': unknown direction ($sDirection), expecting 'both' or 'down'");
}
$aRelations[$sRelationId][$sNeighbourId] = array(
'_legacy_' => false,
'sDirection' => $sDirection,
'sDefinedInClass' => $sClass,
'sNeighbour' => $sNeighbourId,
'sQueryDown' => $oNeighbour->GetChildText('query_down'),
'sQueryUp' => $oNeighbour->GetChildText('query_up'),
'sAttribute' => $oNeighbour->GetChildText('attribute'),
'sQueryDown' => $sQueryDown,
'sQueryUp' => $sQueryUp,
'sAttribute' => $sAttribute,
);
}
}