示例#1
0
 /**
  * How to use Relation::addLink() to add link (a1,b1) into r:
  * r :: A * B
  * addLink(a1[A], b1[B], false);
  * addLink(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 addLink($leftAtom, $rightAtom, $isFlipped = false, $source = 'User')
 {
     $this->logger->debug("Insert link ({$leftAtom->__toString()},{$rightAtom->__toString()}) into 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 insert link ({$srcAtom->__toString()},{$tgtAtom->__toString()}) into 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 insert link ({$srcAtom->__toString()},{$tgtAtom->__toString()}) into relation '{$this->__toString()}', because target concept does not match relation target or its specializations", 500);
     }
     if (is_null($srcAtom->id)) {
         throw new Exception("Cannot insert link in relation '{$this->__toString()}', because src atom is not specified", 500);
     }
     if (is_null($tgtAtom->id)) {
         throw new Exception("Cannot insert link in relation '{$this->__toString()}', because tgt atom is not specified", 500);
     }
     // Ensure that atoms exists in their concept tables
     $srcAtom->addAtom();
     $tgtAtom->addAtom();
     // Insert link in relation table
     $this->db->addLink($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();
     }
 }