/** * Deletes the nested set part under the node including the node * @param Node\NodeInterface $node */ public function delete(Node\NodeInterface $node) { if (!$this->locked) { //\Log::info('Should lock before changes'); } if (!$node instanceof Node\DoctrineNode) { throw new Exception\WrongInstance($node, 'Node\\DoctrineNode'); } $left = $node->getLeftValue(); $right = $node->getRightValue(); // Deletes only children here because there could be associations that // doesn't allow deletion, then only leafs could be erased $sql = "DELETE FROM {$this->tableName}\n\t\t\t\tWHERE lft > {$left} AND rgt < {$right}"; $sql .= $this->getAdditionalConditionSql('AND'); $this->entityManager->getConnection()->exec($sql); // // Deletes only children here because there could be associations that // // doesn't allow deletion, then only leafs could be erased // $dql = "DELETE FROM {$this->className} e // WHERE e.left > {$left} AND e.right < {$right}"; // // $dql .= $this->getAdditionalCondition('AND'); // // $query = $this->entityManager->createQuery($dql); // $query->execute(); $this->arrayHelper->delete($node); }
/** * Dump the node data as string * @param NodeInterface $node * @return string */ public static function dump(NodeInterface $node) { $prefix = str_repeat(static::DUMP_PREFIX, $node->getLevel()); $left = $node->getLeftValue(); $right = $node->getRightValue(); $level = $node->getLevel(); $title = $node->getNodeTitle(); $dumpData = array(static::DUMP_PREFIX_POS => $prefix, static::DUMP_LEFT_POS => $left, static::DUMP_RIGHT_POS => $right, static::DUMP_LEVEL_POS => $level, static::DUMP_TITLE_POS => $title); ksort($dumpData); $dumpString = vsprintf(static::DUMP_FORMAT, $dumpData); return $dumpString; }