public function ComputeImpactedItems() { $oToNotify = $this->Get('contacts_list'); $oToImpact = $this->Get('functionalcis_list'); $oImpactedInfras = DBObjectSet::FromLinkSet($this, 'functionalcis_list', 'functionalci_id'); $aComputed = $oImpactedInfras->GetRelatedObjects('impacts', 10); if (isset($aComputed['FunctionalCI']) && is_array($aComputed['FunctionalCI'])) { foreach ($aComputed['FunctionalCI'] as $iKey => $oObject) { $oNewLink = new lnkFunctionalCIToTicket(); $oNewLink->Set('functionalci_id', $iKey); $oNewLink->Set('impact', 'potentially impacted (automatically computed)'); $oToImpact->AddObject($oNewLink); } } if (isset($aComputed['Contact']) && is_array($aComputed['Contact'])) { foreach ($aComputed['Contact'] as $iKey => $oObject) { $oNewLink = new lnkContactToTicket(); $oNewLink->Set('contact_id', $iKey); $oNewLink->Set('role', 'contact automatically computed'); $oToNotify->AddObject($oNewLink); } } parent::OnInsert(); }
protected function OnInsert() { $oToNotify = $this->Get('contacts_list'); $oToImpact = $this->Get('functionalcis_list'); $oImpactedInfras = DBObjectSet::FromLinkSet($this, 'functionalcis_list', 'functionalci_id'); $aComputed = $oImpactedInfras->GetRelatedObjects('impacts', 10); if (isset($aComputed['FunctionalCI']) && is_array($aComputed['FunctionalCI'])) { foreach ($aComputed['FunctionalCI'] as $iKey => $oObject) { $oNewLink = new lnkFunctionalCIToTicket(); $oNewLink->Set('functionalci_id', $iKey); $oToImpact->AddObject($oNewLink); } } if (isset($aComputed['Contact']) && is_array($aComputed['Contact'])) { foreach ($aComputed['Contact'] as $iKey => $oObject) { $oNewLink = new lnkContactToTicket(); $oNewLink->Set('contact_id', $iKey); $oNewLink->Set('role', 'contact automatically computed'); $oToNotify->AddObject($oNewLink); } } $this->Set('creation_date', time()); $this->Set('last_update', time()); }
protected function LoadValues($aArgs) { $this->m_aValues = array(); if (!array_key_exists('this', $aArgs)) { throw new CoreException("Missing 'this' in arguments", array('args' => $aArgs)); } $oTarget = $aArgs['this->object()']; // Nodes from which we will start the search for neighbourhood $oNodes = DBObjectSet::FromLinkSet($oTarget, $this->m_sLinkSetAttCode, $this->m_sExtKeyToRemote); // Neighbours, whatever their class $aRelated = $oNodes->GetRelatedObjects($this->m_sRelationCode, $this->m_iMaxDepth); $sRootClass = MetaModel::GetRootClass($this->m_sTargetClass); if (array_key_exists($sRootClass, $aRelated)) { $aLinksToCreate = array(); foreach ($aRelated[$sRootClass] as $iKey => $oObject) { if (MetaModel::IsParentClass($this->m_sTargetClass, get_class($oObject))) { $oNewLink = MetaModel::NewObject($this->m_sTargetLinkClass); $oNewLink->Set($this->m_sTargetExtKey, $iKey); //$oNewLink->Set('role', 'concerned by an impacted CI'); $aLinksToCreate[] = $oNewLink; } } // #@# or AddObjectArray($aObjects) ? $oSetToCreate = DBObjectSet::FromArray($this->m_sTargetLinkClass, $aLinksToCreate); $this->m_aValues[$oObject->GetKey()] = $oObject->GetName(); } return true; }