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\nestedintervals\NestedIntervalsBehavior; |
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 NodeAlNi[] $parents |
28
|
|
|
* @property NodeAlNi $parent |
29
|
|
|
* @property NodeAlNi $root |
30
|
|
|
* @property NodeAlNi[] $descendants |
31
|
|
|
* @property NodeAlNi[] $children |
32
|
|
|
* @property NodeAlNi[] $leaves |
33
|
|
|
* @property NodeAlNi $prev |
34
|
|
|
* @property NodeAlNi $next |
35
|
|
|
* |
36
|
|
|
* @method static NodeAlNi|null findOne() findOne($condition) |
37
|
|
|
* |
38
|
|
|
* @mixin AdjacencyListBehavior |
39
|
|
|
* @mixin NestedIntervalsBehavior |
40
|
|
|
*/ |
41
|
|
View Code Duplication |
class NodeAlNi 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' => NestedIntervalsBehavior::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.