Skip to content

Commit 6748af4

Browse files
committed
Merge branch '1.1'
2 parents 524cef4 + 6517384 commit 6748af4

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

Diff for: .travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.3
54
- 5.4
65
- 5.5
76

Diff for: CHANGELOG.markdown

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
### 1.0.1
2-
* `Collection::toDictionary` is now obsolete. Use `Collection::groupBy`.
1+
### 1.1.0
2+
* `Collection::toDictionary` is now obsolete. Use `Collection::groupBy`.
3+
* Laravel 4.2 is required

Diff for: composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
],
1313

1414
"require": {
15-
"php": ">=5.3.0",
16-
"illuminate/support": "~4.1.18",
17-
"illuminate/database": "~4.1.18"
15+
"php": ">=5.4.0",
16+
"illuminate/support": "~4.2.1",
17+
"illuminate/database": "~4.2.1"
1818
},
1919

2020
"require-dev": {

Diff for: src/Kalnoy/Nestedset/Node.php

+41-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace Kalnoy\Nestedset;
1+
<?php
2+
3+
namespace Kalnoy\Nestedset;
24

35
use \Illuminate\Database\Eloquent\Model as Eloquent;
46
use \Illuminate\Database\Query\Builder;
@@ -41,6 +43,27 @@ class Node extends Eloquent {
4143
*/
4244
const AFTER = 'after';
4345

46+
/**
47+
* Whether model uses soft delete.
48+
*
49+
* @var bool
50+
*
51+
* @since 1.1
52+
*/
53+
static protected $softDelete;
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
protected static function boot()
59+
{
60+
parent::boot();
61+
62+
$instance = new static;
63+
64+
static::$softDelete = method_exists($instance, 'withTrashed');
65+
}
66+
4467
/**
4568
* Get the root node.
4669
*
@@ -300,7 +323,7 @@ protected function beforeOrAfter(Node $node, $dir)
300323
*/
301324
protected function checkTarget(Node $node)
302325
{
303-
if (!$node->exists || $node->isDirty(static::LFT))
326+
if ( ! $node->exists || $node->isDirty(static::LFT))
304327
{
305328
throw new Exception("Target node is updated but not saved.");
306329
}
@@ -361,19 +384,19 @@ public function fireModelEvent($event, $halt = true)
361384
{
362385
if ($this->exists)
363386
{
364-
if ($this->isDirty(static::LFT) && !$this->updateTree())
387+
if ($this->isDirty(static::LFT) && ! $this->updateTree())
365388
{
366389
return false;
367390
}
368391
}
369392
else
370393
{
371-
if (!isset($this->attributes[static::LFT]))
394+
if ( ! isset($this->attributes[static::LFT]))
372395
{
373396
throw new Exception("Cannot save node until it is inserted.");
374397
}
375398

376-
if (!$this->updateTree()) return false;
399+
if ( ! $this->updateTree()) return false;
377400
}
378401
}
379402

@@ -382,7 +405,7 @@ public function fireModelEvent($event, $halt = true)
382405
throw new Exception("Cannot delete root node.");
383406
}
384407

385-
if ($event === 'deleted' && !$this->softDelete) $this->deleteNode();
408+
if ($event === 'deleted' && ! static::$softDelete) $this->deleteNode();
386409

387410
return parent::fireModelEvent($event, $halt);
388411
}
@@ -591,6 +614,16 @@ protected function newBaseQueryBuilder()
591614
return new QueryBuilder($conn, $grammar, $conn->getPostProcessor(), $this);
592615
}
593616

617+
/**
618+
* Get a new query including deleted nodes.
619+
*
620+
* @since 1.1
621+
*/
622+
protected function newQueryWithDeleted()
623+
{
624+
return static::$softDelete ? $this->withTrashed() : $this->newQuery();
625+
}
626+
594627
/**
595628
* Create a new NestedSet Collection instance.
596629
*
@@ -610,7 +643,7 @@ public function newCollection(array $models = array())
610643
*/
611644
public function getNodeHeight()
612645
{
613-
if (!$this->exists) return 2;
646+
if ( ! $this->exists) return 2;
614647

615648
return $this->attributes[static::RGT] - $this->attributes[static::LFT] + 1;
616649
}
@@ -635,7 +668,7 @@ public function getDescendantCount()
635668
*/
636669
public function setParentIdAttribute($value)
637670
{
638-
if (!isset($this->attributes[static::PARENT_ID]) || $this->attributes[static::PARENT_ID] != $value)
671+
if ( ! isset($this->attributes[static::PARENT_ID]) || $this->attributes[static::PARENT_ID] != $value)
639672
{
640673
$this->appendTo(static::findOrFail($value));
641674
}

Diff for: tests/NodeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function assertTreeNotBroken($table = 'categories')
4848
// Check if lft and rgt values are unique
4949
$checks[] = "from $table c1, $table c2 where c1.id <> c2.id and ".
5050
"(c1._lft=c2._lft or c1._rgt=c2._rgt or c1._lft=c2._rgt or c1._rgt=c2._lft)";
51-
51+
5252
// Check if parent_id is set correctly
5353
$checks[] = "from $table c, $table p, $table m where c.parent_id=p.id and m.id <> p.id and m.id <> c.id and ".
5454
"(c._lft not between p._lft and p._rgt or c._lft between m._lft and m._rgt and m._lft between p._lft and p._rgt)";

0 commit comments

Comments
 (0)