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\materializedPath\MaterializedPathBehavior; |
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 NodeAlMp[] $parents |
28
|
|
|
* @property NodeAlMp $parent |
29
|
|
|
* @property NodeAlMp $root |
30
|
|
|
* @property NodeAlMp[] $descendants |
31
|
|
|
* @property NodeAlMp[] $children |
32
|
|
|
* @property NodeAlMp[] $leaves |
33
|
|
|
* @property NodeAlMp $prev |
34
|
|
|
* @property NodeAlMp $next |
35
|
|
|
* |
36
|
|
|
* @method static NodeAlMp|null findOne() findOne($condition) |
37
|
|
|
* |
38
|
|
|
* @mixin AdjacencyListBehavior |
39
|
|
|
* @mixin MaterializedPathBehavior |
40
|
|
|
*/ |
41
|
|
View Code Duplication |
class NodeAlMp 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' => MaterializedPathBehavior::className(), |
64
|
|
|
], |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @inheritdoc |
70
|
|
|
*/ |
71
|
10 |
|
public function transactions() |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
10 |
|
self::SCENARIO_DEFAULT => self::OP_ALL, |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return NodeQuery |
80
|
|
|
*/ |
81
|
21 |
|
public static function find() |
82
|
|
|
{ |
83
|
21 |
|
return new NodeQuery(get_called_class()); |
84
|
|
|
} |
85
|
|
|
} |
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.