1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/paulzi/yii2-auto-tree |
4
|
|
|
* @copyright Copyright (c) 2015 PaulZi <[email protected]> |
5
|
|
|
* @license MIT (https://github.com/paulzi/yii2-auto-tree/blob/master/LICENSE) |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace paulzi\autotree\tests\models; |
9
|
|
|
|
10
|
|
|
use paulzi\adjacencyList\AdjacencyListBehavior; |
11
|
|
|
use paulzi\nestedsets\NestedSetsBehavior; |
12
|
|
|
use paulzi\autotree\AutoTreeTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author PaulZi <[email protected]> |
16
|
|
|
* |
17
|
|
|
* @property integer $id |
18
|
|
|
* @property integer $parent_id |
19
|
|
|
* @property integer $sort |
20
|
|
|
* @property integer $tree |
21
|
|
|
* @property integer $lft |
22
|
|
|
* @property integer $rgt |
23
|
|
|
* @property integer $depth |
24
|
|
|
* @property string $path |
25
|
|
|
* @property string $slug |
26
|
|
|
* |
27
|
|
|
* @property NodeAlNs[] $parents |
28
|
|
|
* @property NodeAlNs $parent |
29
|
|
|
* @property NodeAlNs $root |
30
|
|
|
* @property NodeAlNs[] $descendants |
31
|
|
|
* @property NodeAlNs[] $children |
32
|
|
|
* @property NodeAlNs[] $leaves |
33
|
|
|
* @property NodeAlNs $prev |
34
|
|
|
* @property NodeAlNs $next |
35
|
|
|
* |
36
|
|
|
* @method static NodeAlNs|null findOne() findOne($condition) |
37
|
|
|
* |
38
|
|
|
* @mixin AdjacencyListBehavior |
39
|
|
|
* @mixin NestedSetsBehavior |
40
|
|
|
*/ |
41
|
|
View Code Duplication |
class NodeAlNs extends \yii\db\ActiveRecord |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
use AutoTreeTrait; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritdoc |
47
|
|
|
*/ |
48
|
21 |
|
public static function tableName() |
49
|
|
|
{ |
50
|
21 |
|
return '{{%tree}}'; |
51
|
|
|
} |
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
*/ |
55
|
21 |
|
public function behaviors() |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
[ |
59
|
21 |
|
'class' => AdjacencyListBehavior::className(), |
60
|
|
|
'sortable' => false, |
61
|
|
|
], |
62
|
|
|
[ |
63
|
21 |
|
'class' => NestedSetsBehavior::className(), |
64
|
21 |
|
'treeAttribute' => 'tree', |
65
|
|
|
], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritdoc |
71
|
|
|
*/ |
72
|
10 |
|
public function transactions() |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
10 |
|
self::SCENARIO_DEFAULT => self::OP_ALL, |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return NodeQuery |
81
|
|
|
*/ |
82
|
21 |
|
public static function find() |
83
|
|
|
{ |
84
|
21 |
|
return new NodeQuery(get_called_class()); |
85
|
|
|
} |
86
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.