/** * Returns the query builder needed to update the numChildren value of a node * * @param Node $node * @param string $path * @param string $incDec inc|dec * @return QueryBuilder */ public function getUpdateNumChildrenQueryBuilder($node, $path, $dir = 'inc') { $dir = $dir == 'inc' ? '+' : '-'; $qb = $this->hm->getEntityManager()->createQueryBuilder()->update($this->classMetadata->name, 'e'); $rval = $node->getNumChildrenFieldName() . $dir . '1'; $qb->set('e.' . $node->getNumChildrenFieldName(), 'e.' . $rval); $qb->where($qb->expr()->eq('e.' . $node->getPathFieldName(), $qb->expr()->literal($path))); return $qb; }
/** * Update stuff when moving to a child * * @param string $pos * @param Node $target * @param integer $newDepth * @return array **/ protected function _fixMoveToChild($pos, $target, $newDepth) { $newDepth = $target->getDepth(); $siblings = array(); if (in_array($pos, array('first-child', 'last-child', 'sorted-child'))) { $parent = $target; $newDepth++; if ($target->isLeaf()) { $newPos = 1; $pos = 'first-sibling'; $siblings = array(); // TODO - hmm } else { $target = $target->getLastChild(); $pos = str_replace('child', 'sibling', $pos); } $this->classMetadata->reflValues[$this->getNumChildrenFieldName()]->setValue($parent, $parent->getNumberOfChildren() + 1); } return array($pos, $target, $newDepth, $siblings, $newPos); }