Esempio n. 1
0
 /**
  * Updates the value of the inverse var (always a one-way action)
  * @param epObject $o The opposite object
  * @param string $actoin The action to be taken: INVERSE_ADD or INVERSE_REMOVE
  * @return bool
  */
 protected function _updateInverse(&$o, $action = epObject::INVERSE_ADD)
 {
     // check if object is epObject
     if (!$o || !$this->fm || !$o instanceof epObject) {
         return false;
     }
     // get inverse var
     if (!($ivar = $this->fm->getInverse())) {
         return true;
     }
     // no action if an object is updating (to prevent endless loop)
     if ($o->epIsUpdating($action)) {
         return true;
     }
     // set inverse updating flag
     $this->o->epSetUpdating(true, $action);
     $o->epSetUpdating(true, $action);
     // a single-valued field
     if (!$o->epIsMany($ivar)) {
         switch ($action) {
             case epObject::INVERSE_ADD:
                 $o[$ivar] = $this->o;
                 break;
             case epObject::INVERSE_REMOVE:
                 $o[$ivar] = null;
                 break;
         }
     } else {
         switch ($action) {
             case epObject::INVERSE_ADD:
                 $o[$ivar][] = $this->o;
                 break;
             case epObject::INVERSE_REMOVE:
                 $o[$ivar]->remove($this->o);
                 break;
         }
     }
     // reset inverse updating flag
     $o->epSetUpdating(false, $action);
     $this->o->epSetUpdating(false, $action);
     return true;
 }