src/wcmf/lib/model/Node.php
public function deleteNode(PersistentObject $other, $role=null, $updateOtherSide=true) {

    $mapper = $this->getMapper();

    // set role if missing
    if ($role == null) {
      $otherType = $other->getType();
      $relations = $mapper->getRelationsByType($otherType);
      $role = (sizeof($relations) > 0) ? $relations[0]->getOtherRole() : $otherType;
    }

    $nodes = $this->getValue($role);
    if (empty($nodes)) {
      // nothing to delete
      return;
    }

    // get the relation description
    $relDesc = $mapper->getRelation($role);

    $oid = $other->getOID();
    if (is_array($nodes)) {
      // multi valued relation
      for($i=0, $count=sizeof($nodes); $i<$count; $i++) {
        if ($nodes[$i]->getOID() == $oid) {
          // remove child
          array_splice($nodes, $i, 1);
          break;
        }
      }
    }
    else {
      // single valued relation
      if ($nodes->getOID() == $oid) {
        // remove child
        $nodes = null;
      }
    }
    parent::setValue($role, $nodes);

    // remember the deletion
    if (!isset($this->deletedNodes[$role])) {
      $this->deletedNodes[$role] = [];
    }
    $this->deletedNodes[$role][] = $other->getOID();
    $this->setState(PersistentOBject::STATE_DIRTY);

    // propagate add action to the other object
    if ($updateOtherSide) {
      $thisRole = $relDesc ? $relDesc->getThisRole() : null;
      $other->deleteNode($this, $thisRole, false);
    }
  }
public function deleteNode(PersistentObject $other, $role=null, $updateOtherSide=true) {

    $mapper = $this->getMapper();

    // set role if missing
    if ($role == null) {
      $otherType = $other->getType();
      $relations = $mapper->getRelationsByType($otherType);
      $role = (sizeof($relations) > 0) ? $relations[0]->getOtherRole() : $otherType;
    }

    $nodes = $this->getValue($role);
    if (empty($nodes)) {
      // nothing to delete
      return;
    }

    // get the relation description
    $relDesc = $mapper->getRelation($role);

    $oid = $other->getOID();
    if (is_array($nodes)) {
      // multi valued relation
      for($i=0, $count=sizeof($nodes); $i<$count; $i++) {
        if ($nodes[$i]->getOID() == $oid) {
          // remove child
          array_splice($nodes, $i, 1);
          break;
        }
      }
    }
    else {
      // single valued relation
      if ($nodes->getOID() == $oid) {
        // remove child
        $nodes = null;
      }
    }
    parent::setValue($role, $nodes);

    // remember the deletion
    if (!isset($this->deletedNodes[$role])) {
      $this->deletedNodes[$role] = [];
    }
    $this->deletedNodes[$role][] = $other->getOID();
    $this->setState(PersistentOBject::STATE_DIRTY);

    // propagate add action to the other object
    if ($updateOtherSide) {
      $thisRole = $relDesc ? $relDesc->getThisRole() : null;
      $other->deleteNode($this, $thisRole, false);
    }
  }
public function deleteNode ( PersistentObject $ other , $ role = null , $ updateOtherSide = true ) { $ mapper = $ this -> getMapper ( ) ; // set role if missing if ( $ role == null ) { $ otherType = $ other -> getType ( ) ; $ relations = $ mapper -> getRelationsByType ( $ otherType ) ; $ role = ( sizeof ( $ relations ) > 0 ) ? $ relations [ 0 ] -> getOtherRole ( ) : $ otherType ; } $ nodes = $ this -> getValue ( $ role ) ; if ( empty ( $ nodes ) ) { // nothing to delete return ; } // get the relation description $ relDesc = $ mapper -> getRelation ( $ role ) ; $ oid = $ other -> getOID ( ) ; if ( is_array ( $ nodes ) ) { // multi valued relation for ( $ i = 0 , $ count = sizeof ( $ nodes ) ; $ i < $ count ; $ i ++ ) { if ( $ nodes [ $ i ] -> getOID ( ) == $ oid ) { // remove child array_splice ( $ nodes , $ i , 1 ) ; break ; } } } else { // single valued relation if ( $ nodes -> getOID ( ) == $ oid ) { // remove child $ nodes = null ; } } parent :: setValue ( $ role , $ nodes ) ; // remember the deletion if ( ! isset ( $ this -> deletedNodes [ $ role ] ) ) { $ this -> deletedNodes [ $ role ] = [ ] ; } $ this -> deletedNodes [ $ role ] [ ] = $ other -> getOID ( ) ; $ this -> setState ( PersistentOBject :: STATE_DIRTY ) ; // propagate add action to the other object if ( $ updateOtherSide ) { $ thisRole = $ relDesc ? $ relDesc -> getThisRole ( ) : null ; $ other -> deleteNode ( $ this , $ thisRole , false ) ; } }
Delete a Node from the given relation.
@param $other The Node to delete.
@param $role The role of the Node. If null, the role is the Node's type (without namespace) (default: _null_)
@param $updateOtherSide Boolean whether to update also the other side of the relation (default: _true_)
Delete a Node from the given relation .