Beispiel #1
0
 /**
  * Quotes an identifier for being used in a database query.
  *
  * @param mixed $value
  * @return string
  */
 protected function quoteIdentifier($value)
 {
     if (is_null($value)) {
         return 'NULL';
     }
     $connection = $this->node->getConnection();
     $pdo = $connection->getPdo();
     return $pdo->quote($value);
 }
Beispiel #2
0
 /**
  * Perform the re-calculation of the left and right indexes of the whole
  * nested set tree structure.
  *
  * @param  bool $force
  * @return void
  */
 public function rebuild($force = false)
 {
     $alreadyValid = forward_static_call(array(get_class($this->node), 'isValidNestedSet'));
     // Do not rebuild a valid Nested Set tree structure
     if (!$force && $alreadyValid) {
         return true;
     }
     // Rebuild lefts and rights for each root node and its children (recursively).
     // We go by setting left (and keep track of the current left bound), then
     // search for each children and recursively set the left index (while
     // incrementing that index). When going back up the recursive chain we start
     // setting the right indexes and saving the nodes...
     $self = $this;
     $this->node->getConnection()->transaction(function () use($self) {
         foreach ($self->roots() as $root) {
             $self->rebuildBounds($root, 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);
 }
Beispiel #4
0
 protected function wrapInTransaction(Closure $callback)
 {
     return $this->node->getConnection()->transaction($callback);
 }