|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
|
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
|
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
|
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
|
8
|
|
|
* @link https://vistart.me/ |
|
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
|
10
|
|
|
* @license https://vistart.me/license/ |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace rhosocial\organization; |
|
14
|
|
|
|
|
15
|
|
|
use rhosocial\organization\queries\OrganizationQuery; |
|
16
|
|
|
use yii\behaviors\AttributeBehavior; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @version 1.0 |
|
20
|
|
|
* @author vistart <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class Organization extends BaseOrganization |
|
23
|
|
|
{ |
|
24
|
|
|
public $parentAttribute = 'parent'; |
|
25
|
|
|
|
|
26
|
8 |
|
public function init() |
|
27
|
|
|
{ |
|
28
|
8 |
|
if (!is_string($this->queryClass)) { |
|
29
|
|
|
$this->queryClass = OrganizationQuery::class; |
|
30
|
|
|
} |
|
31
|
8 |
|
parent::init(); |
|
32
|
8 |
|
} |
|
33
|
|
|
|
|
34
|
8 |
|
protected function typeAttributeBehavior() |
|
35
|
|
|
{ |
|
36
|
|
|
return [ |
|
37
|
|
|
[ |
|
38
|
|
|
'class' => AttributeBehavior::class, |
|
39
|
|
|
'attributes' => [ |
|
40
|
8 |
|
self::EVENT_BEFORE_INSERT => 'type', |
|
41
|
8 |
|
self::EVENT_BEFORE_UPDATE => 'type', |
|
42
|
|
|
], |
|
43
|
8 |
|
'value' => self::TYPE_ORGANIZATION, |
|
44
|
|
|
] |
|
45
|
8 |
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* The default value of `type` attribute is `ORGANIZATION`(1). |
|
50
|
|
|
* @return array Rules associated with `type` attribute. |
|
51
|
|
|
*/ |
|
52
|
8 |
|
protected function getTypeRules() |
|
53
|
|
|
{ |
|
54
|
|
|
return [ |
|
55
|
8 |
|
['type', 'default', 'value' => self::TYPE_ORGANIZATION], |
|
56
|
|
|
['type', 'required'], |
|
57
|
8 |
|
['type', 'in', 'range' => [self::TYPE_ORGANIZATION]], |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @inheritdoc |
|
63
|
|
|
*/ |
|
64
|
8 |
|
public static function find() |
|
65
|
|
|
{ |
|
66
|
8 |
|
return parent::find()->andWhere(['type' => self::TYPE_ORGANIZATION]); |
|
67
|
|
|
} |
|
68
|
|
|
} |