コード例 #1
0
ファイル: ajax.csvimport.php プロジェクト: henryavila/itop
/**
 * Get all the fields xxx->yyy based on the field xxx which is an external key
 * @param string $sExtKeyAttCode Attribute code of the external key
 * @param AttributeDefinition $oExtKeyAttDef Attribute definition of the external key
 * @param bool $bAdvanced True if advanced mode
 * @return Ash List of codes=>display name: xxx->yyy where yyy are the reconciliation keys for the object xxx 
 */
function GetMappingsForExtKey($sAttCode, AttributeDefinition $oExtKeyAttDef, $bAdvanced)
{
    $aResult = array();
    $sTargetClass = $oExtKeyAttDef->GetTargetClass();
    foreach (MetaModel::ListAttributeDefs($sTargetClass) as $sTargetAttCode => $oTargetAttDef) {
        if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode)) {
            $bExtKey = $oTargetAttDef->IsExternalKey();
            $sSuffix = '';
            if ($bExtKey) {
                $sSuffix = '->id';
            }
            if ($bAdvanced || !$bExtKey) {
                // When not in advanced mode do not allow to use reconciliation keys (on external keys) if they are themselves external keys !
                $aResult[$sAttCode . '->' . $sTargetAttCode] = $oExtKeyAttDef->GetLabel() . '->' . $oTargetAttDef->GetLabel() . $sSuffix;
            }
        }
    }
    return $aResult;
}
コード例 #2
0
ファイル: metamodel.class.php プロジェクト: henryavila/itop
 public static function Init_AddAttribute(AttributeDefinition $oAtt, $sTargetClass = null)
 {
     if (!$sTargetClass) {
         $sTargetClass = self::GetCallersPHPClass("Init");
     }
     $sAttCode = $oAtt->GetCode();
     if ($sAttCode == 'finalclass') {
         throw new Exception("Declaration of {$sTargetClass}: using the reserved keyword '{$sAttCode}' in attribute declaration");
     }
     if ($sAttCode == 'friendlyname') {
         throw new Exception("Declaration of {$sTargetClass}: using the reserved keyword '{$sAttCode}' in attribute declaration");
     }
     if (array_key_exists($sAttCode, self::$m_aAttribDefs[$sTargetClass])) {
         throw new Exception("Declaration of {$sTargetClass}: attempting to redeclare the inherited attribute '{$sAttCode}', originaly declared in " . self::$m_aAttribOrigins[$sTargetClass][$sAttCode]);
     }
     // Set the "host class" as soon as possible, since HierarchicalKeys use it for their 'target class' as well
     // and this needs to be know early (for Init_IsKnowClass 19 lines below)
     $oAtt->SetHostClass($sTargetClass);
     // Some attributes could refer to a class
     // declared in a module which is currently not installed/active
     // We simply discard those attributes
     //
     if ($oAtt->IsLinkSet()) {
         $sRemoteClass = $oAtt->GetLinkedClass();
         if (!self::Init_IsKnownClass($sRemoteClass)) {
             self::$m_aIgnoredAttributes[$sTargetClass][$oAtt->GetCode()] = $sRemoteClass;
             return;
         }
     } elseif ($oAtt->IsExternalKey()) {
         $sRemoteClass = $oAtt->GetTargetClass();
         if (!self::Init_IsKnownClass($sRemoteClass)) {
             self::$m_aIgnoredAttributes[$sTargetClass][$oAtt->GetCode()] = $sRemoteClass;
             return;
         }
     } elseif ($oAtt->IsExternalField()) {
         $sExtKeyAttCode = $oAtt->GetKeyAttCode();
         if (isset(self::$m_aIgnoredAttributes[$sTargetClass][$sExtKeyAttCode])) {
             // The corresponding external key has already been ignored
             self::$m_aIgnoredAttributes[$sTargetClass][$oAtt->GetCode()] = self::$m_aIgnoredAttributes[$sTargetClass][$sExtKeyAttCode];
             return;
         }
         // #@# todo - Check if the target attribute is still there
         // this is not simple to implement because is involves
         // several passes (the load order has a significant influence on that)
     }
     self::$m_aAttribDefs[$sTargetClass][$oAtt->GetCode()] = $oAtt;
     self::$m_aAttribOrigins[$sTargetClass][$oAtt->GetCode()] = $sTargetClass;
     // Note: it looks redundant to put targetclass there, but a mix occurs when inheritance is used
 }