Example #1
0
 /**
  * How to use Relation::deleteLink() to delete link (a1,b1) from r:
  * r :: A * B
  * deleteLink(a1[A], b1[B], false);
  * deleteLink(b1[B], a1[A], true);
  * 
  * @param Atom $leftAtom
  * @param Atom $rightAtom
  * @param boolean $isFlipped
  * @param string $source specifies who calls this function (e.g. 'User' or 'ExecEngine')
  * @return void
  */
 public function deleteLink($leftAtom, $rightAtom, $isFlipped = false, $source = 'User')
 {
     $this->logger->debug("Delete link ({$leftAtom->__toString()},{$rightAtom->__toString()}) from relation '{$this->__toString()}{({$isFlipped} ? '~' : '')}'");
     // Determine src and tgt atom based on $isFlipped
     $srcAtom = $isFlipped ? $rightAtom : $leftAtom;
     $tgtAtom = $isFlipped ? $leftAtom : $rightAtom;
     // Checks
     if (!in_array($srcAtom->concept, $this->srcConcept->getSpecializationsIncl())) {
         throw new Exception("Cannot delete link ({$srcAtom->__toString()},{$tgtAtom->__toString()}) from relation '{$this->__toString()}', because source concept does not match relation source or its specializations", 500);
     }
     if (!in_array($tgtAtom->concept, $this->tgtConcept->getSpecializationsIncl())) {
         throw new Exception("Cannot delete link ({$srcAtom->__toString()},{$tgtAtom->__toString()}) from relation '{$this->__toString()}', because target concept does not match relation target or its specializations", 500);
     }
     // Delete link from relation table
     $this->db->deleteLink($this, $srcAtom, $tgtAtom);
     // Flag session var as affected when src or tgt concept of this relation is SESSION
     if ($srcAtom->concept->isSession() || $tgtAtom->concept->isSession()) {
         Session::singleton()->setSessionVarAffected();
     }
 }