/** * Checks if duplicate values for the column specified exist. Takes * the Nested Set scope columns into account (if appropiate). * * @param string $column * @return boolean */ protected function duplicatesExistForColumn($column) { $connection = $this->node->getConnection(); $grammar = $connection->getQueryGrammar(); $columns = array_merge($this->node->getQualifiedScopedColumns(), array($column)); $columnsForSelect = implode(', ', array_map(function ($col) use($grammar) { return $grammar->wrap($col); }, $columns)); $wrappedColumn = $grammar->wrap($column); $query = $this->node->newQuery()->select($connection->raw("{$columnsForSelect}, COUNT({$wrappedColumn})"))->havingRaw("COUNT({$wrappedColumn}) > 1"); foreach ($columns as $col) { $query->groupBy($col); } $result = $query->first(); return !is_null($result); }
/** * @param Node $node * @param array $array * @param Key $lo * @param Key $hi */ private function _range(Node $node, array &$array, Key $lo, Key $hi) { if (!$node->getLength()) { return; } $cmpLo = $node->getKey()->compare($lo); $cmpHi = $node->getKey()->compare($hi); if ($cmpLo > 0) { $this->_range($node->getLeft(), $array, $lo, $hi); } if ($cmpLo >= 0 && $cmpHi <= 0) { $array[] = $node; } if ($cmpHi < 0) { $this->_range($node->getRight(), $array, $lo, $hi); } }
/** * Applies a lock to the rows between the supplied index boundaries. * * @param int $lft * @param int $rgt * @return void */ protected function applyLockBetween($lft, $rgt) { $this->node->newQuery()->where($this->node->getLeftColumnName(), '>=', $lft)->where($this->node->getRightColumnName(), '<=', $rgt)->select($this->node->getKeyName())->lockForUpdate()->get(); }
protected function wrapInTransaction(Closure $callback) { return $this->node->getConnection()->transaction($callback); }
private function balance(Node $node) : Node { if ($node->getRight()->isRed()) { return $this->rotateLeft($node); } return $node; }
/** * Get the fully qualified value for the specified column. * * @return string */ protected function qualify($column) { return $this->node->getTable() . '.' . $column; }
/** * Return an array of the scoped attributes of the supplied node. * * @param Tree\Node $node * @return array */ protected function scopedAttributes($node) { $keys = $this->node->getScopedColumns(); if (count($keys) == 0) { return array(); } $values = array_map(function ($column) use($node) { return $node->getAttribute($column); }, $keys); return array_combine($keys, $values); }