public function Equals($val1, $val2)
 {
     if ($val1 === $val2) {
         return true;
     }
     if (is_object($val1) != is_object($val2)) {
         return false;
     }
     if (!is_object($val1)) {
         // string ?
         // todo = implement this case ?
         return false;
     }
     // Note: maintain this algorithm so as to make sure it is strictly equivalent to the one used within DBObject::DBWriteLinks()
     $sExtKeyToMe = $this->GetExtKeyToMe();
     $sAdditionalKey = null;
     if ($this->IsIndirect() && !$this->DuplicatesAllowed()) {
         $sAdditionalKey = $this->GetExtKeyToRemote();
     }
     $oComparator = new DBObjectSetComparator($val1, $val2, array($sExtKeyToMe), $sAdditionalKey);
     $aChanges = $oComparator->GetDifferences();
     $bAreEquivalent = count($aChanges['added']) == 0 && count($aChanges['removed']) == 0 && count($aChanges['modified']) == 0;
     return $bAreEquivalent;
 }
Пример #2
0
 private function DBWriteLinks()
 {
     foreach (MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode => $oAttDef) {
         if (!$oAttDef->IsLinkSet()) {
             continue;
         }
         if (!array_key_exists($sAttCode, $this->m_aTouchedAtt)) {
             continue;
         }
         if (array_key_exists($sAttCode, $this->m_aModifiedAtt) && $this->m_aModifiedAtt[$sAttCode] == false) {
             continue;
         }
         // Note: any change to this algorithm must be reproduced into the implementation of AttributeLinkSet::Equals()
         $sExtKeyToMe = $oAttDef->GetExtKeyToMe();
         $sAdditionalKey = null;
         if ($oAttDef->IsIndirect() && !$oAttDef->DuplicatesAllowed()) {
             $sAdditionalKey = $oAttDef->GetExtKeyToRemote();
         }
         $oComparator = new DBObjectSetComparator($this->m_aOrigValues[$sAttCode], $this->Get($sAttCode), array($sExtKeyToMe), $sAdditionalKey);
         $aChanges = $oComparator->GetDifferences();
         foreach ($aChanges['added'] as $oLink) {
             // Make sure that the objects in the set point to "this"
             $oLink->Set($oAttDef->GetExtKeyToMe(), $this->m_iKey);
             $id = $oLink->DBWrite();
         }
         foreach ($aChanges['modified'] as $oLink) {
             // Objects in the set either remain attached or have been detached -> leave the link as is
             $oLink->DBWrite();
         }
         foreach ($aChanges['removed'] as $oLink) {
             $oLink->DBDelete();
         }
     }
 }
Пример #3
0
 /**
  * Compare two sets of objects to determine if their content is identical or not.
  * 
  * Limitation:
  * Works only for sets of 1 column (i.e. one class of object selected)
  * 
  * @param DBObjectSet $oObjectSet
  * @param array $aExcludeColumns The list of columns to exclude frop the comparison
  * @return boolean True if the sets are identical, false otherwise
  */
 public function HasSameContents(DBObjectSet $oObjectSet, $aExcludeColumns = array())
 {
     $oComparator = new DBObjectSetComparator($this, $oObjectSet, $aExcludeColumns);
     return $oComparator->SetsAreEquivalent();
 }
Пример #4
0
 private function DBWriteLinks()
 {
     foreach (MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode => $oAttDef) {
         if (!$oAttDef->IsLinkSet()) {
             continue;
         }
         if (!array_key_exists($sAttCode, $this->m_aTouchedAtt)) {
             continue;
         }
         if (array_key_exists($sAttCode, $this->m_aModifiedAtt) && $this->m_aModifiedAtt[$sAttCode] == false) {
             continue;
         }
         $sExtKeyToMe = $oAttDef->GetExtKeyToMe();
         $sAdditionalKey = null;
         if ($oAttDef->IsIndirect()) {
             $sAdditionalKey = $oAttDef->GetExtKeyToRemote();
         }
         $oComparator = new DBObjectSetComparator($this->m_aOrigValues[$sAttCode], $this->Get($sAttCode), array($sExtKeyToMe), $sAdditionalKey);
         $aChanges = $oComparator->GetDifferences();
         foreach ($aChanges['added'] as $oLink) {
             // Make sure that the objects in the set point to "this"
             $oLink->Set($oAttDef->GetExtKeyToMe(), $this->m_iKey);
             $id = $oLink->DBWrite();
         }
         foreach ($aChanges['modified'] as $oLink) {
             // Make sure that the objects in the set point to "this"
             $oLink->Set($oAttDef->GetExtKeyToMe(), $this->m_iKey);
             $oLink->DBWrite();
         }
         foreach ($aChanges['removed'] as $oLink) {
             // Objects can be removed from the set because:
             // 1) They should no longer exist
             // 2) They are about to be removed from the set BUT NOT deleted, their ExtKey has been reset
             if ($oLink->IsModified() && $oLink->Get($sExtKeyToMe) != $this->m_iKey) {
                 $oLink->DBWrite();
             } else {
                 $oLink->DBDelete();
             }
         }
     }
 }