Exemplo n.º 1
0
 /**
  * Builds closure table join based on the given column.
  *
  * @param string $column
  * @param bool $withSelf
  * @return QueryBuilder
  */
 protected function joinClosureBy($column, $withSelf = false)
 {
     $primary = $this->getQualifiedKeyName();
     $closure = $this->closure->getTable();
     $ancestor = $this->closure->getQualifiedAncestorColumn();
     $descendant = $this->closure->getQualifiedDescendantColumn();
     switch ($column) {
         case 'ancestor':
             $query = $this->join($closure, $ancestor, '=', $primary)->where($descendant, '=', $this->getKey());
             break;
         case 'descendant':
             $query = $this->join($closure, $descendant, '=', $primary)->where($ancestor, '=', $this->getKey());
             break;
     }
     $depthOperator = $withSelf === true ? '>=' : '>';
     $query->where($this->closure->getQualifiedDepthColumn(), $depthOperator, 0);
     return $query;
 }