Пример #1
0
 /**
  * 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);
 }
Пример #2
0
 /**
  * @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);
     }
 }
Пример #3
0
 /**
  * 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();
 }
Пример #4
0
 protected function wrapInTransaction(Closure $callback)
 {
     return $this->node->getConnection()->transaction($callback);
 }
Пример #5
0
 private function balance(Node $node) : Node
 {
     if ($node->getRight()->isRed()) {
         return $this->rotateLeft($node);
     }
     return $node;
 }
Пример #6
0
 /**
  * Get the fully qualified value for the specified column.
  *
  * @return string
  */
 protected function qualify($column)
 {
     return $this->node->getTable() . '.' . $column;
 }
Пример #7
0
 /**
  * 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);
 }